[bug-61792] some changes to avoid iterating over chars of Strings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1815871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2017-11-20 23:35:36 +00:00
parent 18f87a1c18
commit 2d8c9cbc9a
8 changed files with 42 additions and 68 deletions

View File

@ -86,10 +86,10 @@ public final class HeaderFooterRecord extends StandardRecord implements Cloneabl
} }
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("[").append("HEADERFOOTER").append("] (0x"); sb.append('[').append("HEADERFOOTER").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT)).append(")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("HEADERFOOTER").append("]\n"); sb.append("[/").append("HEADERFOOTER").append("]\n");
return sb.toString(); return sb.toString();

View File

@ -111,10 +111,10 @@ public final class UnknownRecord extends StandardRecord {
if (biffName == null) { if (biffName == null) {
biffName = "UNKNOWNRECORD"; biffName = "UNKNOWNRECORD";
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("[").append(biffName).append("] (0x"); sb.append('[').append(biffName).append("] (0x");
sb.append(Integer.toHexString(_sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(Integer.toHexString(_sid).toUpperCase(Locale.ROOT)).append(")\n");
if (_rawData.length > 0) { if (_rawData.length > 0) {
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
} }

View File

@ -74,10 +74,10 @@ public final class UserSViewBegin extends StandardRecord {
} }
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("[").append("USERSVIEWBEGIN").append("] (0x"); sb.append("[").append("USERSVIEWBEGIN").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT)).append(")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("USERSVIEWBEGIN").append("]\n"); sb.append("[/").append("USERSVIEWBEGIN").append("]\n");
return sb.toString(); return sb.toString();

View File

@ -60,10 +60,10 @@ public final class UserSViewEnd extends StandardRecord {
} }
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("[").append("USERSVIEWEND").append("] (0x"); sb.append('[').append("USERSVIEWEND").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n"); sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT)).append(")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n"); sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("USERSVIEWEND").append("]\n"); sb.append("[/").append("USERSVIEWEND").append("]\n");
return sb.toString(); return sb.toString();

View File

@ -452,7 +452,7 @@ public final class FontFormatting implements Cloneable {
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
buffer.append(" [Font Formatting]\n"); buffer.append(" [Font Formatting]\n");
buffer.append(" .font height = ").append(getFontHeight()).append(" twips\n"); buffer.append(" .font height = ").append(getFontHeight()).append(" twips\n");
@ -525,7 +525,8 @@ public final class FontFormatting implements Cloneable {
{ {
buffer.append(" .underline type is not modified\n"); buffer.append(" .underline type is not modified\n");
} }
buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase(Locale.ROOT)).append("\n"); buffer.append(" .color index = ").append("0x")
.append(Integer.toHexString(getFontColorIndex()).toUpperCase(Locale.ROOT)).append('\n');
buffer.append(" [/Font Formatting]\n"); buffer.append(" [/Font Formatting]\n");
return buffer.toString(); return buffer.toString();

View File

@ -50,14 +50,13 @@ import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign; import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextRun.FieldType; import org.apache.poi.sl.usermodel.TextRun.FieldType;
import org.apache.poi.sl.usermodel.TextRun.TextCap;
import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.sl.usermodel.TextShape.TextDirection; import org.apache.poi.sl.usermodel.TextShape.TextDirection;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
public class DrawTextParagraph implements Drawable { public class DrawTextParagraph implements Drawable {
private static final POILogger LOG = POILogFactory.getLogger(DrawTextParagraph.class); private static final POILogger LOG = POILogFactory.getLogger(DrawTextParagraph.class);
@ -379,33 +378,16 @@ public class DrawTextParagraph implements Drawable {
Slide<?,?> slide = (Slide<?,?>)graphics.getRenderingHint(Drawable.CURRENT_SLIDE); Slide<?,?> slide = (Slide<?,?>)graphics.getRenderingHint(Drawable.CURRENT_SLIDE);
return (slide == null) ? "" : Integer.toString(slide.getSlideNumber()); return (slide == null) ? "" : Integer.toString(slide.getSlideNumber());
} }
StringBuilder buf = new StringBuilder(); String txt = tr.getRawText();
TextCap cap = tr.getTextCap(); txt.replace("\t", tab2space(tr)).replace("\u000b", "\n");
String tabs = null;
for (char c : tr.getRawText().toCharArray()) {
switch (c) {
case '\t':
if (tabs == null) {
tabs = tab2space(tr);
}
buf.append(tabs);
break;
case '\u000b':
buf.append('\n');
break;
default:
switch (cap) {
case ALL: c = Character.toUpperCase(c); break;
case SMALL: c = Character.toLowerCase(c); break;
case NONE: break;
}
buf.append(c); switch (tr.getTextCap()) {
break; case ALL: txt.toUpperCase(LocaleUtil.getUserLocale()); break;
} case SMALL: txt.toLowerCase(LocaleUtil.getUserLocale()); break;
case NONE: break;
} }
return buf.toString(); return txt;
} }
/** /**

View File

@ -30,6 +30,7 @@ import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.xslf.model.CharacterPropertyFetcher; import org.apache.poi.xslf.model.CharacterPropertyFetcher;
import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties; import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
@ -95,28 +96,18 @@ public class XSLFTextRun implements TextRun {
String txt = ((CTRegularTextRun)_r).getT(); String txt = ((CTRegularTextRun)_r).getT();
TextCap cap = getTextCap(); // TODO: finish support for tabs
StringBuilder buf = new StringBuilder(); txt.replace("\t", " ");
for(int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
if(c == '\t') {
// TODO: finish support for tabs
buf.append(" ");
} else {
switch (cap){
case ALL:
buf.append(Character.toUpperCase(c));
break;
case SMALL:
buf.append(Character.toLowerCase(c));
break;
default:
buf.append(c);
}
}
}
return buf.toString(); switch (getTextCap()) {
case ALL:
txt = txt.toUpperCase(LocaleUtil.getUserLocale());
break;
case SMALL:
txt = txt.toLowerCase(LocaleUtil.getUserLocale());
break;
}
return txt;
} }
@Override @Override

View File

@ -142,7 +142,7 @@ public class RecordUtil
public static String getConstName( String parentName, String constName, public static String getConstName( String parentName, String constName,
int padTo ) int padTo )
{ {
StringBuffer fieldName = new StringBuffer(); StringBuilder fieldName = new StringBuilder();
toConstIdentifier( parentName, fieldName ); toConstIdentifier( parentName, fieldName );
fieldName.append( '_' ); fieldName.append( '_' );
toConstIdentifier( constName, fieldName ); toConstIdentifier( constName, fieldName );
@ -152,7 +152,7 @@ public class RecordUtil
public static String getFieldName( int position, String name, int padTo ) public static String getFieldName( int position, String name, int padTo )
{ {
StringBuffer fieldName = new StringBuffer( "field_" + position + "_" ); StringBuilder fieldName = new StringBuilder().append("field_").append(position).append('_');
toIdentifier( name, fieldName ); toIdentifier( name, fieldName );
pad( fieldName, padTo ); pad( fieldName, padTo );
@ -161,7 +161,7 @@ public class RecordUtil
public static String getFieldName( String name, int padTo ) public static String getFieldName( String name, int padTo )
{ {
StringBuffer fieldName = new StringBuffer(); StringBuilder fieldName = new StringBuilder();
toIdentifier( name, fieldName ); toIdentifier( name, fieldName );
pad( fieldName, padTo ); pad( fieldName, padTo );
@ -170,7 +170,7 @@ public class RecordUtil
public static String getFieldName1stCap( String name, int padTo ) public static String getFieldName1stCap( String name, int padTo )
{ {
StringBuffer fieldName = new StringBuffer(); StringBuilder fieldName = new StringBuilder();
toIdentifier( name, fieldName ); toIdentifier( name, fieldName );
fieldName.setCharAt( 0, Character.toUpperCase( fieldName.charAt( 0 ) ) ); fieldName.setCharAt( 0, Character.toUpperCase( fieldName.charAt( 0 ) ) );
pad( fieldName, padTo ); pad( fieldName, padTo );
@ -180,7 +180,7 @@ public class RecordUtil
public static String getType1stCap( String size, String type, int padTo ) public static String getType1stCap( String size, String type, int padTo )
{ {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append( type ); result.append( type );
result = pad( result, padTo ); result = pad( result, padTo );
result.setCharAt( 0, Character.toUpperCase( result.charAt( 0 ) ) ); result.setCharAt( 0, Character.toUpperCase( result.charAt( 0 ) ) );
@ -188,14 +188,14 @@ public class RecordUtil
return result.toString(); return result.toString();
} }
protected static StringBuffer pad( StringBuffer fieldName, int padTo ) protected static StringBuilder pad( StringBuilder fieldName, int padTo )
{ {
for ( int i = fieldName.length(); i < padTo; i++ ) for ( int i = fieldName.length(); i < padTo; i++ )
fieldName.append( ' ' ); fieldName.append( ' ' );
return fieldName; return fieldName;
} }
private static void toConstIdentifier( String name, StringBuffer fieldName ) private static void toConstIdentifier( String name, StringBuilder fieldName )
{ {
for ( int i = 0; i < name.length(); i++ ) for ( int i = 0; i < name.length(); i++ )
{ {
@ -206,7 +206,7 @@ public class RecordUtil
} }
} }
private static void toIdentifier( String name, StringBuffer fieldName ) private static void toIdentifier( String name, StringBuilder fieldName )
{ {
for ( int i = 0; i < name.length(); i++ ) for ( int i = 0; i < name.length(); i++ )
{ {