ICU-990 add a parameter for smart handling of backslashes to prettify()

X-SVN-Rev: 5268
This commit is contained in:
Alan Liu 2001-07-18 18:38:53 +00:00
parent 894e687b54
commit 62314ba406
2 changed files with 18 additions and 2 deletions

View File

@ -336,7 +336,7 @@ IntlTest::prettify(const UnicodeString &source,
// Replace nonprintable characters with unicode escapes // Replace nonprintable characters with unicode escapes
UnicodeString UnicodeString
IntlTest::prettify(const UnicodeString &source) IntlTest::prettify(const UnicodeString &source, UBool parseBackslash)
{ {
int32_t i; int32_t i;
UnicodeString target; UnicodeString target;
@ -349,6 +349,22 @@ IntlTest::prettify(const UnicodeString &source)
if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E) if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E)
{ {
if (parseBackslash) {
// If we are preceded by an odd number of backslashes,
// then this character has already been backslash escaped.
// Delete a backslash.
int32_t backslashCount = 0;
for (int32_t j=target.length()-1; j>=0; --j) {
if (target.charAt(j) == (UChar)92) {
++backslashCount;
} else {
break;
}
}
if ((backslashCount % 2) == 1) {
target.truncate(target.length() - 1);
}
}
target += "\\u"; target += "\\u";
appendHex(ch, 4, target); appendHex(ch, 4, target);
} }

View File

@ -144,7 +144,7 @@ protected:
Collator::EComparisonResult expectedResult ); Collator::EComparisonResult expectedResult );
static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target); static UnicodeString &prettify(const UnicodeString &source, UnicodeString &target);
static UnicodeString prettify(const UnicodeString &source); static UnicodeString prettify(const UnicodeString &source, UBool parseBackslash=FALSE);
static UnicodeString &prettify(const CollationKey &source, UnicodeString &target); static UnicodeString &prettify(const CollationKey &source, UnicodeString &target);
static UnicodeString &appendHex(uint32_t number, int8_t digits, UnicodeString &target); static UnicodeString &appendHex(uint32_t number, int8_t digits, UnicodeString &target);
static UnicodeString &appendCompareResult(Collator::EComparisonResult result, UnicodeString &target); static UnicodeString &appendCompareResult(Collator::EComparisonResult result, UnicodeString &target);