You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by gw...@apache.org on 2017/11/16 01:22:52 UTC

svn commit: r1815404 - /poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java

Author: gwoolsey
Date: Thu Nov 16 01:22:52 2017
New Revision: 1815404

URL: http://svn.apache.org/viewvc?rev=1815404&view=rev
Log:
add Locale awareness to case insensitive conditional comparisons in formatting rule logic.  Needed anyway, and removes forbidden API issues.

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java?rev=1815404&r1=1815403&r2=1815404&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java Thu Nov 16 01:22:52 2017
@@ -17,6 +17,8 @@
 
 package org.apache.poi.ss.formula;
 
+import java.text.CollationKey;
+import java.text.Collator;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.ArrayList;
@@ -49,6 +51,7 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.util.LocaleUtil;
 
 /**
  * Abstracted and cached version of a Conditional Format rule for use with a
@@ -86,6 +89,9 @@ public class EvaluationConditionalFormat
     private final String formula1;
     private final String formula2;
     private final String text;
+    // cached for performance, used with cell text comparisons, which are case insensitive and need to be Locale aware (contains, starts with, etc.) 
+    private final String lowerText;
+
     private final OperatorEnum operator;
     private final ConditionType type;
     // cached for performance, to avoid reading the XMLBean every time a conditionally formatted cell is rendered
@@ -118,12 +124,16 @@ public class EvaluationConditionalFormat
         this.regions = regions;
         formula1 = rule.getFormula1();
         formula2 = rule.getFormula2();
+        
         text = rule.getText();
+        lowerText = text == null ? null : text.toLowerCase(LocaleUtil.getUserLocale());
+        
         numberFormat = rule.getNumberFormat();
         
         operator = OperatorEnum.values()[rule.getComparisonOperation()];
         type = rule.getConditionType();
         
+//         Excel uses the stored text representation from the XML apparently, in tests done so far
         decimalTextFormat = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
         decimalTextFormat.setMaximumFractionDigits(340); // DecimalFormat.DOUBLE_FRACTION_DIGITS, which is default scoped
     }
@@ -559,16 +569,16 @@ public class EvaluationConditionalFormat
             return op.isValid(val, comp, null);
         case CONTAINS_TEXT:
             // implemented both by a cfRule "text" attribute and a formula.  Use the text.
-            return cv.toString().toLowerCase().contains(text.toLowerCase());
+            return text == null ? false : cv.toString().toLowerCase(LocaleUtil.getUserLocale()).contains(lowerText);
         case NOT_CONTAINS_TEXT:
             // implemented both by a cfRule "text" attribute and a formula.  Use the text.
-            return ! cv.toString().toLowerCase().contains(text.toLowerCase());
+            return text == null ? true : ! cv.toString().toLowerCase(LocaleUtil.getUserLocale()).contains(lowerText);
         case BEGINS_WITH:
             // implemented both by a cfRule "text" attribute and a formula.  Use the text.
-            return cv.toString().toLowerCase().startsWith(text.toLowerCase());
+            return cv.toString().toLowerCase(LocaleUtil.getUserLocale()).startsWith(lowerText);
         case ENDS_WITH:
             // implemented both by a cfRule "text" attribute and a formula.  Use the text.
-            return cv.toString().toLowerCase().endsWith(text.toLowerCase());
+            return cv.toString().toLowerCase(LocaleUtil.getUserLocale()).endsWith(lowerText);
         case CONTAINS_BLANKS:
             try {
                 String v = cv.getString();



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