sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1552067 - in /sis/trunk: ./ core/sis-utility/src/main/java/org/apache/sis/util/Locales.java core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java
Date Wed, 18 Dec 2013 19:20:54 GMT
Author: desruisseaux
Date: Wed Dec 18 19:20:54 2013
New Revision: 1552067

URL: http://svn.apache.org/r1552067
Log:
Merge from the JDK6 branch.

Modified:
    sis/trunk/   (props changed)
    sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java
    sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java

Propchange: sis/trunk/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK7:r1551836-1552063
  Merged /sis/branches/JDK6:r1551840-1552066

Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java?rev=1552067&r1=1552066&r2=1552067&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8] Wed
Dec 18 19:20:54 2013
@@ -314,8 +314,8 @@ filter: for (final Locale locale : local
         language = (String) trimWhitespaces(code, fromIndex, p1);
         language = toISO2(language, LANGUAGE);
         country  = toISO2(country,  COUNTRY);
-        if (language.length() > 8 || !isAlpha(language) ||
-             country.length() > 3 || !isAlpha(country))
+        if (language.length() > 8 || !isAlphaNumeric(language) ||
+             country.length() > 3 || !isAlphaNumeric(country))
         {
             throw new RuntimeException( // IllformedLocaleException (indirectly) on the JDK7
branch.
                     Errors.format(Errors.Keys.IllegalLanguageCode_1, code.substring(fromIndex)));
@@ -324,12 +324,15 @@ filter: for (final Locale locale : local
     }
 
     /**
-     * Returns {@code true} if the given text contains only Latin alphabetic characters.
+     * Returns {@code true} if the given text contains only Latin alphabetic or numeric characters.
+     * We use this method for simulating the check performed by {@code Locale.Builder} on
JDK7. Our
+     * test is not as accurate as the JDK7 one however - we are more permissive. But it is
not our
+     * intend to reproduce all the JDK7 syntax checks here.
      */
-    private static boolean isAlpha(final String text) {
+    private static boolean isAlphaNumeric(final String text) {
         for (int i=text.length(); --i>=0;) {
             final char c = text.charAt(i);
-            if (!(c >= 'A' && c <= 'Z') && !(c >= 'a' &&
c <= 'z')) {
+            if (!(c >= 'A' && c <= 'Z') && !(c >= 'a' &&
c <= 'z') && !(c >= '0' && c <= '9')) {
                 return false;
             }
         }

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java?rev=1552067&r1=1552066&r2=1552067&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java [UTF-8]
(original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java [UTF-8]
Wed Dec 18 19:20:54 2013
@@ -73,13 +73,14 @@ public final strictfp class LocalesTest 
     @Test
     @DependsOnMethod("testUnique")
     public void testParse() {
+        assertSame(Locale.ENGLISH,       Locales.parse("en"));
         assertSame(Locale.FRENCH,        Locales.parse("fr"));
         assertSame(Locale.FRENCH,        Locales.parse("fra"));
         assertSame(Locale.CANADA_FRENCH, Locales.parse("fr_CA"));
         assertSame(Locale.CANADA_FRENCH, Locales.parse("fra_CA"));
         assertSame(Locale.CANADA_FRENCH, Locales.parse("fr_CAN"));
         assertSame(Locale.CANADA_FRENCH, Locales.parse("fra_CAN"));
-        assertSame(Locale.ENGLISH,       Locales.parse("en"));
+        assertSame(Locale.JAPAN,         Locales.parse("ja_JP"));
 
         assertEquals(new Locale("de", "DE"),            Locales.parse("de_DE"));
         assertEquals(new Locale("",   "GB"),            Locales.parse("_GB"));
@@ -88,6 +89,17 @@ public final strictfp class LocalesTest 
     }
 
     /**
+     * Tests the {@link Locales#parse(String)} method with a IETF BCP 47 language tag string.
+     * This functionality is supported only on the JDK7 branch.
+     */
+    @Test
+    @org.junit.Ignore("Not supported on the JDK6 branch")
+    public void testParseIETF() {
+        assertEquals(Locale.JAPAN, Locales.parse("ja-JP"));
+        assertEquals(new Locale("en", "US", "POSIX"), Locales.parse("en-US-x-lvariant-POSIX"));
+    }
+
+    /**
      * Tests that {@link Locales#parse(String)} throw an exception if given an invalid argument.
      */
     @Test



Mime
View raw message