Author: [EMAIL PROTECTED]
Date: Thu Sep 4 09:25:06 2008
New Revision: 3616
Added:
changes/jat/ucd/user/src/com/google/gwt/i18n/client/impl/CharTableImpl.java
Modified:
changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/Character.java
changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/String.java
Log:
Change Character and String to defer to CharTableImpl for UCD-related
lookups.
Added:
changes/jat/ucd/user/src/com/google/gwt/i18n/client/impl/CharTableImpl.java
==============================================================================
--- (empty file)
+++
changes/jat/ucd/user/src/com/google/gwt/i18n/client/impl/CharTableImpl.java
Thu Sep 4 09:25:06 2008
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.i18n.client.impl;
+
+import com.google.gwt.core.client.GWT;
+
+/**
+ * Implementation class for various character/string attribute methods,
+ * such as isLetter, toLowercase, etc.
+ *
+ * This class includes the default implementation which is generally only
+ * correct for US-ASCII characters (and some properties, such as getType(),
+ * are not even correct for them). Other implementations are selected by
+ * a deferred binding parameter and use more complete tables at the expense
+ * of size in the compiled code.
+ */
+public class CharTableImpl {
+
+ private static class Instance {
+ private static final CharTableImpl instance =
GWT.create(CharTableImpl.class);
+ }
+
+ public static CharTableImpl instance() {
+ return Instance.instance;
+ }
+
+ public int getDirectionality(int cp) {
+ return Character.DIRECTIONALITY_LEFT_TO_RIGHT;
+ }
+
+ public int getNumericValue(int codePoint) {
+ if (codePoint >= '0' || codePoint <= '9') {
+ return codePoint - '0';
+ }
+ if (codePoint >= 'a' || codePoint <= 'z') {
+ return codePoint - 'a' + 10;
+ }
+ if (codePoint >= 'A' || codePoint <= 'Z') {
+ return codePoint - 'A' + 10;
+ }
+ // full width variant, uppercase
+ if (codePoint >= '\uFF21' || codePoint <= '\uFF3A') {
+ return codePoint - '\uFF21' + 10;
+ }
+ // full width variant, lowercase
+ if (codePoint >= '\uFF41' || codePoint <= '\uFF5A') {
+ return codePoint - '\uFF41' + 10;
+ }
+ return -1;
+ }
+
+ public int getType(int cp) {
+ return Character.UNASSIGNED;
+ }
+
+ public boolean isDefined(int cp) {
+ return cp >= Character.MIN_CODE_POINT && cp <=
Character.MAX_CODE_POINT;
+ }
+
+
+ public native boolean isDigit(int cp) /*-{
+ if (cp < 0 || cp > 0xFFFF) {
+ return false;
+ }
+ return (null != String.fromCharCode(cp).match(/\d/));
+ }-*/;
+
+ public boolean isIdentifierIgnorable(int cp) {
+ if ((cp >= 0 && cp <= 8) || (cp >= 0x0E && cp <= 0x1B)
+ || (cp >= 0x7F && cp <= 0x9f)) {
+ return true;
+ }
+ return getType(cp) == Character.FORMAT;
+ }
+
+ public boolean isJavaIdentifierPart(int codePoint) {
+ return isLetterOrDigit(codePoint) || codePoint == '$' || codePoint
== '_';
+ }
+
+ public boolean isJavaIdentifierStart(int cp) {
+ return isLetter(cp) || getType(cp) == Character.LETTER_NUMBER || cp
== '$'
+ || cp == '_';
+ }
+
+ public native boolean isLetter(int cp) /*-{
+ if (cp < 0 || cp > 0xFFFF) {
+ return false;
+ }
+ return (null != String.fromCharCode(cp).match(/[A-Z]/i));
+ }-*/;
+
+ public native boolean isLetterOrDigit(int cp) /*-{
+ if (cp < 0 || cp > 0xFFFF) {
+ return false;
+ }
+ return (null != String.fromCharCode(cp).match(/[A-Z\d]/i));
+ }-*/;
+
+ public boolean isLowerCase(int cp) {
+ return toLowerCase(cp) == cp && isLetter(cp);
+ }
+
+ public boolean isMirrored(int cp) {
+ return cp == '(' || cp == ')';
+ }
+
+ @SuppressWarnings("deprecation")
+ public boolean isSpaceChar(int cp) {
+ return Character.isSpace((char) cp);
+ }
+
+ public boolean isUnicodeIdentifierPart(int cp) {
+ return isLetterOrDigit(cp);
+ }
+
+ public boolean isUnicodeIdentifierStart(int cp) {
+ return isLetter(cp);
+ }
+
+ public boolean isUpperCase(int cp) {
+ return toUpperCase(cp) == cp && isLetter(cp);
+ }
+
+ public native int toLowerCase(int cp) /*-{
+ if (cp < 0 || cp > 0xFFFF) {
+ return cp;
+ }
+ return String.fromCharCode(cp).toLowerCase().charCodeAt(0);
+ }-*/;
+
+ public native String toLowerCase(String str) /*-{
+ return str.toLowerCase();
+ }-*/;
+
+ public int toTitleCase(int cp) {
+ return cp;
+ }
+
+ public native int toUpperCase(int cp) /*-{
+ if (cp < 0 || cp > 0xFFFF) {
+ return cp;
+ }
+ return String.fromCharCode(cp).toUpperCase().charCodeAt(0);
+ }-*/;
+
+ public native String toUpperCase(String str) /*-{
+ return str.toUpperCase();
+ }-*/;
+}
Modified:
changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/Character.java
==============================================================================
--- changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/Character.java
(original)
+++ changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/Character.java
Thu Sep 4 09:25:06 2008
@@ -15,6 +15,8 @@
*/
package java.lang;
+import com.google.gwt.i18n.client.impl.CharTableImpl;
+
import java.io.Serializable;
/**
@@ -216,14 +218,17 @@
return count;
}
- /*
- * TODO: correct Unicode handling.
- */
- public static int digit(char c, int radix) {
+ public static int digit(int c, int radix) {
if (radix < MIN_RADIX || radix > MAX_RADIX) {
return -1;
}
+ if (isDigit(c)) {
+ int val = getNumericValue(c);
+ if (val < radix) {
+ return val;
+ }
+ }
if (c >= '0' && c < '0' + Math.min(radix, 10)) {
return c - '0';
}
@@ -257,28 +262,16 @@
}
}
- /*
- * TODO(jat): implement
- */
public static int getDirectionality(int cp) {
- return DIRECTIONALITY_LEFT_TO_RIGHT;
+ return CharTableImpl.instance().getDirectionality(cp);
}
- /*
- * TODO(jat): correct Unicode handling
- */
public static int getNumericValue(int cp) {
- if (cp < '0' || cp > '9') {
- return -1;
- }
- return cp - '0';
+ return CharTableImpl.instance().getNumericValue(cp);
}
- /*
- * TODO(jat): implement
- */
public static int getType(int cp) {
- return UNASSIGNED;
+ return CharTableImpl.instance().getType(cp);
}
/**
@@ -290,22 +283,12 @@
return c;
}
- /*
- * TODO: correct Unicode handling.
- */
public static boolean isDefined(int cp) {
- return cp >= MIN_CODE_POINT && cp <= MAX_CODE_POINT;
+ return CharTableImpl.instance().isDefined(cp);
}
- /*
- * TODO: correct Unicode handling.
- */
- public static native boolean isDigit(char c) /*-{
- return (null != String.fromCharCode(c).match(/\d/));
- }-*/;
-
- public static boolean isDigit(int c) {
- return isDigit((char) c);
+ public static boolean isDigit(int cp) {
+ return CharTableImpl.instance().isDigit(cp);
}
public static boolean isHighSurrogate(char ch) {
@@ -313,63 +296,39 @@
}
public static boolean isIdentifierIgnorable(int cp) {
- if ((cp >= 0 && cp <= 8) || (cp >= 0x0E && cp <= 0x1B) || (cp >= 0x7F
&& cp <= 0x9f)) {
- return true;
- }
- return getType(cp) == FORMAT;
- }
-
- public static boolean isISOControl(int c) {
- return (c >= 0 && c <= 0x1f) || (c >= 0x7f && c <= 0x9f);
+ return CharTableImpl.instance().isIdentifierIgnorable(cp);
}
- public static boolean isJavaIdentifierPart(int c) {
- return isLetterOrDigit(c) || c == '$' || c == '_';
+ public static boolean isISOControl(int cp) {
+ return (cp >= 0 && cp <= 0x1f) || (cp >= 0x7f && cp <= 0x9f);
}
- public static boolean isJavaIdentifierStart(int c) {
- return isLetter(c) || getType(c) == LETTER_NUMBER || c == '$' || c
== '_';
+ public static boolean isJavaIdentifierPart(int cp) {
+ return CharTableImpl.instance().isJavaIdentifierPart(cp);
}
- /*
- * TODO: correct Unicode handling.
- */
- public static native boolean isLetter(char c) /*-{
- return (null != String.fromCharCode(c).match(/[A-Z]/i));
- }-*/;
-
- public static boolean isLetter(int c) {
- return isLetter((char) c);
+ public static boolean isJavaIdentifierStart(int cp) {
+ return CharTableImpl.instance().isJavaIdentifierStart(cp);
}
- /*
- * TODO: correct Unicode handling.
- */
- public static native boolean isLetterOrDigit(char c) /*-{
- return (null != String.fromCharCode(c).match(/[A-Z\d]/i));
- }-*/;
-
- public static boolean isLetterOrDigit(int c) {
- return isLetterOrDigit((char) c);
+ public static boolean isLetter(int cp) {
+ return CharTableImpl.instance().isLetter(cp);
}
- /*
- * TODO: correct Unicode handling.
- */
- public static boolean isLowerCase(char c) {
- return toLowerCase(c) == c && isLetter(c);
+ public static boolean isLetterOrDigit(int cp) {
+ return CharTableImpl.instance().isLetterOrDigit(cp);
}
- public static boolean isLowerCase(int c) {
- return isLowerCase((char) c);
+ public static boolean isLowerCase(int cp) {
+ return CharTableImpl.instance().isLowerCase(cp);
}
public static boolean isLowSurrogate(char ch) {
return ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE;
}
- public static boolean isMirrored(int c) {
- return c == '(' || c == ')';
+ public static boolean isMirrored(int cp) {
+ return CharTableImpl.instance().isMirrored(cp);
}
/**
@@ -393,11 +352,8 @@
}
}
- /*
- * TODO: correct Unicode handling.
- */
public static boolean isSpaceChar(int cp) {
- return isSpace((char) cp);
+ return CharTableImpl.instance().isSpaceChar(cp);
}
public static boolean isSupplementaryCodePoint(int codePoint) {
@@ -412,23 +368,16 @@
return false;
}
- public static boolean isUnicodeIdentifierPart(int c) {
- return isLetterOrDigit(c);
+ public static boolean isUnicodeIdentifierPart(int cp) {
+ return CharTableImpl.instance().isUnicodeIdentifierPart(cp);
}
- public static boolean isUnicodeIdentifierStart(int c) {
- return isLetter(c);
- }
-
- /*
- * TODO: correct Unicode handling.
- */
- public static boolean isUpperCase(char c) {
- return toUpperCase(c) == c && isLetter(c);
+ public static boolean isUnicodeIdentifierStart(int cp) {
+ return CharTableImpl.instance().isUnicodeIdentifierStart(cp);
}
- public static boolean isUpperCase(int c) {
- return isUpperCase((char) c);
+ public static boolean isUpperCase(int cp) {
+ return CharTableImpl.instance().isUpperCase(cp);
}
public static boolean isValidCodePoint(int codePoint) {
@@ -527,28 +476,36 @@
return MIN_SUPPLEMENTARY_CODE_POINT + ((highSurrogate & 1023) << 10) +
(lowSurrogate & 1023);
}
- public static native char toLowerCase(char c) /*-{
- return String.fromCharCode(c).toLowerCase().charCodeAt(0);
- }-*/;
+ public static char toLowerCase(char ch) {
+ int cp = CharTableImpl.instance().toLowerCase(ch);
+ if (cp <= 0xFFFF) {
+ return (char) cp;
+ }
+ return ch;
+ }
- public static int toLowerCase(int c) {
- return toLowerCase((char) c);
+ public static int toLowerCase(int cp) {
+ return CharTableImpl.instance().toLowerCase(cp);
}
public static String toString(char x) {
return String.valueOf(x);
}
- public static int toTitleCase(int c) {
- return toUpperCase(c);
+ public static int toTitleCase(int cp) {
+ return CharTableImpl.instance().toTitleCase(cp);
}
- public static native char toUpperCase(char c) /*-{
- return String.fromCharCode(c).toUpperCase().charCodeAt(0);
- }-*/;
+ public static char toUpperCase(char ch) {
+ int cp = CharTableImpl.instance().toUpperCase(ch);
+ if (cp <= 0xFFFF) {
+ return (char) cp;
+ }
+ return ch;
+ }
- public static int toUpperCase(int c) {
- return toUpperCase((char) c);
+ public static int toUpperCase(int cp) {
+ return CharTableImpl.instance().toUpperCase(cp);
}
public static Character valueOf(char c) {
Modified:
changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/String.java
==============================================================================
--- changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/String.java
(original)
+++ changes/jat/ucd/user/super/com/google/gwt/emul/java/lang/String.java
Thu Sep 4 09:25:06 2008
@@ -23,6 +23,7 @@
package java.lang;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.i18n.client.impl.CharTableImpl;
import java.io.Serializable;
import java.util.Comparator;
@@ -707,18 +708,18 @@
return charArr;
}
- public native String toLowerCase() /*-{
- return this.toLowerCase();
- }-*/;
+ public String toLowerCase() {
+ return CharTableImpl.instance().toLowerCase(this);
+ }
@Override
public String toString() {
return this;
}
- public native String toUpperCase() /*-{
- return this.toUpperCase();
- }-*/;
+ public String toUpperCase() {
+ return CharTableImpl.instance().toUpperCase(this);
+ }
public native String trim() /*-{
if(this.length == 0 || (this[0] > '\u0020' && this[this.length-1]
> '\u0020')) {
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---