ICU-3400 make UnicodeSet.toPattern() prefer [ab] over [a-b]

X-SVN-Rev: 14558
This commit is contained in:
Alan Liu 2004-02-20 23:32:06 +00:00
parent 53056e10ac
commit 8f1373d83c
2 changed files with 22 additions and 9 deletions

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/translit/UnicodeSetTest.java,v $
* $Date: 2003/10/13 23:47:14 $
* $Revision: 1.55 $
* $Date: 2004/02/20 23:31:54 $
* $Revision: 1.56 $
*
*****************************************************************************************
*/
@ -582,9 +582,10 @@ public class UnicodeSetTest extends TestFmwk {
}
/**
* Test pattern behavior of multicharacter strings.
* Test toPattern().
*/
public void TestStringPatterns() {
public void TestToPattern() {
// Test pattern behavior of multicharacter strings.
UnicodeSet s = new UnicodeSet("[a-z {aa} {ab}]");
expectToPattern(s, "[a-z{aa}{ab}]",
new String[] {"aa", "ab", NOT, "ac"});
@ -608,7 +609,12 @@ public class UnicodeSetTest extends TestFmwk {
s.add("abc");
expectToPattern(s, "[{abc}]",
new String[] {"abc", NOT, "ab"});
}
// JB#3400: For 2 character ranges prefer [ab] to [a-b]
s.clear();
s.add('a', 'b');
expectToPattern(s, "[ab]", null);
}
static final Integer
I_ANY = new Integer(SortedSetRelation.ANY),
@ -1596,6 +1602,9 @@ public class UnicodeSetTest extends TestFmwk {
errln("FAIL: toPattern() => \"" + pat + "\", expected \"" + expPat + "\"");
return;
}
if (expStrings == null) {
return;
}
boolean in = true;
for (int i=0; i<expStrings.length; ++i) {
if (expStrings[i] == NOT) { // sic; pointer comparison

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UnicodeSet.java,v $
* $Date: 2003/12/02 01:34:31 $
* $Revision: 1.105 $
* $Date: 2004/02/20 23:32:06 $
* $Revision: 1.106 $
*
*****************************************************************************************
*/
@ -639,7 +639,9 @@ public class UnicodeSet extends UnicodeFilter {
int end = getRangeStart(i)-1;
_appendToPat(result, start, escapeUnprintable);
if (start != end) {
result.append('-');
if ((start+1) != end) {
result.append('-');
}
_appendToPat(result, end, escapeUnprintable);
}
}
@ -652,7 +654,9 @@ public class UnicodeSet extends UnicodeFilter {
int end = getRangeEnd(i);
_appendToPat(result, start, escapeUnprintable);
if (start != end) {
result.append('-');
if ((start+1) != end) {
result.append('-');
}
_appendToPat(result, end, escapeUnprintable);
}
}