commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1589508 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/time/FastDateParser.java test/java/org/apache/commons/lang3/time/FastDateParserTest.java
Date Wed, 23 Apr 2014 20:17:55 GMT
Author: chas
Date: Wed Apr 23 20:17:54 2014
New Revision: 1589508

URL: http://svn.apache.org/r1589508
Log:
LANG-966 - toLowerCase should use locale, additional unit tests for case-insensitive matching

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java?rev=1589508&r1=1589507&r2=1589508&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
Wed Apr 23 20:17:54 2014
@@ -586,6 +586,7 @@ public class FastDateParser implements D
      */
      private static class TextStrategy extends Strategy {
         private final int field;
+        private final Locale locale;
         private final Map<String, Integer> keyValues;
         private final Map<String, Integer> lKeyValues;
 
@@ -597,11 +598,12 @@ public class FastDateParser implements D
          */
         TextStrategy(final int field, final Calendar definingCalendar, final Locale locale)
{
             this.field= field;
+            this.locale= locale;
             this.keyValues= getDisplayNames(field, definingCalendar, locale);
             this.lKeyValues= new HashMap<String,Integer>();
 
             for(Map.Entry<String, Integer> entry : keyValues.entrySet()) {
-            	lKeyValues.put(entry.getKey().toLowerCase(), entry.getValue());
+            	lKeyValues.put(entry.getKey().toLowerCase(locale), entry.getValue());
             }
         }
 
@@ -623,7 +625,7 @@ public class FastDateParser implements D
          */
         @Override
         void setCalendar(final FastDateParser parser, final Calendar cal, final String value)
{
-            final Integer iVal = lKeyValues.get(value.toLowerCase());
+            final Integer iVal = lKeyValues.get(value.toLowerCase(locale));
             if(iVal == null) {
                 final StringBuilder sb= new StringBuilder(value);
                 sb.append(" not in (");

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java?rev=1589508&r1=1589507&r2=1589508&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
Wed Apr 23 20:17:54 2014
@@ -325,12 +325,17 @@ public class FastDateParserTest {
 
     private void checkParse(final Locale locale, final Calendar cal, final SimpleDateFormat
sdf, final DateParser fdf) throws ParseException {
         final String formattedDate= sdf.format(cal.getTime());
-        final Date expectedTime = sdf.parse(formattedDate);
-        final Date actualTime = fdf.parse(formattedDate);
-        assertEquals(locale.toString()+" "+formattedDate
-                +"\n",expectedTime, actualTime);
+        checkParse(locale, sdf, fdf, formattedDate);
+        checkParse(locale, sdf, fdf, formattedDate.toLowerCase(locale));
+        checkParse(locale, sdf, fdf, formattedDate.toUpperCase(locale));
     }
 
+	private void checkParse(final Locale locale, final SimpleDateFormat sdf, final DateParser
fdf, final String formattedDate) throws ParseException {
+		final Date expectedTime = sdf.parse(formattedDate);
+        final Date actualTime = fdf.parse(formattedDate);
+        assertEquals(locale.toString()+" "+formattedDate +"\n",expectedTime, actualTime);
+	}
+
     @Test
     public void testParseNumerics() throws ParseException {
         final Calendar cal= Calendar.getInstance(NEW_YORK, Locale.US);
@@ -362,8 +367,15 @@ public class FastDateParserTest {
         testSdfAndFdp("''yyyyMMdd'A''B'HHmmssSSS''", "'20030210A'B153320989'", false); //
OK
         testSdfAndFdp("''''yyyyMMdd'A''B'HHmmssSSS''", "''20030210A'B153320989'", false);
// OK
         testSdfAndFdp("'$\\Ed'" ,"$\\Ed", false); // OK
+        
+        // quoted charaters are case sensitive
+        testSdfAndFdp("'QED'", "QED", false);
+        testSdfAndFdp("'QED'", "qed", true);
+        // case sensitive after insensitive Month field
+        testSdfAndFdp("yyyy-MM-dd 'QED'", "2003-02-10 QED", false);
+        testSdfAndFdp("yyyy-MM-dd 'QED'", "2003-02-10 qed", true);
     }
-
+    
     @Test
     public void testLANG_832() throws Exception {
         testSdfAndFdp("'d'd" ,"d3", false); // OK



Mime
View raw message