diff --git a/src/java/org/apache/poi/ss/formula/functions/TextFunction.java b/src/java/org/apache/poi/ss/formula/functions/TextFunction.java index 82082bb9c..f9562ef85 100644 --- a/src/java/org/apache/poi/ss/formula/functions/TextFunction.java +++ b/src/java/org/apache/poi/ss/formula/functions/TextFunction.java @@ -112,18 +112,18 @@ public abstract class TextFunction implements Function { * 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)); } diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java index cb0be00e3..a9095982c 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java +++ b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java @@ -54,14 +54,25 @@ public final class TestProper extends TestCase { 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");