Author: onealj
Date: Fri Jul 15 07:25:16 2016
New Revision: 1752786

URL: http://svn.apache.org/viewvc?rev=1752786&view=rev
Log:
annotate purpose of each PROPER() function test case, add a few more test 
cases, identify some problems with ß handling

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/TextFunction.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java

Modified: 
poi/trunk/src/java/org/apache/poi/ss/formula/functions/TextFunction.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/TextFunction.java?rev=1752786&r1=1752785&r2=1752786&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/TextFunction.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/TextFunction.java 
Fri Jul 15 07:25:16 2016
@@ -112,18 +112,18 @@ public abstract class TextFunction imple
         * Implementation of the PROPER function:
      * Normalizes all words (separated by non-word characters) by
      * making the first letter upper and the rest lower case.
+     * 
+     * This is nearly equivalent to toTitleCase if the Java language had it
         */
        public static final Function PROPER = new SingleArgTextFunc() {
                protected ValueEval evaluate(String text) {
                        StringBuilder sb = new StringBuilder();
                        boolean shouldMakeUppercase = true;
-                       final int length = text.length();
-                       for(int i = 0; i < length; ++i) {
-                               final char ch = text.charAt(i);
+                       for(final char ch : text.toCharArray()) {
 
                                // Note: we are using String.toUpperCase() here 
on purpose as it handles certain things
                                // better than Character.toUpperCase(), e.g. 
German "scharfes s" is translated
-                               // to "SS" (i.e. two characters), if upercased 
properly!
+                               // to "SS" (i.e. two characters), if uppercased 
properly!
                                if (shouldMakeUppercase) {
                                        
sb.append(String.valueOf(ch).toUpperCase(Locale.ROOT));
                                }

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java?rev=1752786&r1=1752785&r2=1752786&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
 (original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
 Fri Jul 15 07:25:16 2016
@@ -54,14 +54,25 @@ public final class TestProper extends Te
         cell11 = sheet.createRow(0).createCell(0);
         cell11.setCellType(CellType.FORMULA);
 
-        confirm("PROPER(\"hi there\")", "Hi There");
-        confirm("PROPER(\"what's up\")", "What'S Up");
-        confirm("PROPER(\"I DON'T TH!NK SO!\")", "I Don'T Th!Nk So!");
+        confirm("PROPER(\"hi there\")", "Hi There"); //simple case
+        confirm("PROPER(\"what's up\")", "What'S Up"); //apostrophes are 
treated as word breaks
+        confirm("PROPER(\"I DON'T TH!NK SO!\")", "I Don'T Th!Nk So!"); 
//capitalization is ignored, special punctuation is treated as a word break
         confirm("PROPER(\"dr\u00dcb\u00f6'\u00e4 \u00e9lo\u015f|\u00eb\u00e8 
\")", "Dr\u00fcb\u00f6'\u00c4 \u00c9lo\u015f|\u00cb\u00e8 ");
-        confirm("PROPER(\"hi123 the123re\")", "Hi123 The123Re");
-        confirm("PROPER(\"-\")", "-");
-        confirm("PROPER(\"!\u00a7$\")", "!\u00a7$");
-        confirm("PROPER(\"/&%\")", "/&%");
+        confirm("PROPER(\"hi123 the123re\")", "Hi123 The123Re"); //numbers are 
treated as word breaks
+        confirm("PROPER(\"-\")", "-"); //nothing happens with ascii 
punctuation that is not upper or lower case
+        confirm("PROPER(\"!\u00a7$\")", "!\u00a7$"); //nothing happens with 
unicode punctuation (section sign) that is not upper or lower case
+        confirm("PROPER(\"/&%\")", "/&%"); //nothing happens with ascii 
punctuation that is not upper or lower case
+        confirm("PROPER(\"Apache POI\")", "Apache Poi"); //acronyms are not 
special
+        confirm("PROPER(\"  hello world\")", "  Hello World"); //leading 
whitespace is ignored
+        
+        final String scharfes = "\u00df$"; //German lowercase eszett, scharfes 
s, sharp s
+        // CURRENTLY FAILS: result: "Stra"+scharfes+"E"
+        // confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e");
+        
+        // CURRENTLY FAILS: result: "SSUnd"+scharfes
+        // LibreOffice 5.0.3.2 behavior: "Sund"+scharfes
+        // Excel 2013 behavior: ???
+        //confirm("PROPER(\""+scharfes+"und"+scharfes+"\")", "SSund"+scharfes);
         
         // also test longer string
         StringBuilder builder = new StringBuilder("A");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to