ICU-8795 Remove suffix when CharsetMatch is creating a new string

X-SVN-Rev: 30648
This commit is contained in:
Michael Ow 2011-09-13 18:10:10 +00:00
parent 8981a441b2
commit 844d3c5e1f
2 changed files with 22 additions and 2 deletions

View 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;

View 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 {