commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r651874 - in /commons/proper/codec/trunk/src: java/org/apache/commons/codec/language/ test/org/apache/commons/codec/
Date Sun, 27 Apr 2008 00:35:59 GMT
Author: bayard
Date: Sat Apr 26 17:35:56 2008
New Revision: 651874

URL: http://svn.apache.org/viewvc?rev=651874&view=rev
Log:
Applying Benjamin Bentmann's patch from CODEC-65, which changes the various encoders to use
a locale when lowercasing. The encoders all assume the English locale, so when running in
non English locales the default toLowerCase sometimes does not work as the encoder expects.


Modified:
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Metaphone.java
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/SoundexUtils.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java?rev=651874&r1=651873&r2=651874&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java
(original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Caverphone.java
Sat Apr 26 17:35:56 2008
@@ -56,7 +56,7 @@
         }
 
         // 1. Convert to lowercase
-        txt = txt.toLowerCase();
+        txt = txt.toLowerCase(java.util.Locale.ENGLISH);
 
         // 2. Remove anything not A-Z
         txt = txt.replaceAll("[^a-z]", "");

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java?rev=651874&r1=651873&r2=651874&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
(original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
Sat Apr 26 17:35:56 2008
@@ -923,7 +923,7 @@
 		if (input.length() == 0) {
 			return null;
 		}
-		return input.toUpperCase();
+		return input.toUpperCase(java.util.Locale.ENGLISH);
 	}
 
     /**

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Metaphone.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Metaphone.java?rev=651874&r1=651873&r2=651874&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Metaphone.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/Metaphone.java Sat
Apr 26 17:35:56 2008
@@ -85,10 +85,10 @@
         }
         // single character is itself
         if (txt.length() == 1) {
-            return txt.toUpperCase() ;
+            return txt.toUpperCase(java.util.Locale.ENGLISH) ;
         }
       
-        char[] inwd = txt.toUpperCase().toCharArray() ;
+        char[] inwd = txt.toUpperCase(java.util.Locale.ENGLISH).toCharArray() ;
       
         StringBuffer local = new StringBuffer(40); // manipulate
         StringBuffer code = new StringBuffer(10) ; //   output

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/SoundexUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/SoundexUtils.java?rev=651874&r1=651873&r2=651874&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/SoundexUtils.java
(original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/SoundexUtils.java
Sat Apr 26 17:35:56 2008
@@ -50,9 +50,9 @@
             }
         }
         if (count == len) {
-            return str.toUpperCase();
+            return str.toUpperCase(java.util.Locale.ENGLISH);
         }
-        return new String(chars, 0, count).toUpperCase();
+        return new String(chars, 0, count).toUpperCase(java.util.Locale.ENGLISH);
     }
 
     /**

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java?rev=651874&r1=651873&r2=651874&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/StringEncoderAbstractTest.java
Sat Apr 26 17:35:56 2008
@@ -17,6 +17,8 @@
 
 package org.apache.commons.codec;
 
+import java.util.Locale;
+
 import junit.framework.TestCase;
 
 /**
@@ -63,4 +65,36 @@
         assertTrue( "An exception was not thrown when we tried to encode " +
                     "a Float object", exceptionThrown );
     }
+
+    public void testLocaleIndependence() throws Exception {
+        StringEncoder encoder = makeEncoder();
+
+        String[] data = { "I", "i", };
+
+        Locale orig = Locale.getDefault();
+        Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
+
+        try {
+            for (int i = 0; i < data.length; i++) {
+                String ref = null;
+                for (int j = 0; j < locales.length; j++) {
+                    Locale.setDefault(locales[j]);
+                    if (j <= 0) {
+                        ref = encoder.encode(data[i]);
+                    } else {
+                        String cur = null;
+                        try {
+                            cur = encoder.encode(data[i]);
+                        } catch (Exception e) {
+                            fail(Locale.getDefault().toString() + ": " + e.getMessage());
+                        }
+                        assertEquals(Locale.getDefault().toString() + ": ", ref, cur);
+                    }
+                }
+            }
+        } finally {
+            Locale.setDefault(orig);
+        }
+    }
+
 }



Mime
View raw message