From 6ea74f170df7df0d1d640aa21f92cd717ac21e78 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 15 Jul 2016 07:25:16 +0000 Subject: [PATCH] =?UTF-8?q?annotate=20purpose=20of=20each=20PROPER()=20fun?= =?UTF-8?q?ction=20test=20case,=20add=20a=20few=20more=20test=20cases,=20i?= =?UTF-8?q?dentify=20some=20problems=20with=20=C3=9F=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1752786 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/formula/functions/TextFunction.java | 8 +++--- .../poi/ss/formula/functions/TestProper.java | 25 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) 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");