From 5553497e0f0cf4165aaa98166ed0e7f0939e11d1 Mon Sep 17 00:00:00 2001 From: Alan Liu Date: Wed, 24 May 2000 17:27:35 +0000 Subject: [PATCH] Add UInfo-based character property methods X-SVN-Rev: 1452 --- .../icu/dev/test/translit/TestUtility.java | 30 ++++++++++++++++++- .../com/ibm/test/translit/TestUtility.java | 30 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/icu4j/src/com/ibm/icu/dev/test/translit/TestUtility.java b/icu4j/src/com/ibm/icu/dev/test/translit/TestUtility.java index 97e5b5c53f..63e2185317 100755 --- a/icu4j/src/com/ibm/icu/dev/test/translit/TestUtility.java +++ b/icu4j/src/com/ibm/icu/dev/test/translit/TestUtility.java @@ -1,6 +1,10 @@ package com.ibm.test.translit; +import com.ibm.text.UInfo; + public final class TestUtility { + private static UInfo uinfo; + public static byte getScript(char c) { return getScript(getBlock(c)); } @@ -32,6 +36,30 @@ public final class TestUtility { return c; } + // Supplements to Character methods; these methods go through + // UInfo if possible. If not, they fall back to Character. + + public static UInfo getUInfo() { + if (uinfo == null) { + uinfo = new UInfo(); + } + return uinfo; + } + + public static boolean isUnassigned(char c) { + try { + return getUInfo().getCategory(c) == UInfo.UNASSIGNED; + } catch (NullPointerException e) {} + return Character.getType(c) == Character.UNASSIGNED; + } + + public static boolean isLetter(char c) { + try { + return getUInfo().isLetter(c); + } catch (NullPointerException e) {} + return Character.isLetter(c); + } + public static String hex(char ch) { String foo = Integer.toString(ch,16).toUpperCase(); return "0000".substring(0,4-foo.length()) + foo; @@ -51,7 +79,7 @@ public final class TestUtility { return result; } - public static void test() { + public static void main(String[] args) { System.out.println("Blocks: "); byte lastblock = -128; for (char cc = 0; cc < 0xFFFF; ++cc) { diff --git a/icu4j/src/com/ibm/test/translit/TestUtility.java b/icu4j/src/com/ibm/test/translit/TestUtility.java index 97e5b5c53f..63e2185317 100755 --- a/icu4j/src/com/ibm/test/translit/TestUtility.java +++ b/icu4j/src/com/ibm/test/translit/TestUtility.java @@ -1,6 +1,10 @@ package com.ibm.test.translit; +import com.ibm.text.UInfo; + public final class TestUtility { + private static UInfo uinfo; + public static byte getScript(char c) { return getScript(getBlock(c)); } @@ -32,6 +36,30 @@ public final class TestUtility { return c; } + // Supplements to Character methods; these methods go through + // UInfo if possible. If not, they fall back to Character. + + public static UInfo getUInfo() { + if (uinfo == null) { + uinfo = new UInfo(); + } + return uinfo; + } + + public static boolean isUnassigned(char c) { + try { + return getUInfo().getCategory(c) == UInfo.UNASSIGNED; + } catch (NullPointerException e) {} + return Character.getType(c) == Character.UNASSIGNED; + } + + public static boolean isLetter(char c) { + try { + return getUInfo().isLetter(c); + } catch (NullPointerException e) {} + return Character.isLetter(c); + } + public static String hex(char ch) { String foo = Integer.toString(ch,16).toUpperCase(); return "0000".substring(0,4-foo.length()) + foo; @@ -51,7 +79,7 @@ public final class TestUtility { return result; } - public static void test() { + public static void main(String[] args) { System.out.println("Blocks: "); byte lastblock = -128; for (char cc = 0; cc < 0xFFFF; ++cc) {