]> granicus.if.org Git - icu/commitdiff
ICU-11447 add toString. Just an override of existing API, so not an API change.
authorMark Davis <mark@macchiato.com>
Wed, 9 Sep 2015 13:14:46 +0000 (13:14 +0000)
committerMark Davis <mark@macchiato.com>
Wed, 9 Sep 2015 13:14:46 +0000 (13:14 +0000)
X-SVN-Rev: 37918

icu4j/main/classes/core/src/com/ibm/icu/text/SpoofChecker.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/text/SpoofCheckerTest.java

index 42c2a456657205a5a68b85bfbc54e4a2203fc48e..bd749daed8c7e81795ec496a0224a8047d360b5c 100644 (file)
@@ -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.
     }
 
     /**
index e6cbfe29557a7d5369b4375ba7a507c465cc917b..e35e7681c89ecc7998aef6eecdc387380e593af8 100644 (file)
@@ -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"));
+    }
+
 }