From f0a074123a5bff3238b528b4e64fedc02c88b804 Mon Sep 17 00:00:00 2001 From: Mark Davis Date: Wed, 26 Nov 2003 23:36:39 +0000 Subject: [PATCH] chart demo X-SVN-Rev: 13900 --- .../ibm/icu/dev/demo/chart/UnicodeChart.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 icu4j/src/com/ibm/icu/dev/demo/chart/UnicodeChart.java diff --git a/icu4j/src/com/ibm/icu/dev/demo/chart/UnicodeChart.java b/icu4j/src/com/ibm/icu/dev/demo/chart/UnicodeChart.java new file mode 100644 index 00000000000..85eefb2d091 --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/demo/chart/UnicodeChart.java @@ -0,0 +1,111 @@ +/* + ******************************************************************************* + * Copyright (C) 1997-2003, International Business Machines Corporation and * + * others. All Rights Reserved. * + ******************************************************************************* + * + * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/demo/chart/UnicodeChart.java,v $ + * $Date: 2003/11/26 23:36:39 $ + * $Revision: 1.1 $ + * + ***************************************************************************************** + */ + +package com.ibm.icu.dev.demo.chart; +import java.io.*; +import com.ibm.icu.dev.test.util.*; +import com.ibm.icu.text.*; +import com.ibm.icu.lang.*; +import com.ibm.icu.impl.*; + +public class UnicodeChart { + public static void main(String[] args) throws IOException { + int rowWidth = 256; + PrintWriter pw = BagFormatter.openUTF8Writer("", "UnicodeChart.html", BagFormatter.CONSOLE); + pw.println(""); + pw.println("Unicode 4.0 Chart"); + pw.println(""); + pw.println(""); + + pw.println(""); + for (int j = 0; j < rowWidth; ++j) { + pw.print(""); + } + pw.println(""); + // TODO: fix Utility to take ints + + int surrogateType = UCharacter.getType('\ud800'); + int privateUseType = UCharacter.getType('\ue000'); + System.out.println("Surrogate Type: Java=" + Character.SURROGATE + ", ICU=" + surrogateType); + System.out.println("Private-Use Type: Java=" + Character.PRIVATE_USE + ", ICU=" + privateUseType); + + boolean gotOne = true; + int columns = 0; + for (int i = 0; i < 0x10FFFF; i += rowWidth) { + boolean gotLast = gotOne; + gotOne = false; + int limit = i + rowWidth; + for (int j = i; j < limit; ++j) { + int type = UCharacter.getType(j); + if (type == Character.UNASSIGNED + && !UCharacter.hasBinaryProperty(j, UProperty.NONCHARACTER_CODE_POINT)) continue; + if (type == surrogateType || type == privateUseType) continue; + gotOne = true; + } + if (!gotOne) { + if (false) { + System.out.println("Skipping: " + hex(i>>8,2) + "__"); + for (int j = i; j < limit; ++j) { + System.out.print(UCharacter.getType(j) + ","); + } + System.out.println(); + } + continue; + }; + System.out.println(hex(i>>8,2) + "__"); + columns++; + pw.print(""); + for (int j = i; j < limit; ++j) { + String value = "\u00a0"; + String cellclass = gotLast ? "" : " class='d'"; + if (UCharacter.hasBinaryProperty(j, UProperty.NONCHARACTER_CODE_POINT)) { + cellclass = gotLast ? " class='n'" : " class='dn'"; + } else if (!UCharacter.isDefined(j)) { + cellclass = gotLast ? " class='u'" : " class='du'"; + } else if (UCharacter.isUWhiteSpace(j)) { + // nothing + } else if (UCharacter.hasBinaryProperty(j, UProperty.DEFAULT_IGNORABLE_CODE_POINT)) { + cellclass = gotLast ? " class='i'" : " class='di'"; + } else { + value = UTF16.valueOf(j); + } + pw.print("" + value + ""); + if ((j & 0xF) == 0xF) { + pw.println(); + } + } + pw.println(""); + } + pw.println("

Unicode 4.0 Chart

" + hex(j,2) + "
" + hex(i>>8,2) + "__

Copyright \u00A9 2003, Mark Davis. All Rights Reserved."); + pw.close(); + System.out.println("columns: " + columns); + } + + static String hex(int i, int padTo) { + String result = Integer.toHexString(i).toUpperCase(java.util.Locale.ENGLISH); + while (result.length() < padTo) result = "0" + result; + return result; + } +} \ No newline at end of file