[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() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("[").append("HEADERFOOTER").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n");
sb.append('[').append("HEADERFOOTER").append("] (0x");
sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT)).append(")\n");
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("HEADERFOOTER").append("]\n");
return sb.toString();

View File

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

View File

@ -74,10 +74,10 @@ public final class UserSViewBegin extends StandardRecord {
}
public String toString() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
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("[/").append("USERSVIEWBEGIN").append("]\n");
return sb.toString();

View File

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

View File

@ -452,7 +452,7 @@ public final class FontFormatting implements Cloneable {
public String toString()
{
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append(" [Font Formatting]\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(" .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");
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.TextRun;
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.TextDirection;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units;
public class DrawTextParagraph implements Drawable {
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);
return (slide == null) ? "" : Integer.toString(slide.getSlideNumber());
}
StringBuilder buf = new StringBuilder();
TextCap cap = tr.getTextCap();
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;
}
String txt = tr.getRawText();
txt.replace("\t", tab2space(tr)).replace("\u000b", "\n");
buf.append(c);
break;
}
switch (tr.getTextCap()) {
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.TextRun;
import org.apache.poi.util.Beta;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties;
import org.apache.xmlbeans.XmlObject;
@ -95,28 +96,18 @@ public class XSLFTextRun implements TextRun {
String txt = ((CTRegularTextRun)_r).getT();
TextCap cap = getTextCap();
StringBuilder buf = new StringBuilder();
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);
}
}
}
// TODO: finish support for tabs
txt.replace("\t", " ");
return buf.toString();
switch (getTextCap()) {
case ALL:
txt = txt.toUpperCase(LocaleUtil.getUserLocale());
break;
case SMALL:
txt = txt.toLowerCase(LocaleUtil.getUserLocale());
break;
}
return txt;
}
@Override

View File

@ -142,7 +142,7 @@ public class RecordUtil
public static String getConstName( String parentName, String constName,
int padTo )
{
StringBuffer fieldName = new StringBuffer();
StringBuilder fieldName = new StringBuilder();
toConstIdentifier( parentName, fieldName );
fieldName.append( '_' );
toConstIdentifier( constName, fieldName );
@ -152,7 +152,7 @@ public class RecordUtil
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 );
pad( fieldName, padTo );
@ -161,7 +161,7 @@ public class RecordUtil
public static String getFieldName( String name, int padTo )
{
StringBuffer fieldName = new StringBuffer();
StringBuilder fieldName = new StringBuilder();
toIdentifier( name, fieldName );
pad( fieldName, padTo );
@ -170,7 +170,7 @@ public class RecordUtil
public static String getFieldName1stCap( String name, int padTo )
{
StringBuffer fieldName = new StringBuffer();
StringBuilder fieldName = new StringBuilder();
toIdentifier( name, fieldName );
fieldName.setCharAt( 0, Character.toUpperCase( fieldName.charAt( 0 ) ) );
pad( fieldName, padTo );
@ -180,7 +180,7 @@ public class RecordUtil
public static String getType1stCap( String size, String type, int padTo )
{
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append( type );
result = pad( result, padTo );
result.setCharAt( 0, Character.toUpperCase( result.charAt( 0 ) ) );
@ -188,14 +188,14 @@ public class RecordUtil
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++ )
fieldName.append( ' ' );
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++ )
{
@ -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++ )
{