]> source.dussan.org Git - poi.git/commitdiff
[bug-61792] some changes to avoid iterating over chars of Strings
authorPJ Fanning <fanningpj@apache.org>
Mon, 20 Nov 2017 23:35:36 +0000 (23:35 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 20 Nov 2017 23:35:36 +0000 (23:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1815871 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java
src/java/org/apache/poi/hssf/record/UnknownRecord.java
src/java/org/apache/poi/hssf/record/UserSViewBegin.java
src/java/org/apache/poi/hssf/record/UserSViewEnd.java
src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
src/scratchpad/src/org/apache/poi/hwpf/dev/RecordUtil.java

index af4a385987391330616bdb49c001932b4679be7f..92966385e18467dec479054bf43b37b9f9edcd0c 100644 (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();
index 59bab98f27185e1979904c0d07e9ad060eb2d72b..189b582472d4d044baf5aba2db0a0b57de10134b 100644 (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");
         }
index 1c4895a53e9a51c61d040db51f271d3dd8c7eed1..c32cffbb2b4ac1aa344652b3db0a332ef04a2c94 100644 (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();
index aa72eacd5a590f6c43e036be8a8ddac629551d2c..b3410ebc3e05ff2bbd7e91621e7fe73909c40578 100644 (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();
index 807d67afd12750de70b10d3ae9d984fa1014590f..e6ea05de236034beff673c637b9086dbfdb92542 100644 (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();
index e93a3a5fb0cf82d3d08a08103d9bc546dfe04186..1b086430cd155712c262ca2a272e51e9f36ec391 100644 (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;
     }
 
     /**
index ea533600840cbe234585b9b7862bc31be3b79675..6e62e4ae4daa20dcafca45383b2c1ad36327e58e 100644 (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
index a1b03bb0d5b30c38cb1d66bbc2faac4033e007b2..9cfa1324e9ec94feacd4f56a309d57458f5bfe53 100644 (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++ )
         {