ICU-4052 fix a number of small problems that got in the way of the CLDR tools.

X-SVN-Rev: 16130
This commit is contained in:
Mark Davis 2004-08-08 16:57:53 +00:00
parent 804ed9fbad
commit 90e8464b3a
6 changed files with 188 additions and 55 deletions

View File

@ -32,21 +32,29 @@ import com.ibm.icu.text.UnicodeSet;
public class BagFormatter {
static final boolean DEBUG = false;
public static final Transliterator toHTML = Transliterator.createFromRules(
"any-html",
private static final String HTML_RULES =
"'<' > '&lt;' ;" +
"'&' > '&amp;' ;" +
"'>' > '&gt;' ;" +
"'\"' > '&quot;' ; ",
Transliterator.FORWARD);
public static final Transliterator fromHTML = Transliterator.createFromRules(
"html-any",
"'<' < '&'[lL][Tt]';' ;" +
"'&' > '&amp;' ;" +
"'&' < '&'[aA][mM][pP]';' ;" +
"'>' > '&gt;' ;" +
"'>' < '&'[gG][tT]';' ;" +
"'\"' < '&'[qQ][uU][oO][tT]';' ; ",
Transliterator.REVERSE);
"'\"' > '&quot;' ; " +
"'\"' < '&'[qQ][uU][oO][tT]';' ; ";
private static final String XML_RULES = HTML_RULES +
"'' > '&apos;' ; " +
"'' < '&'[aA][pP][oO][sS]';' ; ";
public static final Transliterator toXML = Transliterator.createFromRules(
"any-xml", XML_RULES, Transliterator.FORWARD);
public static final Transliterator fromXML = Transliterator.createFromRules(
"xml-any", XML_RULES, Transliterator.REVERSE);
public static final Transliterator toHTML = Transliterator.createFromRules(
"any-html", HTML_RULES, Transliterator.FORWARD);
public static final Transliterator fromHTML = Transliterator.createFromRules(
"html-any", HTML_RULES, Transliterator.REVERSE);
public static final PrintWriter CONSOLE = new PrintWriter(System.out,true);

View File

@ -4457,6 +4457,42 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
}
return 0; // undefined
}
/**
* Returns a string version of the property value.
* @param propertyEnum
* @param codepoint
* @param nameChoice
* @return value as string
* @internal
* @deprecated
*/
public static String getStringPropertyValue(int propertyEnum, int codepoint, int nameChoice) {
// TODO some of these are less efficient, since a string is forced!
if ((propertyEnum >= UProperty.BINARY_START && propertyEnum < UProperty.BINARY_LIMIT) ||
(propertyEnum >= UProperty.INT_START && propertyEnum < UProperty.INT_LIMIT)) {
return getPropertyValueName(propertyEnum, getIntPropertyValue(codepoint, propertyEnum), nameChoice);
}
if (propertyEnum == UProperty.NUMERIC_VALUE) {
return String.valueOf(getUnicodeNumericValue(codepoint));
}
// otherwise must be string property
switch (propertyEnum) {
case UProperty.AGE: return getAge(codepoint).toString();
case UProperty.ISO_COMMENT: return getISOComment(codepoint);
case UProperty.BIDI_MIRRORING_GLYPH: return UTF16.valueOf(getMirror(codepoint));
case UProperty.CASE_FOLDING: return foldCase(UTF16.valueOf(codepoint), true);
case UProperty.LOWERCASE_MAPPING: return toLowerCase(UTF16.valueOf(codepoint));
case UProperty.NAME: return getName(codepoint);
case UProperty.SIMPLE_CASE_FOLDING: return UTF16.valueOf(foldCase(codepoint,true));
case UProperty.SIMPLE_LOWERCASE_MAPPING: return UTF16.valueOf(toLowerCase(codepoint));
case UProperty.SIMPLE_TITLECASE_MAPPING: return UTF16.valueOf(toTitleCase(codepoint));
case UProperty.SIMPLE_UPPERCASE_MAPPING: return UTF16.valueOf(toUpperCase(codepoint));
case UProperty.TITLECASE_MAPPING: return toTitleCase(UTF16.valueOf(codepoint),null);
case UProperty.UNICODE_1_NAME: return getName1_0(codepoint);
case UProperty.UPPERCASE_MAPPING: return toUpperCase(UTF16.valueOf(codepoint));
}
throw new IllegalArgumentException("Illegal Property Enum");
}
/**
* Get the minimum value for an integer/binary Unicode property type.

View File

@ -3844,6 +3844,14 @@ public class DecimalFormat extends NumberFormat {
// given currency.
super.setCurrency(theCurrency);
if (theCurrency != null) {
boolean[] isChoiceFormat = new boolean[1];
String s = theCurrency.getName(symbols.getLocale(),
Currency.SYMBOL_NAME,
isChoiceFormat);
symbols.setCurrencySymbol(s);
symbols.setInternationalCurrencySymbol(theCurrency.getCurrencyCode());
}
if (isCurrencyFormat) {
if (theCurrency != null) {

View File

@ -31,6 +31,9 @@ import com.ibm.icu.util.ByteArrayWrapper;
* // do something with key.bytes
* }
* </code>
* <p><strong>Note:</strong> Comparison between RawCollationKeys created by
* different Collators might return incorrect results.
* See class documentation for Collator.</p>
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
* @see RuleBasedCollator
@ -94,38 +97,4 @@ public final class RawCollationKey extends ByteArrayWrapper
this.size = size;
}
// public method --------------------------------------------------------
/**
* <p>
* Compares this RawCollationKey object to the target RawCollationKey
* object. The collation rules of the Collator that created this key are
* applied.
* </p>
* <p><strong>Note:</strong> Comparison between RawCollationKeys created by
* different Collators might return incorrect results.
* See class documentation.</p>
* @param target RawCollationKey to be compared with
* @return 0 if the sort order is the same,
* &lt; 0 if this RawCollationKey has a smaller sort order than
* target,
* &gt; 0 if this RawCollationKey has a bigger sort order than
* target.
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public int compareTo(RawCollationKey target)
{
for (int i = 0;; ++i) {
int l = bytes[i]&0xff;
int r = target.bytes[i]&0xff;
if (l < r) {
return -1;
} else if (l > r) {
return 1;
} else if (l == 0) {
return 0;
}
}
}
}

View File

@ -1691,7 +1691,7 @@ public final class RuleBasedCollator extends Collator
}
}
catch (Exception e) {
e.printStackTrace();
// e.printStackTrace();
// if failed use UCA.
}
}

View File

@ -7,6 +7,10 @@
package com.ibm.icu.util;
import java.nio.ByteBuffer;
import com.ibm.icu.impl.Utility;
/**
* <p>
* A simple utility class to wrap a byte array.
@ -20,7 +24,7 @@ package com.ibm.icu.util;
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public class ByteArrayWrapper
public class ByteArrayWrapper implements Comparable
{
// public data member ------------------------------------------------
@ -47,6 +51,39 @@ public class ByteArrayWrapper
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public ByteArrayWrapper() {
bytes = new byte[0]; // for consistency
}
/**
* Create from ByteBuffer
* @param byteBuffer
*/
public ByteArrayWrapper(ByteBuffer source) {
size = source.limit();
bytes = new byte[size];
source.get(bytes,0,size);
}
/**
* Create from ByteBuffer
* @param byteBuffer
*/
public ByteArrayWrapper(ByteArrayWrapper source) {
size = source.size;
bytes = new byte[size];
copyBytes(source.bytes, 0, bytes, 0, size);
}
/**
* create from byte buffer
* @param src
* @param start
* @param limit
*/
public ByteArrayWrapper(byte[] src, int start, int limit) {
size = limit - start;
bytes = new byte[size];
copyBytes(src, start, bytes, 0, size);
}
// public methods ----------------------------------------------------
@ -60,13 +97,14 @@ public class ByteArrayWrapper
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public void ensureCapacity(int capacity)
public ByteArrayWrapper ensureCapacity(int capacity)
{
if (bytes == null || bytes.length < capacity) {
byte[] newbytes = new byte[capacity];
copyBytes(bytes, 0, newbytes, 0, size);
bytes = newbytes;
}
return this;
}
/**
@ -80,10 +118,19 @@ public class ByteArrayWrapper
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public final void set(byte[] src, int start, int limit)
public final ByteArrayWrapper set(byte[] src, int start, int limit)
{
size = 0;
append(src, start, limit);
return this;
}
public final ByteArrayWrapper get(byte[] target, int start, int limit)
{
int len = limit - start;
if (len > size) throw new IllegalArgumentException("limit too long");
copyBytes(bytes, 0, target, start, len);
return this;
}
/**
@ -96,14 +143,31 @@ public class ByteArrayWrapper
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public final void append(byte[] src, int start, int limit)
public final ByteArrayWrapper append(byte[] src, int start, int limit)
{
int len = limit - start;
ensureCapacity(size + len);
copyBytes(src, start, bytes, size, len);
size += len;
return this;
}
/**
* Appends the internal byte array from offset size with the
* contents of src from offset start to limit. This increases the size of
* the internal byte array to (size + limit - start).
* @param src source byte array to copy from
* @param start start offset of src to copy from
* @param limit end + 1 offset of src to copy from
* @draft ICU 2.8
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public final ByteArrayWrapper append(ByteArrayWrapper other)
{
return append(other.bytes, 0, other.size);
}
/**
* Releases the internal byte array to the caller, resets the internal
* byte array to null and its size to 0.
@ -119,6 +183,54 @@ public class ByteArrayWrapper
return result;
}
// Boilerplate ----------------------------------------------------
/**
* Returns string value for debugging
*/
public String toString() {
StringBuffer result = new StringBuffer();
for (int i = 0; i < size; ++i) {
if (i != 0) result.append(" ");
result.append(Utility.hex(bytes[i]&0xFF,2));
}
return result.toString();
}
public boolean equals(Object other) {
if (this == other) return true;
if (other == null) return false;
ByteArrayWrapper that = (ByteArrayWrapper) other;
if (size != that.size) return false;
for (int i = 0; i < size; ++i) {
if (bytes[i] != that.bytes[i]) return false;
}
return true;
}
public int getHashCode(Object object) {
int result = bytes.length;
for (int i = 0; i < size; ++i) {
result = 37*result + bytes[i];
}
return result;
}
public int compareTo(Object other) {
if (this == other) return 0;
if (other == null) return 1;
ByteArrayWrapper that = (ByteArrayWrapper) other;
int minSize = size < that.size ? size : that.size;
for (int i = 0; i < minSize; ++i) {
if (bytes[i] == that.bytes[i]) continue;
if ((bytes[i] & 0xFF) < (that.bytes[i] & 0xFF)) return -1;
return 1;
}
if (size == that.size) return 0;
if (size < that.size) return -1;
return 1;
}
// private methods -----------------------------------------------------
/**