From 62314ba40649dad2cead9d71bbec5fe77ff7dfbf Mon Sep 17 00:00:00 2001 From: Alan Liu Date: Wed, 18 Jul 2001 18:38:53 +0000 Subject: [PATCH] ICU-990 add a parameter for smart handling of backslashes to prettify() X-SVN-Rev: 5268 --- icu4c/source/test/intltest/intltest.cpp | 18 +++++++++++++++++- icu4c/source/test/intltest/intltest.h | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/icu4c/source/test/intltest/intltest.cpp b/icu4c/source/test/intltest/intltest.cpp index f6427ff460..add312860b 100644 --- a/icu4c/source/test/intltest/intltest.cpp +++ b/icu4c/source/test/intltest/intltest.cpp @@ -336,7 +336,7 @@ IntlTest::prettify(const UnicodeString &source, // Replace nonprintable characters with unicode escapes UnicodeString -IntlTest::prettify(const UnicodeString &source) +IntlTest::prettify(const UnicodeString &source, UBool parseBackslash) { int32_t i; UnicodeString target; @@ -349,6 +349,22 @@ IntlTest::prettify(const UnicodeString &source) 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"; appendHex(ch, 4, target); } diff --git a/icu4c/source/test/intltest/intltest.h b/icu4c/source/test/intltest/intltest.h index d1f8bed95f..f929353ce4 100644 --- a/icu4c/source/test/intltest/intltest.h +++ b/icu4c/source/test/intltest/intltest.h @@ -144,7 +144,7 @@ protected: Collator::EComparisonResult expectedResult ); 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 &appendHex(uint32_t number, int8_t digits, UnicodeString &target); static UnicodeString &appendCompareResult(Collator::EComparisonResult result, UnicodeString &target);