From 48b4c5cb07b64a25c427383ad2e59b3d1f44eea3 Mon Sep 17 00:00:00 2001 From: dchandler Date: Sat, 17 Jan 2004 17:10:12 +0000 Subject: [PATCH] Added a Unicode->ASCII dump for debugging *->Unicode conversions. To use it, use 'java -cp Jskad.jar org.thdl.util.VerboseUnicodeDump'. --- .../thdl/tib/text/tshegbar/UnicodeUtils.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/source/org/thdl/tib/text/tshegbar/UnicodeUtils.java b/source/org/thdl/tib/text/tshegbar/UnicodeUtils.java index 466ae7a..551079d 100644 --- a/source/org/thdl/tib/text/tshegbar/UnicodeUtils.java +++ b/source/org/thdl/tib/text/tshegbar/UnicodeUtils.java @@ -298,6 +298,16 @@ public class UnicodeUtils implements UnicodeConstants { characters will appear as themselves. */ public static String unicodeCodepointToString(char cp, boolean shortenIfPossible) { + return unicodeCodepointToString(cp, shortenIfPossible, "\\u"); + } + + /** Like {@link #unicodeCodepointToString(char, boolean)} if you + pass in "\\u" as prefix. If you pass in the + empty string as prefix, then U+0F55 will print as + 0F55. */ + public static String unicodeCodepointToString(char cp, + boolean shortenIfPossible, + String prefix) { if (shortenIfPossible) { if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') @@ -327,22 +337,22 @@ public class UnicodeUtils implements UnicodeConstants { || cp == '{' || cp == '}') return new String(new char[] { cp }); + if ('\t' == cp) + return "\\t"; + if ('\n' == cp) + return "\\n"; + if ('\r' == cp) + return "\\r"; } - if ('\t' == cp) - return "\\t"; - if ('\n' == cp) - return "\\n"; - if ('\r' == cp) - return "\\r"; if (cp < '\u0010') - return "\\u000" + Integer.toHexString((int)cp); + return prefix + "000" + Integer.toHexString((int)cp); else if (cp < '\u0100') - return "\\u00" + Integer.toHexString((int)cp); + return prefix + "00" + Integer.toHexString((int)cp); else if (cp < '\u1000') - return "\\u0" + Integer.toHexString((int)cp); + return prefix + "0" + Integer.toHexString((int)cp); else - return "\\u" + Integer.toHexString((int)cp); + return prefix + Integer.toHexString((int)cp); } /**