From: Mark Davis Date: Wed, 9 Sep 2015 13:14:46 +0000 (+0000) Subject: ICU-11447 add toString. Just an override of existing API, so not an API change. X-Git-Tag: milestone-59-0-1~902 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1fc1ceab5582a476915c2c2069889b641451aaa5;p=icu ICU-11447 add toString. Just an override of existing API, so not an API change. X-SVN-Rev: 37918 --- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java b/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java index 42c2a456657..bd749daed8c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java @@ -1569,6 +1569,33 @@ public class SpoofChecker { checks = 0; position = 0; } + + private static final String[] NAMES = { + "SINGLE_SCRIPT_CONFUSABLE", + "MIXED_SCRIPT_CONFUSABLE", + "WHOLE_SCRIPT_CONFUSABLE", + "ANY_CASE", + "RESTRICTION_LEVEL", + "INVISIBLE", + "CHAR_LIMIT", + "MIXED_NUMBERS" + }; + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "checks: " + getCheckNames(checks) + + ", numerics: " + numerics.toPattern(false) + + ", position: " + position + + ", restrictionLevel: " + restrictionLevel + ; + } + + static String getCheckNames(int check) { + return check >= 1 && check < (1 << NAMES.length) ? NAMES[(int)Math.round(Math.log10(check)/Math.log10(2))] : null; + } // might be better way to do this, but just threw it together quickly. } /** diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/text/SpoofCheckerTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/text/SpoofCheckerTest.java index e6cbfe29557..e35e7681c89 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/text/SpoofCheckerTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/text/SpoofCheckerTest.java @@ -795,4 +795,20 @@ public class SpoofCheckerTest extends TestFmwk { errln(e.toString()); } } + + public void TestCheckResultToString11447() { + Object[][] tests = { + {"1", "[0]"}, + {"१", "[०]"}, + {"1१", "[0०]"}, + {"١۱", "[٠۰]"}, + }; + CheckResult checkResult = new CheckResult(); + SpoofChecker sc = new SpoofChecker.Builder() + .setChecks(-1) + .build(); + sc.failsChecks("1१", checkResult); + assertTrue("CheckResult: ", checkResult.toString().contains("MIXED_NUMBERS")); + } + }