]> granicus.if.org Git - icu/commitdiff
ICU-8795 Remove suffix when CharsetMatch is creating a new string
authorMichael Ow <mow@svn.icu-project.org>
Tue, 13 Sep 2011 18:10:10 +0000 (18:10 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Tue, 13 Sep 2011 18:10:10 +0000 (18:10 +0000)
X-SVN-Rev: 30648

icu4j/main/classes/core/src/com/ibm/icu/text/CharsetMatch.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/charsetdet/TestCharsetDetector.java

index 07e8f9fd1bc30474fa9fec0bdc268fc51ce5fe19..00118fd555e11e4a6300bcfd476cd940fca368ee 100644 (file)
@@ -1,6 +1,6 @@
 /**
 *******************************************************************************
-* Copyright (C) 2005-2010, International Business Machines Corporation and    *
+* Copyright (C) 2005-2011, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */
@@ -102,7 +102,17 @@ public class CharsetMatch implements Comparable<CharsetMatch> {
             
             return sb.toString();
         } else {
-            result = new String(fRawInput, getName());            
+            String name = getName();
+            /*
+             * getName() may return a name with a suffix 'rtl' or 'ltr'. This cannot
+             * be used to open a charset (e.g. IBM424_rtl). The ending '_rtl' or 'ltr'
+             * should be stripped off before creating the string.
+             */
+            int startSuffix = name.indexOf("_rtl") < 0 ? name.indexOf("_ltr") : name.indexOf("_rtl");
+            if (startSuffix > 0) {
+                name = name.substring(0, startSuffix);
+            }
+            result = new String(fRawInput, name);
         }
         return result;
 
index 881198451816acf874e59a6ca35be0104e254dd6..edbe12c3108f0951e57d0486de72c4e2a0d4c852 100644 (file)
@@ -617,11 +617,21 @@ public class TestCharsetDetector extends TestFmwk
         charsetMatch = m.getName();
         CheckAssert(charsetMatch.equals("IBM424_rtl"));
         CheckAssert(m.getLanguage().equals("he"));
+        try {
+            m.getString();
+        } catch (Exception ex) {
+            errln("Error getting string for charsetMatch: " + charsetMatch);
+        }
         
         m = _testIBM424_he_ltr(s);
         charsetMatch = m.getName();
         CheckAssert(charsetMatch.equals("IBM424_ltr"));
         CheckAssert(m.getLanguage().equals("he"));
+        try {
+            m.getString();
+        } catch (Exception ex) {
+            errln("Error getting string for charsetMatch: " + charsetMatch);
+        }
     }
     
     private CharsetMatch _test1255(String s) throws Exception {