ICU-2309 Modularize ICU4J big bang commit
X-SVN-Rev: 10912
This commit is contained in:
parent
8c64e1bb22
commit
573dc7ae2e
408
icu4j/build.xml
408
icu4j/build.xml
@ -6,8 +6,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/build.xml,v $
|
||||
* $Date: 2002/12/13 00:19:40 $
|
||||
* $Revision: 1.62 $
|
||||
* $Date: 2003/01/28 18:55:30 $
|
||||
* $Revision: 1.63 $
|
||||
*
|
||||
*******************************************************************************
|
||||
* This is the ant build file for ICU4J. See readme.html for more information.
|
||||
@ -20,27 +20,27 @@
|
||||
<property name="icu4j.tempdir" value="tmp"/>
|
||||
<property name="clover.initstring" value="${icu4j.tempdir}/icu4j.db"/>
|
||||
<path id="clover.classpath">
|
||||
<!-- ***** you will need to change the paths below to point
|
||||
to clover.jar and velocity.jar on your filesystem ***** -->
|
||||
<!-- ***** you will need to change the paths below to point
|
||||
to clover.jar and velocity.jar on your filesystem ***** -->
|
||||
<pathelement path="${java.class.path}/"/>
|
||||
<pathelement location="clover.jar"/>
|
||||
<pathelement location="velocity.jar"/>
|
||||
<pathelement location="clover.jar"/>
|
||||
<pathelement location="velocity.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- target to switch Clover on -->
|
||||
<target name="with.clover">
|
||||
<property name="build.compiler" value="org.apache.tools.ant.taskdefs.CloverCompilerAdapter"/>
|
||||
<property name="build.compiler" value="org.apache.tools.ant.taskdefs.CloverCompilerAdapter"/>
|
||||
|
||||
<!-- instruct clover to use a class-based instrumentation strategy when instrumenting SimpleTimeZone.java -->
|
||||
<property name="clover.useclass.includes" value="**/SimpleTimeZone.java"/>
|
||||
<!-- instruct clover to use a class-based instrumentation strategy when instrumenting SimpleTimeZone.java -->
|
||||
<property name="clover.useclass.includes" value="**/SimpleTimeZone.java"/>
|
||||
</target>
|
||||
|
||||
<!-- target to generate a Clover html report -->
|
||||
<target name="clover.report">
|
||||
<java classname="com.cortexeb.tools.clover.reporters.html.HtmlReporter" fork="yes">
|
||||
<arg line="--outputdir ${icu4j.tempdir}/icu4j_html --showSrc --initstring ${clover.initstring} --title 'icu4j core'"/>
|
||||
<classpath refid="clover.classpath"/>
|
||||
</java>
|
||||
<java classname="com.cortexeb.tools.clover.reporters.html.HtmlReporter" fork="yes">
|
||||
<arg line="--outputdir ${icu4j.tempdir}/icu4j_html --showSrc --initstring ${clover.initstring} --title 'icu4j core'"/>
|
||||
<classpath refid="clover.classpath"/>
|
||||
</java>
|
||||
</target>
|
||||
<!-- ### end clover setup ### -->
|
||||
|
||||
@ -51,14 +51,14 @@
|
||||
override it, which we used to do for Ant 1.4. -->
|
||||
<condition property="version.1.4">
|
||||
<or>
|
||||
<equals arg1="${ant.java.version}" arg2="1.4"/>
|
||||
<equals arg1="${ant.java.version}" arg2="1.4"/>
|
||||
</or>
|
||||
</condition>
|
||||
|
||||
<condition property="doc.params"
|
||||
value="-breakiterator -use -tagletpath ./classes -taglet com.ibm.icu.dev.tool.docs.ICUTaglet -group 'ICU Core' 'com.ibm.icu.lang*:com.ibm.icu.math*:com.ibm.icu.text*:com.ibm.icu.util*' -group 'ICU Tools' 'com.ibm.icu.dev*' -group 'Rich Text Editing' 'com.ibm.richtext*'">
|
||||
<condition property="doc.params"
|
||||
value="-breakiterator -use -tagletpath ./classes -taglet com.ibm.icu.dev.tool.docs.ICUTaglet -group 'ICU Core' 'com.ibm.icu.lang*:com.ibm.icu.math*:com.ibm.icu.text*:com.ibm.icu.util*' -group 'ICU Tools' 'com.ibm.icu.dev*' -group 'Rich Text Editing' 'com.ibm.richtext*'">
|
||||
<equals arg1="${version.1.4}" arg2="true"/>
|
||||
</condition>
|
||||
</condition>
|
||||
</target>
|
||||
|
||||
<target name="anthack2" unless="doc.params">
|
||||
@ -75,10 +75,10 @@
|
||||
<property name="zip.file" value="../icu4j${DSTAMP}.zip"/>
|
||||
<property name="zipSrc.file" value="../icu4jSrc${DSTAMP}.zip"/>
|
||||
|
||||
<path id="build.classpath">
|
||||
<pathelement path="${build.dir}"/>
|
||||
<path refid="clover.classpath"/>
|
||||
</path>
|
||||
<path id="build.classpath">
|
||||
<pathelement path="${build.dir}"/>
|
||||
<path refid="clover.classpath"/>
|
||||
</path>
|
||||
|
||||
<property name="richedit.dir" value="richedit"/>
|
||||
<property name="richedit.doc.dir" value="${richedit.dir}/doc"/>
|
||||
@ -87,10 +87,10 @@
|
||||
<property name="richedit.manifest" value="${src.dir}/com/ibm/richtext/manifest.stub"/>
|
||||
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<uptodate property="icu4j.resources" targetfile="${src.dir}/com/ibm/icu/impl/data/ICULocaleData.jar">
|
||||
<!-- note must not have '/' before 'com' in srcfiles includes arg! -->
|
||||
<srcfiles dir="${build.dir}" includes="com/ibm/icu/impl/data/LocaleElements_index.class"/>
|
||||
</uptodate>
|
||||
<uptodate property="icu4j.resources" targetfile="${src.dir}/com/ibm/icu/impl/data/ICULocaleData.jar">
|
||||
<!-- note must not have '/' before 'com' in srcfiles includes arg! -->
|
||||
<srcfiles dir="${build.dir}" includes="com/ibm/icu/impl/data/LocaleElements_index.class"/>
|
||||
</uptodate>
|
||||
<echo message="java home: ${java.home}"/>
|
||||
<echo message="java version: ${java.version}"/>
|
||||
<echo message="ant java version: ${ant.java.version}"/>
|
||||
@ -100,63 +100,63 @@
|
||||
<!-- build everything but dist-related stuff -->
|
||||
<target name="all" depends="core,tests,tools,richedit,demos,jar,docs"/>
|
||||
|
||||
<target name="resources" depends="init">
|
||||
<!-- use this target to force resources to be rebuilt -->
|
||||
<unjar src="${src.dir}/com/ibm/icu/impl/data/ICULocaleData.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/com/ibm/icu/impl/data/LocaleElements_index.class"/>
|
||||
</target>
|
||||
<target name="resources" depends="init">
|
||||
<!-- use this target to force resources to be rebuilt -->
|
||||
<unjar src="${src.dir}/com/ibm/icu/impl/data/ICULocaleData.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/com/ibm/icu/impl/data/LocaleElements_index.class"/>
|
||||
</target>
|
||||
|
||||
<target name="_resources" depends="init" if="icu4j.resources">
|
||||
<!-- use this target to conditionally build resources only if icu4j.resources is set -->
|
||||
<unjar src="${src.dir}/com/ibm/icu/impl/data/ICULocaleData.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/com/ibm/icu/impl/data/LocaleElements_index.class"/>
|
||||
</target>
|
||||
<target name="_resources" depends="init" if="icu4j.resources">
|
||||
<!-- use this target to conditionally build resources only if icu4j.resources is set -->
|
||||
<unjar src="${src.dir}/com/ibm/icu/impl/data/ICULocaleData.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/com/ibm/icu/impl/data/LocaleElements_index.class"/>
|
||||
</target>
|
||||
|
||||
<!-- core does not build richedit or tests -->
|
||||
<!-- core does not build richedit or tests -->
|
||||
<target name="core" depends="init,coreData,_resources">
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/thai_dict"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/><!-- only needed if you are using html reporter -->
|
||||
<javac includes="com/ibm/icu/util/**/*.java,com/ibm/icu/text/**/*.java,com/ibm/icu/math/**/*.java,com/ibm/icu/impl/**/*.java,com/ibm/icu/lang/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<target name="tests" depends="core,testData">
|
||||
<javac includes="com/ibm/icu/dev/test/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<target name="demos" depends="core,testData">
|
||||
<javac includes="com/ibm/icu/dev/demo/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<target name="one4tools" depends="anthack1,anthack2" if="version.1.4">
|
||||
<javac includes="com/ibm/icu/dev/tool/docs/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<target name="tools" depends="core,one4tools">
|
||||
<javac includes="com/ibm/icu/dev/tool/**/*.java"
|
||||
excludes="com/ibm/icu/dev/tool/docs/*,**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
@ -170,12 +170,12 @@
|
||||
sourcepath="${src.dir}"
|
||||
destdir="${doc.dir}"
|
||||
nodeprecatedlist="true"
|
||||
windowtitle="icu4j"
|
||||
doctitle="icu4j"
|
||||
encoding="iso-8859-1"
|
||||
docencoding="iso-8859-1"
|
||||
bottom="<font size=-1>Copyright (c) 2002 IBM Corporation and others.</font>"
|
||||
additionalparam="${doc.params}"
|
||||
windowtitle="icu4j"
|
||||
doctitle="icu4j"
|
||||
encoding="iso-8859-1"
|
||||
docencoding="iso-8859-1"
|
||||
bottom="<font size=-1>Copyright (c) 2002 IBM Corporation and others.</font>"
|
||||
additionalparam="${doc.params}"
|
||||
/>
|
||||
</target>
|
||||
|
||||
@ -188,12 +188,12 @@
|
||||
|
||||
<target name ="testData" depends="init">
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/data/rbbi/english.dict"
|
||||
todir="${build.dir}/com/ibm/icu/dev/data/rbbi"/>
|
||||
<javac includes="com/ibm/icu/dev/data/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
todir="${build.dir}/com/ibm/icu/dev/data/rbbi"/>
|
||||
<javac includes="com/ibm/icu/dev/data/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
@ -201,9 +201,9 @@
|
||||
<target name="richedit" depends="init">
|
||||
<javac includes="com/ibm/richtext/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
<copy todir="${build.dir}/com/ibm/richtext/textapps/resources" overwrite="yes" includeEmptyDirs="no">
|
||||
<fileset dir="${src.dir}/com/ibm/richtext/textapps/resources" includes="*.red"/>
|
||||
@ -224,7 +224,7 @@
|
||||
<jar jarfile="${richedit.jar.file}"
|
||||
compress="false"
|
||||
includes="com/ibm/richtext/**/*"
|
||||
excludes="com/ibm/richtext/test/**/*"
|
||||
excludes="com/ibm/richtext/test/**/*"
|
||||
basedir="${build.dir}"
|
||||
manifest="${richedit.manifest}"/>
|
||||
</target>
|
||||
@ -242,18 +242,18 @@
|
||||
sourcepath="${src.dir}"
|
||||
destdir="${richedit.doc.dir}"
|
||||
nodeprecatedlist="true"
|
||||
windowtitle="RichEdit Control"
|
||||
doctitle="RichEdit Control"
|
||||
encoding="iso-8859-1"
|
||||
docencoding="iso-8859-1"
|
||||
bottom="<font size=-1>Copyright (c) 1998-2002 IBM Corporation and others.</font>"
|
||||
/>
|
||||
windowtitle="RichEdit Control"
|
||||
doctitle="RichEdit Control"
|
||||
encoding="iso-8859-1"
|
||||
docencoding="iso-8859-1"
|
||||
bottom="<font size=-1>Copyright (c) 1998-2002 IBM Corporation and others.</font>"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<!-- richedit alphaworks distribution - jar and docs, but no source -->
|
||||
<target name="richeditZip" depends="richeditJar,richeditDocs">
|
||||
<!--Create a zip archive of the richedit jar and readme -->
|
||||
<copy file="license.html" todir="${richedit.dir}"/>
|
||||
<copy file="license.html" todir="${richedit.dir}"/>
|
||||
<zip zipfile="${richedit.zip.file}"
|
||||
basedir="${richedit.dir}"
|
||||
includes="doc/**/*,richedit.jar,license.html"/>
|
||||
@ -284,12 +284,12 @@
|
||||
</target>
|
||||
|
||||
<target name="check" depends="tests">
|
||||
<java classname="com.ibm.icu.dev.test.TestAll">
|
||||
<classpath>
|
||||
<java classname="com.ibm.icu.dev.test.TestAll">
|
||||
<classpath>
|
||||
<pathelement path="${java.class.path}/"/>
|
||||
<pathelement path="${build.dir}"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="_requires14" unless="version.1.4">
|
||||
@ -298,14 +298,14 @@
|
||||
|
||||
<target name="_checktags" depends="anthack1,anthack2,tools" if="version.1.4">
|
||||
<echo message="doc params: ${doc.params}"/>
|
||||
<javadoc sourcepath="${src.dir}"
|
||||
<javadoc sourcepath="${src.dir}"
|
||||
packagenames="com.ibm.icu.*"
|
||||
excludepackagenames="com.ibm.icu.dev.*,com.ibm.icu.impl.*"
|
||||
classpath="${build.dir}">
|
||||
<doclet name="com.ibm.icu.dev.tool.docs.CheckTags"
|
||||
path="${build.dir}">
|
||||
<param name="-brief"/>
|
||||
</doclet>
|
||||
</doclet>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
@ -315,7 +315,257 @@
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${doc.dir}"/>
|
||||
<delete file="${jar.file}"/>
|
||||
<delete dir="${richedit.dir}"/>
|
||||
<delete dir="${richedit.dir}"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to copy the required *.icu files
|
||||
-->
|
||||
<target name="copyICUData" depends="init">
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/unorm.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/uprops.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
<!-- For basic support names data is not needed
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/unames.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/pnames.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
-->
|
||||
</target>
|
||||
|
||||
<target name="copyICUPropsData" depends="init">
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/unorm.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/uprops.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
<!-- For basic support names data is not needed
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/unames.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/> -->
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/pnames.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
|
||||
</target>
|
||||
<target name="copyAllICUData" depends="init">
|
||||
<copy todir="${build.dir}/com/ibm/icu/impl/data">
|
||||
<fileset dir="${src.dir}/com/ibm/icu/impl/data"
|
||||
includes="*.icu"/>
|
||||
</copy>
|
||||
<!-- For basic support names data is not neede -->
|
||||
<delete file="${build.dir}/com/ibm/icu/impl/data/unames.icu"/>
|
||||
</target>
|
||||
|
||||
<target name="moduleJar" depends="init">
|
||||
<jar jarfile="${jar.file}"
|
||||
compress="false"
|
||||
includes="com/ibm/icu/util/**/*,com/ibm/icu/text/**/*,com/ibm/icu/math/**/*,com/ibm/icu/impl/**/*,com/ibm/icu/lang/**/*"
|
||||
basedir="${build.dir}"
|
||||
manifest="${icu4j.manifest}"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only Normalization API and Normalization tests
|
||||
-->
|
||||
<target name="normalizer" depends="init,copyICUData">
|
||||
<javac includes="com/ibm/icu/text/Normalizer.java,com/ibm/icu/text/CanonicalIterator.java,com/ibm/icu/text/UTF16.java,com/ibm/icu/text/UCharacterIterator.java,com/ibm/icu/text/UForwardCharacterIterator.java,com/ibm/icu/text/Replaceable.java,com/ibm/icu/text/ReplaceableString.java,com/ibm/icu/text/UnicodeFilter.java,com/ibm/icu/text/UnicodeSetIterator.java,com/ibm/icu/lang/**/*"
|
||||
excludes="**/CVS/**/*,com/ibm/icu/lang/UScriptRun.java, com/ibm/icu/impl/ICUListResourceBundle.java, com/ibm/icu/impl/UtilityExtensions.java,com/ibm/icu/impl/TrieBuilder.java,com/ibm/icu/impl/IntTrieBuilder.java,com/ibm/icu/impl/BOCU.java,com/ibm/icu/impl/UnicodeCharacterIterator.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
<target name="normalizerTests" depends="normalizer">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/normalizer/**/*.java"
|
||||
excludes="**/CVS/**/*,com/ibm/icu/dev/test/normalizer/TestDeprecatedNormalizerAPI.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only Collation API and Collation tests
|
||||
-->
|
||||
<target name="collator" depends="init,_resources,copyAllICUData">
|
||||
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/thai_dict"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
|
||||
<javac includes="com/ibm/icu/text/*Collator*.java,com/ibm/icu/text/*Collation*.java,com/ibm/icu/text/*BreakIterator*.java,com/ibm/icu/text/Normalizer.java,com/ibm/icu/text/UTF16.java,com/ibm/icu/text/Replaceable.java,com/ibm/icu/text/ReplaceableString.java,com/ibm/icu/text/UnicodeFilter.java,com/ibm/icu/text/UnicodeSetIterator.java, com/ibm/icu/impl/data/*Break*.java"
|
||||
excludes="**/CVS/**/*, com/ibm/icu/lang/UScriptRun.java,com/ibm/icu/impl/UtilityExtensions.java,com/ibm/icu/impl/UnicodeCharacterIterator.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
<target name="collatorTests" depends="collator">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/collator/**/*.java,com/ibm/icu/dev/test/search/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only Character properties API and tests
|
||||
-->
|
||||
<target name="propertiesBasic" depends="init, copyICUPropsData">
|
||||
|
||||
<javac includes="com/ibm/icu/lang/**/*, com/ibm/icu/text/*BreakIterator*.java,com/ibm/icu/text/*BreakDictionary*.java,com/ibm/icu/impl/data/*Break*.java,com/ibm/icu/text/UnicodeSetIterator.java,com/ibm/icu/impl/ICUListResourceBundle.java"
|
||||
excludes="**/CVS/**/*,com/ibm/icu/impl/UtilityExtensions.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
<target name="propertiesFull" depends="init,_resources, copyICUPropsData">
|
||||
|
||||
<javac includes="com/ibm/icu/lang/**/*, com/ibm/icu/text/*BreakIterator*.java,com/ibm/icu/text/*BreakDictionary*.java,com/ibm/icu/impl/data/*Break*.java,com/ibm/icu/text/UnicodeSetIterator.java,com/ibm/icu/impl/ICUListResourceBundle.java"
|
||||
excludes="**/CVS/**/*,com/ibm/icu/impl/UtilityExtensions.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/unames.icu"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
<!-- UScript does not require Collation data, BreakIterator data -->
|
||||
<delete>
|
||||
<fileset DIR="${build.dir}/com/ibm/icu/impl/data/" includes="LocaleElements_*__*.class,LocaleElements_*_*_STROKE.class,*.col,*.brk,*.utf8"/>
|
||||
</delete>
|
||||
</target>
|
||||
<target name="propertiesTests" depends="propertiesBasic">
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/data/unicode/SpecialCasing.txt"
|
||||
todir="${build.dir}/com/ibm/icu/dev/data/unicode/"/>
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/lang/**/*.java"
|
||||
excludes="**/CVS/**/*,com/ibm/icu/dev/test/lang/TestUScriptRun.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
<!--
|
||||
Targets to build only Compression API API and tests
|
||||
-->
|
||||
<target name="compression" depends="init">
|
||||
|
||||
<javac includes="com/ibm/icu/text/SCSU.java, com/ibm/icu/text/UnicodeCompressor.java, com/ibm/icu/text/UnicodeDecompressor.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
<target name="compressionTests" depends="compression">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/compression/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only Calendar API and Calendar tests
|
||||
-->
|
||||
<target name="calendar" depends="init,_resources,copyICUData">
|
||||
|
||||
<javac includes="com/ibm/icu/util/*Calendar*.java,com/ibm/icu/lang/UCharacter.java,com/ibm/icu/impl/ICUListResourceBundle.java,com/ibm/icu/text/UnicodeSetIterator.java,com/ibm/icu/impl/data/*Calendar*.java,com/ibm/icu/impl/data/*Holiday*.java"
|
||||
excludes="**/CVS/**/*, com/ibm/icu/lang/UScriptRun.java,com/ibm/icu/impl/UtilityExtensions.java,com/ibm/icu/impl/BOCU.java,com/ibm/icu/impl/TrieBuilder.java,com/ibm/icu/impl/IntTrieBuilder.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
<!-- Calendar does not require Collation data, BreakIterator data -->
|
||||
<delete>
|
||||
<fileset dir="${build.dir}/com/ibm/icu/impl/data/" includes="LocaleElements_*__*.class,LocaleElements_*_*_STROKE.class,*.col,*.brk,*.utf8"/>
|
||||
</delete>
|
||||
</target>
|
||||
<target name="calendarTests" depends="calendar">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/calendar/**/*"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only Transliterator API and tests
|
||||
-->
|
||||
<target name="transliterator" depends="init,_resources,propertiesBasic">
|
||||
<javac includes="com/ibm/icu/text/*Transliterator*.java,com/ibm/icu/text/UnicodeSetIterator.java,com/ibm/icu/text/RuleBasedBreakIterator.java,com/ibm/icu/text/DictionaryBasedBreakIterator.java,com/ibm/icu/impl/LocaleUtility.java,com/ibm/icu/impl/data/BreakIterator*.java,com/ibm/icu/impl/*Property*.java,com/ibm/icu/impl/*Iterator*.java,com/ibm/icu/impl/ICUListResourceBundle.java,com/ibm/icu/impl/data/ResourceReader.java,com/ibm/icu/impl/UtilityExtensions.java"
|
||||
excludes="**/CVS/**/*, com/ibm/icu/lang/UScriptRun.java,com/ibm/icu/impl/BOCU.java,com/ibm/icu/impl/TrieBuilder.java,com/ibm/icu/impl/IntTrieBuilder.java,com/ibm/icu/text/UnicodeFilterLogic*.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
<copy todir="${build.dir}/com/ibm/icu/impl/data">
|
||||
<fileset dir="${src.dir}/com/ibm/icu/impl/data" includes="Transliterator_*.txt"/>
|
||||
<fileset dir="${src.dir}/com/ibm/icu/impl/data/" includes="unames.icu,unorm.icu" />
|
||||
</copy>
|
||||
<!-- Calendar does not require Collation data, BreakIterator data -->
|
||||
<delete>
|
||||
<fileset dir="${build.dir}/com/ibm/icu/impl/data/" includes="*.col,*.brk,*.utf8"/>
|
||||
</delete>
|
||||
</target>
|
||||
<target name="transliteratorTests" depends="transliterator">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/translit/**/*"
|
||||
excludes="**/CVS/**/*,com/ibm/icu/dev/test/translit/UnicodeFilterLogic*.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only Format API
|
||||
-->
|
||||
<target name="format" depends="init,_resources,copyAllICUData">
|
||||
|
||||
<javac includes="com/ibm/icu/text/*Format*.java,com/ibm/icu/lang/UCharacter.java,com/ibm/icu/text/*Collator*.java,com/ibm/icu/text/UnicodeSetIterator.java,com/ibm/icu/impl/ICUListResourceBundle.java,com/ibm/icu/impl/data/CalendarData*.java"
|
||||
excludes="**/CVS/**/*, com/ibm/icu/lang/UScriptRun.java,com/ibm/icu/impl/UtilityExtensions.java,com/ibm/icu/impl/BOCU.java,com/ibm/icu/impl/TrieBuilder.java,com/ibm/icu/impl/IntTrieBuilder.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
<target name="formatTests" depends="format">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/format/**/*"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Targets to build only BreakIterator API
|
||||
-->
|
||||
<target name="breakIterator" depends="init,_resources,copyICUPropsData">
|
||||
|
||||
<copy file="${src.dir}/com/ibm/icu/impl/data/thai_dict"
|
||||
todir="${build.dir}/com/ibm/icu/impl/data/"/>
|
||||
|
||||
<javac includes="com/ibm/icu/text/*BreakIterator*.java,com/ibm/icu/impl/data/*Break*.java,com/ibm/icu/lang/**/*,com/ibm/icu/impl/UCharacterName.java,com/ibm/icu/impl/ICUListResourceBundle.java,com/ibm/icu/text/UnicodeSetIterator.java"
|
||||
excludes="**/CVS/**/*, com/ibm/icu/lang/UScriptRun.java,com/ibm/icu/impl/UtilityExtensions.java,com/ibm/icu/impl/BOCU.java,com/ibm/icu/impl/TrieBuilder.java,com/ibm/icu/impl/IntTrieBuilder.java"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
<!-- BreakIterator does not require collation data so delete it -->
|
||||
<delete>
|
||||
<fileset dir="${build.dir}/com/ibm/icu/impl/data/" includes="*.col,*.utf8"/>
|
||||
</delete>
|
||||
</target>
|
||||
<target name="breakIteratorTests" depends="breakIterator">
|
||||
<javac includes="com/ibm/icu/dev/test/TestFmwk.java,com/ibm/icu/dev/test/TestLog.java,com/ibm/icu/dev/test/TestUtil.java,com/ibm/icu/dev/test/UTF16Util.java,com/ibm/icu/dev/test/rbbi/**/*"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
debug="on" deprecation="off"/>
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/data/th18057.txt"
|
||||
todir="${build.dir}/com/ibm/icu/dev/data/"/>
|
||||
</target>
|
||||
</project>
|
||||
|
@ -4,9 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestAll.java,v $
|
||||
* $Date: 2002/12/18 19:58:25 $
|
||||
* $Revision: 1.44 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:32 $
|
||||
* $Revision: 1.45 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -18,7 +18,7 @@ import java.util.TimeZone;
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@ -29,7 +29,7 @@ public class TestAll extends TestFmwk {
|
||||
public void TestBigNumberFormat() throws Exception{
|
||||
run(new com.ibm.icu.dev.test.format.BigNumberFormatTest());
|
||||
}
|
||||
|
||||
|
||||
public void TestCompression() throws Exception{
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.compression.DecompressionTest(),
|
||||
@ -72,7 +72,7 @@ public class TestAll extends TestFmwk {
|
||||
run(
|
||||
new com.ibm.icu.dev.test.search.SearchTest());
|
||||
}
|
||||
|
||||
|
||||
public void TestCollator() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.collator.CollationTest(),
|
||||
@ -96,7 +96,7 @@ public class TestAll extends TestFmwk {
|
||||
new com.ibm.icu.dev.test.collator.CollationMiscTest()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestArabicShaping() throws Exception {
|
||||
run(new com.ibm.icu.dev.test.shaping.ArabicShapingRegTest());
|
||||
}
|
||||
@ -134,34 +134,35 @@ public class TestAll extends TestFmwk {
|
||||
new com.ibm.icu.dev.test.lang.UTF16Test()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestTrie() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.util.TrieTest()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestUScript() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.lang.TestUScript(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestNormalizer() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.normalizer.BasicTest(),
|
||||
new com.ibm.icu.dev.test.normalizer.ConformanceTest(),
|
||||
new com.ibm.icu.dev.test.normalizer.ExhaustiveTest(),
|
||||
new com.ibm.icu.dev.test.normalizer.TestDeprecatedNormalizerAPI(),
|
||||
new com.ibm.icu.dev.test.normalizer.TestCanonicalIterator(),
|
||||
new com.ibm.icu.dev.test.normalizer.NormalizationMonkeyTest(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestUScriptRun() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.lang.TestUScriptRun(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestNumberFormat() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.format.IntlTestNumberFormat(),
|
||||
@ -176,7 +177,7 @@ public class TestAll extends TestFmwk {
|
||||
new com.ibm.icu.dev.test.format.IntlTestDecimalFormatSymbolsC()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestDateFormat() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.format.DateFormatMiscTests(),
|
||||
@ -193,28 +194,28 @@ public class TestAll extends TestFmwk {
|
||||
}
|
||||
|
||||
public void TestService() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.util.ICUServiceTest(),
|
||||
new com.ibm.icu.dev.test.util.ICUServiceThreadTest()
|
||||
});
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.util.ICUServiceTest(),
|
||||
new com.ibm.icu.dev.test.util.ICUServiceThreadTest()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestVersionInfo() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.util.VersionInfoTest()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestIterator() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.iterator.TestUCharacterIterator(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void TestUtil() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.util.ICUListResourceBundleTest(),
|
||||
new com.ibm.icu.dev.test.util.CompactArrayTest(),
|
||||
new com.ibm.icu.dev.test.util.CompactArrayTest(),
|
||||
new com.ibm.icu.dev.test.util.StringTokenizerTest(),
|
||||
new com.ibm.icu.dev.test.util.CurrencyTest(),
|
||||
});
|
||||
|
@ -4,9 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java,v $
|
||||
* $Date: 2002/11/06 19:07:02 $
|
||||
* $Revision: 1.33 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java,v $
|
||||
* $Date: 2003/01/28 18:55:32 $
|
||||
* $Revision: 1.34 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -25,10 +25,6 @@ import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
|
||||
/**
|
||||
* TestFmwk is a base class for tests that can be run conveniently from
|
||||
* the command line as well as under the Java test harness.
|
||||
@ -71,7 +67,7 @@ public class TestFmwk implements TestLog {
|
||||
result = new HashMap();
|
||||
Method[] methods = getClass().getDeclaredMethods();
|
||||
for( int i=0; i<methods.length; i++ ) {
|
||||
if( methods[i].getName().startsWith("Test")
|
||||
if( methods[i].getName().startsWith("Test")
|
||||
|| methods[i].getName().startsWith("test")) {
|
||||
result.put(methods[i].getName(), methods[i] );
|
||||
}
|
||||
@ -97,7 +93,7 @@ public class TestFmwk implements TestLog {
|
||||
private void _run() throws Exception {
|
||||
_run(getTestsToRun(null));
|
||||
}
|
||||
|
||||
|
||||
private void _run(Map testsToRun) throws Exception {
|
||||
writeTestName(getClass().getName());
|
||||
params.indentLevel++;
|
||||
@ -108,48 +104,48 @@ public class TestFmwk implements TestLog {
|
||||
Iterator iter = getTestEntryIterator(testsToRun);
|
||||
|
||||
// Run the list of tests given in the test arguments
|
||||
final Object[] NO_ARGS = new Object[0];
|
||||
final Object[] NO_ARGS = new Object[0];
|
||||
while (iter.hasNext()) {
|
||||
int oldCount = params.errorCount;
|
||||
int oldInvalidCount = params.invalidCount;
|
||||
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
String testName = (String)entry.getKey();
|
||||
String testName = (String)entry.getKey();
|
||||
Method testMethod = (Method)entry.getValue();
|
||||
|
||||
writeTestName(testName);
|
||||
|
||||
if (validateMethod(testName)) {
|
||||
try {
|
||||
testMethod.invoke(this, NO_ARGS);
|
||||
} catch( IllegalAccessException e ) {
|
||||
errln("Can't access test method " + testName);
|
||||
} catch( InvocationTargetException e ) {
|
||||
errln("Uncaught exception \"" + e
|
||||
+"\" thrown in test method " + testMethod.getName()
|
||||
if (validateMethod(testName)) {
|
||||
try {
|
||||
testMethod.invoke(this, NO_ARGS);
|
||||
} catch( IllegalAccessException e ) {
|
||||
errln("Can't access test method " + testName);
|
||||
} catch( InvocationTargetException e ) {
|
||||
errln("Uncaught exception \"" + e
|
||||
+"\" thrown in test method " + testMethod.getName()
|
||||
+" accessed under name " + testName);
|
||||
e.getTargetException().printStackTrace(this.params.log);
|
||||
}
|
||||
} else {
|
||||
params.invalidCount++;
|
||||
}
|
||||
e.getTargetException().printStackTrace(this.params.log);
|
||||
}
|
||||
} else {
|
||||
params.invalidCount++;
|
||||
}
|
||||
writeTestResult(params.errorCount - oldCount, params.invalidCount - oldInvalidCount);
|
||||
}
|
||||
} else {
|
||||
params.invalidCount++;
|
||||
}
|
||||
params.indentLevel--;
|
||||
|
||||
|
||||
writeTestResult(params.errorCount - oldClassCount, params.invalidCount - oldClassInvalidCount);
|
||||
}
|
||||
|
||||
|
||||
public void run(String[] args) throws Exception {
|
||||
if (params == null) params = new TestParams();
|
||||
|
||||
// Parse the test arguments. They can be either the flag
|
||||
// "-verbose" or names of test methods. Create a list of
|
||||
// tests to be run.
|
||||
boolean usageError = false;
|
||||
boolean usageError = false;
|
||||
Set testNames = null;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].equals("-verbose") || args[i].equals("-v")) {
|
||||
@ -159,8 +155,8 @@ public class TestFmwk implements TestLog {
|
||||
params.prompt = true;
|
||||
} else if (args[i].equals("-nothrow") || args[i].equals("-n")) {
|
||||
params.nothrow = true;
|
||||
} else if (args[i].equals("-describe")) {
|
||||
params.describe = true;
|
||||
} else if (args[i].equals("-describe")) {
|
||||
params.describe = true;
|
||||
} else if (args[i].startsWith("-e")) {
|
||||
// see above
|
||||
params.inclusion = (args[i].length() == 2) ? 5 : Integer.parseInt(args[i].substring(2));
|
||||
@ -183,9 +179,9 @@ public class TestFmwk implements TestLog {
|
||||
}
|
||||
if (usageError ||
|
||||
(testNames != null && testsToRun.size() != testNames.size())) {
|
||||
usage();
|
||||
return;
|
||||
}
|
||||
usage();
|
||||
return;
|
||||
}
|
||||
|
||||
_run(testsToRun);
|
||||
|
||||
@ -210,15 +206,15 @@ public class TestFmwk implements TestLog {
|
||||
}
|
||||
|
||||
protected String getDescription() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean validateMethod(String name) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected String getMethodDescription(String name) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void run(TestFmwk childTest) throws Exception {
|
||||
@ -257,13 +253,27 @@ public class TestFmwk implements TestLog {
|
||||
* Adds given string to the log if we are in verbose mode.
|
||||
*/
|
||||
public void log( String message ) {
|
||||
log(message, true, false);
|
||||
log(message, true, false, false);
|
||||
}
|
||||
|
||||
public void logln( String message ) {
|
||||
logln(message, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given string to the log.
|
||||
*/
|
||||
public void info( String message ) {
|
||||
message = "INFO: " + message;
|
||||
log(message,false,false,true);
|
||||
}
|
||||
|
||||
public void infoln( String message ) {
|
||||
message = " INFO: " + message;
|
||||
log(message + System.getProperty("line.separator"), false, false,true);
|
||||
params.suppressIndent = false; // time to indent again
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a given string to the log.
|
||||
* @param message text to add
|
||||
@ -273,26 +283,33 @@ public class TestFmwk implements TestLog {
|
||||
* then increment the failure count; if pass is true, then this param
|
||||
* is ignored
|
||||
*/
|
||||
public void log( String message, boolean pass, boolean incrementCount ) {
|
||||
if (!pass && incrementCount) {
|
||||
params.errorCount++;
|
||||
}
|
||||
public void log( String message, boolean pass, boolean incrementCount,boolean isInfo ) {
|
||||
if(!isInfo){
|
||||
if (!pass && incrementCount) {
|
||||
if(params==null) {params = new TestParams();}
|
||||
params.errorCount++;
|
||||
}
|
||||
|
||||
if (!pass || params.verbose) {
|
||||
if (!pass || params.verbose) {
|
||||
if (!params.suppressIndent) indent(params.indentLevel + 1);
|
||||
params.log.print( message );
|
||||
params.log.flush();
|
||||
}
|
||||
|
||||
if (!pass && !params.nothrow) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}else{
|
||||
if (!params.suppressIndent) indent(params.indentLevel + 1);
|
||||
params.log.print( message );
|
||||
params.log.flush();
|
||||
}
|
||||
|
||||
if (!pass && !params.nothrow) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
params.suppressIndent = true; // don't indent on successive calls to log()
|
||||
|
||||
}
|
||||
|
||||
public void logln( String message, boolean pass, boolean incrementCount ) {
|
||||
log(message + System.getProperty("line.separator"), pass, incrementCount);
|
||||
log(message + System.getProperty("line.separator"), pass, incrementCount,false);
|
||||
params.suppressIndent = false; // time to indent again
|
||||
}
|
||||
|
||||
@ -300,7 +317,7 @@ public class TestFmwk implements TestLog {
|
||||
* Convenience overloads
|
||||
*/
|
||||
public void log( String message, boolean pass ) {
|
||||
log(message, pass, true);
|
||||
log(message, pass, true, false);
|
||||
}
|
||||
|
||||
public void logln( String message, boolean pass ) {
|
||||
@ -311,7 +328,7 @@ public class TestFmwk implements TestLog {
|
||||
* Report an error
|
||||
*/
|
||||
public void err( String message ) {
|
||||
log(message, false, true);
|
||||
log(message, false, true, false);
|
||||
}
|
||||
|
||||
public void errln( String message ) {
|
||||
@ -370,29 +387,29 @@ public class TestFmwk implements TestLog {
|
||||
System.out.println(" -e<n> Set exhaustiveness from 0..10. Default is 0, fewest tests.\n To run all tests, specify -e10. Giving -e with no <n> is\n the same as -e5.");
|
||||
System.out.println(" -filter:<str> ?");
|
||||
|
||||
boolean valid = params.describe && validate();
|
||||
if (valid) {
|
||||
String testDescription = getDescription();
|
||||
if (testDescription != null) {
|
||||
System.out.println("-- " + testDescription);
|
||||
}
|
||||
}
|
||||
boolean valid = params.describe && validate();
|
||||
if (valid) {
|
||||
String testDescription = getDescription();
|
||||
if (testDescription != null) {
|
||||
System.out.println("-- " + testDescription);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator testEntries = getTestEntryIterator(getAvailableTests());
|
||||
|
||||
System.out.println("Test names:");
|
||||
while(testEntries.hasNext() ) {
|
||||
Map.Entry e = (Map.Entry)testEntries.next();
|
||||
String methodName = (String)e.getKey();
|
||||
String methodName = (String)e.getKey();
|
||||
|
||||
System.out.print("\t" + methodName );
|
||||
if (valid) {
|
||||
String methodDescription = getMethodDescription(methodName);
|
||||
if (methodDescription != null) {
|
||||
System.out.print(" -- " + methodDescription);
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
if (valid) {
|
||||
String methodDescription = getMethodDescription(methodName);
|
||||
if (methodDescription != null) {
|
||||
System.out.print(" -- " + methodDescription);
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,7 +421,7 @@ public class TestFmwk implements TestLog {
|
||||
}
|
||||
return result + foo;
|
||||
}
|
||||
|
||||
|
||||
public static String hex(int ch) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
String foo = Integer.toString(ch,16).toUpperCase();
|
||||
@ -430,11 +447,10 @@ public class TestFmwk implements TestLog {
|
||||
private static class ASCIIWriter extends PrintWriter {
|
||||
private Writer w;
|
||||
private StringBuffer buffer = new StringBuffer();
|
||||
|
||||
|
||||
// Characters that we think are printable but that escapeUnprintable
|
||||
// doesn't
|
||||
private static final UnicodeSet S =
|
||||
new UnicodeSet("[\\u0009\\u000A\\u000D]");
|
||||
private static final String S ="\u0009"+(char)0x000A+(char)0x000D;
|
||||
|
||||
public ASCIIWriter(Writer w, boolean autoFlush) {
|
||||
super(w, autoFlush);
|
||||
@ -447,22 +463,22 @@ public class TestFmwk implements TestLog {
|
||||
public void write(int c) {
|
||||
synchronized(lock) {
|
||||
buffer.setLength(0);
|
||||
if (!S.contains(c) && Utility.escapeUnprintable(buffer, c)) {
|
||||
if (S.indexOf(c)<0 && TestUtil.escapeUnprintable(buffer, c)) {
|
||||
super.write(buffer.toString());
|
||||
} else {
|
||||
super.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(char[] buf, int off, int len) {
|
||||
synchronized (lock) {
|
||||
buffer.setLength(0);
|
||||
int limit = off + len;
|
||||
while (off < limit) {
|
||||
int c = UTF16.charAt(buf, 0, buf.length, off);
|
||||
off += UTF16.getCharCount(c);
|
||||
if (!S.contains(c) && Utility.escapeUnprintable(buffer, c)) {
|
||||
int c = UTF16Util.charAt(buf, 0, buf.length, off);
|
||||
off += UTF16Util.getCharCount(c);
|
||||
if (S.indexOf(c)<0 && TestUtil.escapeUnprintable(buffer, c)) {
|
||||
super.write(buffer.toString());
|
||||
buffer.setLength(0);
|
||||
} else {
|
||||
@ -471,7 +487,7 @@ public class TestFmwk implements TestLog {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(String s, int off, int len) {
|
||||
write(s.substring(off, off + len).toCharArray(), 0, len);
|
||||
}
|
||||
@ -481,7 +497,7 @@ public class TestFmwk implements TestLog {
|
||||
public boolean prompt = false;
|
||||
public boolean nothrow = false;
|
||||
public boolean verbose = false;
|
||||
public boolean describe = false;
|
||||
public boolean describe = false;
|
||||
public int inclusion = 0;
|
||||
public String filter = null;
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestLog.java,v $
|
||||
* $Date: 2002/08/13 22:02:16 $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2003/01/28 18:55:32 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -27,4 +27,11 @@ public interface TestLog {
|
||||
void err(String message);
|
||||
|
||||
void errln(String message);
|
||||
|
||||
/**
|
||||
* Add infomational line to log
|
||||
*/
|
||||
void info(String message);
|
||||
|
||||
void infoln(String message);
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestUtil.java,v $
|
||||
* $Date: 2002/08/13 22:02:16 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2003/01/28 18:55:32 $
|
||||
* $Revision: 1.3 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -18,68 +18,124 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestUtil {
|
||||
/**
|
||||
* Standard path to the test data.
|
||||
*/
|
||||
public static final String DATA_PATH = "/src/com/ibm/icu/dev/data";
|
||||
/**
|
||||
* Standard path to the test data.
|
||||
*/
|
||||
public static final String DATA_PATH = "/src/com/ibm/icu/dev/data";
|
||||
|
||||
/**
|
||||
* Property for user-defined data path.
|
||||
*/
|
||||
public static final String DATA_PATH_PROPERTY = "ICUDataPath";
|
||||
/**
|
||||
* Property for user-defined data path.
|
||||
*/
|
||||
public static final String DATA_PATH_PROPERTY = "ICUDataPath";
|
||||
|
||||
/**
|
||||
* Get path to test data.<p>
|
||||
*
|
||||
* path is provided relative to the src path, however the user could
|
||||
* set a system property to change the directory path.<br>
|
||||
*/
|
||||
|
||||
public static final File getDataPathRoot() {
|
||||
String s = System.getProperty(DATA_PATH_PROPERTY);
|
||||
if (s == null) {
|
||||
// assume user.dir is directly above src directory
|
||||
s = System.getProperty("user.dir");
|
||||
s = s + DATA_PATH;
|
||||
}
|
||||
|
||||
File f = new File(s);
|
||||
if (!f.exists()) {
|
||||
throw new InternalError("cannot find ICU data root '" + f.getAbsolutePath() + "', try definining " + DATA_PATH_PROPERTY);
|
||||
}
|
||||
/**
|
||||
* Property for modular build.
|
||||
*/
|
||||
public static final String DATA_MODULAR_BUILD_PROPERTY = "ICUModularBuild";
|
||||
|
||||
return f;
|
||||
}
|
||||
/**
|
||||
* Get path to test data.<p>
|
||||
*
|
||||
* path is provided relative to the src path, however the user could
|
||||
* set a system property to change the directory path.<br>
|
||||
*/
|
||||
public static final File getDataPathRoot() {
|
||||
String s = System.getProperty(DATA_PATH_PROPERTY);
|
||||
if (s == null) {
|
||||
// assume user.dir is directly above src directory
|
||||
s = System.getProperty("user.dir");
|
||||
s = s + DATA_PATH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data file at path 'name' rooted at the data path.
|
||||
* For example, <pre>getDataFile("unicode/UnicodeData.txt");</pre>
|
||||
*/
|
||||
public static final File getDataFile(String name) {
|
||||
File f = new File(getDataPathRoot(), name);
|
||||
if (!f.exists()) {
|
||||
throw new InternalError("cannot find ICU data file '" + f.getAbsolutePath() + "'");
|
||||
}
|
||||
File f = new File(s);
|
||||
if (!f.exists()) {
|
||||
throw new InternalError("cannot find ICU data root '" + f.getAbsolutePath() + "', try definining " + DATA_PATH_PROPERTY);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a buffered reader on the data file at path 'name' rooted at the data path
|
||||
* with initial buffer size 'bufSize'.
|
||||
*/
|
||||
public static final BufferedReader getDataReader(String name, int bufSize) throws IOException {
|
||||
File f = getDataFile(name);
|
||||
FileReader fr = new FileReader(f);
|
||||
BufferedReader br = new BufferedReader(fr, bufSize);
|
||||
return br;
|
||||
}
|
||||
/**
|
||||
* Return the data file at path 'name' rooted at the data path.
|
||||
* For example, <pre>getDataFile("unicode/UnicodeData.txt");</pre>
|
||||
*/
|
||||
public static final File getDataFile(String name) {
|
||||
File f = new File(getDataPathRoot(), name);
|
||||
if (!f.exists()) {
|
||||
throw new InternalError("cannot find ICU data file '" + f.getAbsolutePath() + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a buffered reader on the data file at path 'name' rooted at the data path.
|
||||
*/
|
||||
public static final BufferedReader getDataReader(String name) throws IOException {
|
||||
return getDataReader(name, 1024);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a buffered reader on the data file at path 'name' rooted at the data path
|
||||
* with initial buffer size 'bufSize'.
|
||||
*/
|
||||
public static final BufferedReader getDataReader(String name, int bufSize) throws IOException {
|
||||
File f = getDataFile(name);
|
||||
FileReader fr = new FileReader(f);
|
||||
BufferedReader br = new BufferedReader(fr, bufSize);
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a buffered reader on the data file at path 'name' rooted at the data path.
|
||||
*/
|
||||
public static final BufferedReader getDataReader(String name) throws IOException {
|
||||
return getDataReader(name, 1024);
|
||||
}
|
||||
static final char DIGITS[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z'
|
||||
};
|
||||
/**
|
||||
* Return true if the character is NOT printable ASCII. The tab,
|
||||
* newline and linefeed characters are considered unprintable.
|
||||
*/
|
||||
public static boolean isUnprintable(int c) {
|
||||
return !(c >= 0x20 && c <= 0x7E);
|
||||
}
|
||||
/**
|
||||
* Escape unprintable characters using <backslash>uxxxx notation
|
||||
* for U+0000 to U+FFFF and <backslash>Uxxxxxxxx for U+10000 and
|
||||
* above. If the character is printable ASCII, then do nothing
|
||||
* and return FALSE. Otherwise, append the escaped notation and
|
||||
* return TRUE.
|
||||
*/
|
||||
public static boolean escapeUnprintable(StringBuffer result, int c) {
|
||||
if (isUnprintable(c)) {
|
||||
result.append('\\');
|
||||
if ((c & ~0xFFFF) != 0) {
|
||||
result.append('U');
|
||||
result.append(DIGITS[0xF&(c>>28)]);
|
||||
result.append(DIGITS[0xF&(c>>24)]);
|
||||
result.append(DIGITS[0xF&(c>>20)]);
|
||||
result.append(DIGITS[0xF&(c>>16)]);
|
||||
} else {
|
||||
result.append('u');
|
||||
}
|
||||
result.append(DIGITS[0xF&(c>>12)]);
|
||||
result.append(DIGITS[0xF&(c>>8)]);
|
||||
result.append(DIGITS[0xF&(c>>4)]);
|
||||
result.append(DIGITS[0xF&c]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if ICU is built modularly without locale data
|
||||
*/
|
||||
public static boolean isModularBuild(){
|
||||
String s = System.getProperty(DATA_MODULAR_BUILD_PROPERTY);
|
||||
if (s == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
39
icu4j/src/com/ibm/icu/dev/test/calendar/TestAll.java
Normal file
39
icu4j/src/com/ibm/icu/dev/test/calendar/TestAll.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/calendar/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:32 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.calendar;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
public void TestCalendar() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.calendar.AstroTest(),
|
||||
new com.ibm.icu.dev.test.calendar.CalendarRegression(),
|
||||
new com.ibm.icu.dev.test.calendar.CompatibilityTest(),
|
||||
new com.ibm.icu.dev.test.calendar.HebrewTest(),
|
||||
new com.ibm.icu.dev.test.calendar.IBMCalendarTest(),
|
||||
new com.ibm.icu.dev.test.calendar.IslamicTest(),
|
||||
new com.ibm.icu.dev.test.calendar.JapaneseTest(),
|
||||
new com.ibm.icu.dev.test.calendar.ChineseTest(),
|
||||
new com.ibm.icu.dev.test.calendar.HolidayTest()
|
||||
});
|
||||
}
|
||||
}
|
@ -5,14 +5,15 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/collator/CollationTest.java,v $
|
||||
* $Date: 2002/10/08 21:52:23 $
|
||||
* $Revision: 1.7 $
|
||||
* $Date: 2003/01/28 18:55:33 $
|
||||
* $Revision: 1.8 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
import com.ibm.icu.dev.test.ModuleTest;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
import com.ibm.icu.text.RuleBasedCollator;
|
||||
import com.ibm.icu.text.Collator;
|
||||
import com.ibm.icu.text.CollationKey;
|
||||
@ -23,12 +24,13 @@ import com.ibm.icu.impl.LocaleUtility;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
public class CollationTest extends ModuleTest
|
||||
public class CollationTest extends ModuleTest
|
||||
{
|
||||
// public methods --------------------------------------------------------
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
new CollationTest().run(args);
|
||||
/* CollationTest test = new CollationTest();
|
||||
@ -46,29 +48,35 @@ public class CollationTest extends ModuleTest
|
||||
processTest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private data members --------------------------------------------------
|
||||
|
||||
|
||||
private String m_sequence_;
|
||||
private int m_sequenceIndex_;
|
||||
private String m_source_;
|
||||
private StringBuffer m_target_ = new StringBuffer();
|
||||
private int m_nextRelation_;
|
||||
private int m_relation_;
|
||||
|
||||
|
||||
// private methods -------------------------------------------------------
|
||||
|
||||
|
||||
private void processTest() {
|
||||
RuleBasedCollator col = null;
|
||||
// ok i have to be careful here since it seems like we can have
|
||||
// multiple locales for each test
|
||||
// multiple locales for each test
|
||||
String locale = settings.getString("TestLocale");
|
||||
if (locale != null) {
|
||||
// this is a case where we have locale
|
||||
// this is a case where we have locale
|
||||
try {
|
||||
Locale l = LocaleUtility.getLocaleFromName(locale);
|
||||
col = (RuleBasedCollator)Collator.getInstance(l);
|
||||
} catch (Exception e) {
|
||||
col = (RuleBasedCollator)Collator.getInstance(l);
|
||||
}catch (MissingResourceException e){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not load the locale data");
|
||||
}else{
|
||||
throw e;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
errln("Error creating collator for locale " + locale);
|
||||
}
|
||||
logln("Testing collator for locale %s\n" + locale);
|
||||
@ -76,37 +84,44 @@ public class CollationTest extends ModuleTest
|
||||
}
|
||||
String rules = settings.getString("Rules");
|
||||
// ok i have to be careful here since it seems like we can have
|
||||
// multiple rules for each test
|
||||
// multiple rules for each test
|
||||
if (rules != null) {
|
||||
// here we deal with rules
|
||||
try {
|
||||
col = new RuleBasedCollator(rules);
|
||||
}catch (MissingResourceException e){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not load the locale data");
|
||||
}else{
|
||||
throw e;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errln("Error creating collator for rules " + rules);
|
||||
}
|
||||
processCollatorTests(col);
|
||||
}
|
||||
}
|
||||
|
||||
private void processCollatorTests(RuleBasedCollator col)
|
||||
|
||||
private void processCollatorTests(RuleBasedCollator col)
|
||||
{
|
||||
|
||||
|
||||
// ok i have to be careful here since it seems like we can have
|
||||
// multiple rules for each test
|
||||
// multiple rules for each test
|
||||
String arguments = settings.getString("Arguments");
|
||||
if (arguments != null) {
|
||||
processArguments(col, arguments);
|
||||
}
|
||||
processReadyCollator(col);
|
||||
processReadyCollator(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the options string and sets appropriate attributes in collator
|
||||
|
||||
/**
|
||||
* Reads the options string and sets appropriate attributes in collator
|
||||
*/
|
||||
private void processArguments(RuleBasedCollator col, String argument) {
|
||||
int i = 0;
|
||||
while (i < argument.length()) {
|
||||
if (!UCharacter.isWhitespace(argument.charAt(i))) {
|
||||
boolean printInfo = false;
|
||||
while (i < argument.length()) {
|
||||
if (!UCharacter.isWhitespace(argument.charAt(i))) {
|
||||
// eat whitespace
|
||||
break;
|
||||
}
|
||||
@ -116,12 +131,15 @@ public class CollationTest extends ModuleTest
|
||||
// skip opening '['
|
||||
if (argument.charAt(i) == '[') {
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
errln("Error in collation arguments, missing ["); // no opening '['
|
||||
if(!TestUtil.isModularBuild()){
|
||||
errln("Error in collation arguments, missing ["); // no opening '['
|
||||
}
|
||||
printInfo=true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int value = argument.indexOf(' ', i);
|
||||
String option = argument.substring(i, value);
|
||||
i = argument.indexOf(']', value);
|
||||
@ -152,13 +170,17 @@ public class CollationTest extends ModuleTest
|
||||
}
|
||||
}
|
||||
}
|
||||
if(printInfo == true && TestUtil.isModularBuild()){
|
||||
infoln("Could not load the locale data. Skipping...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processReadyCollator(RuleBasedCollator col) {
|
||||
while (nextCase()) {
|
||||
// this is very sad, it is alittle awkward to write the c rb
|
||||
// to have an object array of an object array of a 1 element
|
||||
// string array. so now we have an object array of a 1 element
|
||||
// this is very sad, it is alittle awkward to write the c rb
|
||||
// to have an object array of an object array of a 1 element
|
||||
// string array. so now we have an object array of a 1 element
|
||||
// object array of string arrays.
|
||||
String sequence[] = testcase.getStringArray("sequence");
|
||||
for (int i = 0; i < sequence.length; i ++) {
|
||||
@ -166,24 +188,24 @@ public class CollationTest extends ModuleTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processSequence(RuleBasedCollator col, String sequence) {
|
||||
// TODO: have a smarter tester that remembers the sequence and ensures
|
||||
// that the complete sequence is in order. That is why I have made a
|
||||
// constraint in the sequence format.
|
||||
// TODO: have a smarter tester that remembers the sequence and ensures
|
||||
// that the complete sequence is in order. That is why I have made a
|
||||
// constraint in the sequence format.
|
||||
m_sequence_ = sequence;
|
||||
m_sequenceIndex_ = 0;
|
||||
m_nextRelation_ = -1;
|
||||
m_target_.delete(0, m_target_.length());
|
||||
Vector vector = new Vector();
|
||||
int lastsmallerthanindex = 0;
|
||||
while (getNextInSequence()) {
|
||||
while (getNextInSequence()) {
|
||||
String target = m_target_.toString();
|
||||
doTest(col, m_source_, target, m_relation_);
|
||||
int vsize = vector.size();
|
||||
for (int i = vsize - 1; i >= 0; i --) {
|
||||
String source = (String)vector.elementAt(i);
|
||||
if (i > lastsmallerthanindex) {
|
||||
String source = (String)vector.elementAt(i);
|
||||
if (i > lastsmallerthanindex) {
|
||||
doTest(col, source, target, m_relation_);
|
||||
}
|
||||
else {
|
||||
@ -196,15 +218,15 @@ public class CollationTest extends ModuleTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the sequence to be tested
|
||||
|
||||
/**
|
||||
* Parses the sequence to be tested
|
||||
*/
|
||||
private boolean getNextInSequence() {
|
||||
if (m_sequenceIndex_ >= m_sequence_.length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean quoted = false;
|
||||
boolean quotedsingle = false;
|
||||
boolean done = false;
|
||||
@ -230,7 +252,7 @@ public class CollationTest extends ModuleTest
|
||||
m_nextRelation_ = -1;
|
||||
done = true;
|
||||
break;
|
||||
case 0x003D : // =
|
||||
case 0x003D : // =
|
||||
m_nextRelation_ = 0;
|
||||
done = true;
|
||||
break;
|
||||
@ -255,11 +277,11 @@ public class CollationTest extends ModuleTest
|
||||
offset ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ch == 0x0027) {
|
||||
quoted = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UTF16.insert(m_target_, offset, ch);
|
||||
if (UCharacter.isSupplementary(ch)) {
|
||||
@ -278,43 +300,53 @@ public class CollationTest extends ModuleTest
|
||||
errln("Quote in sequence not closed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
m_sequenceIndex_ = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void doTestVariant(RuleBasedCollator myCollation,
|
||||
|
||||
private void doTestVariant(RuleBasedCollator myCollation,
|
||||
String source, String target, int result)
|
||||
{
|
||||
boolean printInfo = false;
|
||||
int compareResult = myCollation.compare(source, target);
|
||||
if (compareResult != result) {
|
||||
errln("Comparing \"" + Utility.hex(source) + "\" with \""
|
||||
+ Utility.hex(target) + "\" expected " + result
|
||||
+ " but got " + compareResult);
|
||||
printInfo = true;
|
||||
if(!TestUtil.isModularBuild()){
|
||||
errln("Comparing \"" + Utility.hex(source) + "\" with \""
|
||||
+ Utility.hex(target) + "\" expected " + result
|
||||
+ " but got " + compareResult);
|
||||
}
|
||||
}
|
||||
CollationKey ssk = myCollation.getCollationKey(source);
|
||||
CollationKey tsk = myCollation.getCollationKey(target);
|
||||
compareResult = ssk.compareTo(tsk);
|
||||
if (compareResult != result) {
|
||||
errln("Comparing sortkeys of \"" + Utility.hex(source) + "\" with \""
|
||||
+ Utility.hex(target) + "\" expected " + result
|
||||
+ " but got " + compareResult);
|
||||
}
|
||||
printInfo = true;
|
||||
if(!TestUtil.isModularBuild()){
|
||||
errln("Comparing sortkeys of \"" + Utility.hex(source) + "\" with \""
|
||||
+ Utility.hex(target) + "\" expected " + result
|
||||
+ " but got " + compareResult);
|
||||
}
|
||||
}
|
||||
if(printInfo == true && TestUtil.isModularBuild()){
|
||||
infoln("Could not load locale data skipping.");
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest(RuleBasedCollator myCollation,
|
||||
|
||||
private void doTest(RuleBasedCollator myCollation,
|
||||
String source, String target, int result)
|
||||
{
|
||||
doTestVariant(myCollation, source, target, result);
|
||||
if (result == 0) {
|
||||
doTestVariant(myCollation, target, source, result);
|
||||
doTestVariant(myCollation, target, source, result);
|
||||
}
|
||||
else if (result < 0) {
|
||||
doTestVariant(myCollation, target, source, 1);
|
||||
doTestVariant(myCollation, target, source, 1);
|
||||
}
|
||||
else {
|
||||
doTestVariant(myCollation, target, source, -1);
|
||||
doTestVariant(myCollation, target, source, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
55
icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java
Normal file
55
icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:33 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.collator;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
public void TestCollator() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.collator.CollationTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationAPITest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationCurrencyTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationDanishTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationDummyTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationEnglishTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationFinnishTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationFrenchTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationGermanTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationIteratorTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationKanaTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationMonkeyTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationRegressionTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationSpanishTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationThaiTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationTurkishTest(),
|
||||
new com.ibm.icu.dev.test.collator.G7CollationTest(),
|
||||
new com.ibm.icu.dev.test.collator.LotusCollationKoreanTest(),
|
||||
new com.ibm.icu.dev.test.collator.CollationMiscTest()
|
||||
});
|
||||
}
|
||||
|
||||
public void TestSearch() throws Exception {
|
||||
run(
|
||||
new com.ibm.icu.dev.test.search.SearchTest());
|
||||
}
|
||||
}
|
34
icu4j/src/com/ibm/icu/dev/test/compression/TestAll.java
Normal file
34
icu4j/src/com/ibm/icu/dev/test/compression/TestAll.java
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/compression/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:33 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.compression;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.bigdec.DiagBigDecimal;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
|
||||
public void TestCompression() throws Exception{
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.compression.DecompressionTest(),
|
||||
new com.ibm.icu.dev.test.compression.ExhaustiveTest()
|
||||
});
|
||||
}
|
||||
}
|
64
icu4j/src/com/ibm/icu/dev/test/format/TestAll.java
Normal file
64
icu4j/src/com/ibm/icu/dev/test/format/TestAll.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:33 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.format;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
|
||||
public void TestRuleBasedNumberFormat() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.format.RbnfTest(),
|
||||
new com.ibm.icu.dev.test.format.RbnfRoundTripTest()
|
||||
});
|
||||
}
|
||||
|
||||
public void TestNumberFormat() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.format.IntlTestNumberFormat(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestNumberFormatAPI(),
|
||||
new com.ibm.icu.dev.test.format.NumberFormatTest(),
|
||||
new com.ibm.icu.dev.test.format.NumberFormatRoundTripTest(),
|
||||
new com.ibm.icu.dev.test.format.NumberRegression(),
|
||||
new com.ibm.icu.dev.test.format.NumberFormatRegressionTest(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDecimalFormatAPI(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDecimalFormatAPIC(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDecimalFormatSymbols(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDecimalFormatSymbolsC()
|
||||
});
|
||||
}
|
||||
|
||||
public void TestDateFormat() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.format.DateFormatMiscTests(),
|
||||
new com.ibm.icu.dev.test.format.DateFormatRegressionTest(),
|
||||
new com.ibm.icu.dev.test.format.DateFormatRoundTripTest(),
|
||||
new com.ibm.icu.dev.test.format.DateFormatTest(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDateFormat(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDateFormatAPI(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDateFormatAPIC(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestDateFormatSymbols(),
|
||||
new com.ibm.icu.dev.test.format.IntlTestSimpleDateFormatAPI(),
|
||||
new com.ibm.icu.dev.test.format.DateFormatRegressionTestJ()
|
||||
});
|
||||
}
|
||||
}
|
48
icu4j/src/com/ibm/icu/dev/test/lang/TestAll.java
Normal file
48
icu4j/src/com/ibm/icu/dev/test/lang/TestAll.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:33 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.lang;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
public void TestCharacter() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.lang.UCharacterTest(),
|
||||
new com.ibm.icu.dev.test.lang.UCharacterCaseTest(),
|
||||
new com.ibm.icu.dev.test.lang.UCharacterIteratorTest(),
|
||||
new com.ibm.icu.dev.test.lang.UCharacterCategoryTest(),
|
||||
new com.ibm.icu.dev.test.lang.UCharacterDirectionTest(),
|
||||
new com.ibm.icu.dev.test.lang.UPropertyAliasesTest(),
|
||||
new com.ibm.icu.dev.test.lang.UTF16Test()
|
||||
});
|
||||
}
|
||||
public void TestUScript() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.lang.TestUScript(),
|
||||
});
|
||||
}
|
||||
public void TestUScriptRun() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.lang.TestUScriptRun(),
|
||||
});
|
||||
}
|
||||
}
|
@ -9,20 +9,22 @@ package com.ibm.icu.dev.test.lang;
|
||||
|
||||
import com.ibm.icu.lang.UScript;
|
||||
import com.ibm.icu.lang.UScriptRun;
|
||||
import com.ibm.icu.text.Transliterator;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
public class TestUScript extends TestFmwk{
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public TestUScript()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new TestUScript().run(args);
|
||||
}
|
||||
@ -30,34 +32,45 @@ public class TestUScript extends TestFmwk{
|
||||
final Locale[] testNames={
|
||||
/* test locale */
|
||||
new Locale("en",""), new Locale("en","US"),
|
||||
new Locale("sr",""), new Locale("ta","") ,
|
||||
new Locale("sr",""), new Locale("ta","") ,
|
||||
new Locale("te","IN"),
|
||||
new Locale("hi",""),
|
||||
new Locale("hi",""),
|
||||
new Locale("he",""), new Locale("ar",""),
|
||||
new Locale("abcde",""),
|
||||
new Locale("abcde","cdef")
|
||||
};
|
||||
final int[] expected ={
|
||||
/* locales should return */
|
||||
UScript.LATIN, UScript.LATIN,
|
||||
UScript.CYRILLIC, UScript.TAMIL,
|
||||
UScript.TELUGU,UScript.DEVANAGARI,
|
||||
UScript.LATIN, UScript.LATIN,
|
||||
UScript.CYRILLIC, UScript.TAMIL,
|
||||
UScript.TELUGU,UScript.DEVANAGARI,
|
||||
UScript.HEBREW, UScript.ARABIC,
|
||||
UScript.INVALID_CODE,UScript.INVALID_CODE
|
||||
};
|
||||
int i =0;
|
||||
int numErrors =0;
|
||||
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if((code!=null) && (code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
try{
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if(code == null && expected[i]==UScript.INVALID_CODE){
|
||||
// getCode returns null if the code could not be found
|
||||
continue;
|
||||
}
|
||||
if((code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
}
|
||||
if(numErrors >0 ){
|
||||
errln("Number of Errors in UScript.getCode() : " + numErrors);
|
||||
}
|
||||
}catch(MissingResourceException e){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not find Locale data");
|
||||
}else{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if(numErrors >0 ){
|
||||
errln("Number of Errors in UScript.getCode() : " + numErrors);
|
||||
}
|
||||
}
|
||||
public void TestMultipleCode(){
|
||||
final String[] testNames = { "ja" ,"ko_KR","zh","zh_TW"};
|
||||
@ -67,75 +80,110 @@ public class TestUScript extends TestFmwk{
|
||||
{UScript.HAN},
|
||||
{UScript.HAN,UScript.BOPOMOFO}
|
||||
};
|
||||
for(int i=0; i<testNames.length;i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
int[] expt = (int[]) expected[i];
|
||||
for(int j =0; j< code.length;j++){
|
||||
if(code[j]!=expt[j]){
|
||||
logln("Error getting script code Got: " +code[j] + " Expected: " +expt[j] +" for name "+testNames[i]);
|
||||
try{
|
||||
int numErrors = 0;
|
||||
for(int i=0; i<testNames.length;i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
int[] expt = (int[]) expected[i];
|
||||
if(code!=null){
|
||||
for(int j =0; j< code.length;j++){
|
||||
if(code[j]!=expt[j]){
|
||||
numErrors++;
|
||||
logln("Error getting script code Got: " +code[j] + " Expected: " +expt[j] +" for name "+testNames[i]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
numErrors++;
|
||||
}
|
||||
}
|
||||
if(numErrors >0 ){
|
||||
errln("Number of Errors in UScript.getCode() : " + numErrors);
|
||||
}
|
||||
}catch(MissingResourceException e){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not find Locale data");
|
||||
}else{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void TestGetCode(){
|
||||
|
||||
final String[] testNames={
|
||||
/* test locale */
|
||||
"en", "en_US", "sr", "ta"," ___ ---ta" , "te_IN",
|
||||
/* test locale */
|
||||
"en", "en_US", "sr", "ta"," ___ ---ta" , "te_IN",
|
||||
"hi", "he", "ar",
|
||||
/* test abbr */
|
||||
"Hani", "Hang","Hebr","Hira",
|
||||
"Knda","Kana","Khmr","Lao",
|
||||
"Latn",/*"Latf","Latg",*/
|
||||
"Latn",/*"Latf","Latg",*/
|
||||
"Mlym", "Mong",
|
||||
|
||||
|
||||
/* test names */
|
||||
"CYRILLIC","DESERET","DEVANAGARI","ETHIOPIC","GEORGIAN",
|
||||
"GOTHIC", "GREEK", "GUJARATI", "COMMON", "INHERITED",
|
||||
"CYRILLIC","DESERET","DEVANAGARI","ETHIOPIC","GEORGIAN",
|
||||
"GOTHIC", "GREEK", "GUJARATI", "COMMON", "INHERITED",
|
||||
/* test lower case names */
|
||||
"malayalam", "mongolian", "myanmar", "ogham", "old-italic",
|
||||
"oriya", "runic", "sinhala", "syriac","tamil",
|
||||
"telugu", "thaana", "thai", "tibetan",
|
||||
"oriya", "runic", "sinhala", "syriac","tamil",
|
||||
"telugu", "thaana", "thai", "tibetan",
|
||||
/* test the bounds*/
|
||||
"ucas", "arabic","Yi","Zyyy"
|
||||
};
|
||||
final int[] expected ={
|
||||
/* locales should return */
|
||||
UScript.LATIN, UScript.LATIN,
|
||||
UScript.CYRILLIC, UScript.TAMIL, UScript.TAMIL,
|
||||
UScript.TELUGU,UScript.DEVANAGARI,
|
||||
UScript.LATIN, UScript.LATIN,
|
||||
UScript.CYRILLIC, UScript.TAMIL, UScript.TAMIL,
|
||||
UScript.TELUGU,UScript.DEVANAGARI,
|
||||
UScript.HEBREW, UScript.ARABIC,
|
||||
/* abbr should return */
|
||||
UScript.HAN, UScript.HANGUL, UScript.HEBREW, UScript.HIRAGANA,
|
||||
UScript.KANNADA, UScript.KATAKANA, UScript.KHMER, UScript.LAO,
|
||||
UScript.LATIN,/* UScript.LATIN, UScript.LATIN,*/
|
||||
UScript.LATIN,/* UScript.LATIN, UScript.LATIN,*/
|
||||
UScript.MALAYALAM, UScript.MONGOLIAN,
|
||||
/* names should return */
|
||||
UScript.CYRILLIC, UScript.DESERET, UScript.DEVANAGARI, UScript.ETHIOPIC, UScript.GEORGIAN,
|
||||
UScript.GOTHIC, UScript.GREEK, UScript.GUJARATI, UScript.COMMON, UScript.INHERITED,
|
||||
/* lower case names should return */
|
||||
/* lower case names should return */
|
||||
UScript.MALAYALAM, UScript.MONGOLIAN, UScript.MYANMAR, UScript.OGHAM, UScript.OLD_ITALIC,
|
||||
UScript.ORIYA, UScript.RUNIC, UScript.SINHALA, UScript.SYRIAC, UScript.TAMIL,
|
||||
UScript.TELUGU, UScript.THAANA, UScript.THAI, UScript.TIBETAN,
|
||||
/* bounds */
|
||||
UScript.UCAS, UScript.ARABIC, UScript.YI, UScript.COMMON
|
||||
UScript.UCAS, UScript.ARABIC, UScript.YI, UScript.COMMON
|
||||
};
|
||||
int i =0;
|
||||
int numErrors =0;
|
||||
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if((code!=null) && (code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
try{
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if(code == null){
|
||||
if(expected[i]==UScript.INVALID_CODE){
|
||||
// getCode returns null if the code could not be found
|
||||
continue;
|
||||
}
|
||||
// currently commented out until jitterbug#2678 is fixed
|
||||
// logln("Error getting script code Got: null" + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
// numErrors++;
|
||||
continue;
|
||||
}
|
||||
if((code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
}
|
||||
if(numErrors >0 ){
|
||||
errln("Number of Errors in UScript.getCode() : " + numErrors);
|
||||
}
|
||||
}catch(MissingResourceException e){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not find Locale data");
|
||||
}else{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if(numErrors >0 ){
|
||||
errln("Number of Errors in UScript.getCode() : " + numErrors);
|
||||
}
|
||||
|
||||
}
|
||||
public void TestGetName(){
|
||||
|
||||
|
||||
final int[] testCodes={
|
||||
/* names should return */
|
||||
UScript.CYRILLIC, UScript.DESERET, UScript.DEVANAGARI, UScript.ETHIOPIC, UScript.GEORGIAN,
|
||||
@ -143,27 +191,28 @@ public class TestUScript extends TestFmwk{
|
||||
};
|
||||
|
||||
final String[] expectedNames={
|
||||
|
||||
|
||||
/* test names */
|
||||
"Cyrillic","Deseret","Devanagari","Ethiopic","Georgian",
|
||||
"Gothic", "Greek", "Gujarati",
|
||||
"Cyrillic","Deseret","Devanagari","Ethiopic","Georgian",
|
||||
"Gothic", "Greek", "Gujarati",
|
||||
};
|
||||
int i =0;
|
||||
|
||||
int numErrors=0;
|
||||
while(i< testCodes.length){
|
||||
String scriptName = UScript.getName(testCodes[i]);
|
||||
int numErrors=0;
|
||||
if(!expectedNames[i].equals(scriptName)){
|
||||
logln("Error getting abbreviations Got: " +scriptName +" Expected: "+expectedNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
if(numErrors > 0){
|
||||
if(numErrors >0 ){
|
||||
errln("Errors UScript.getShorName() : " + numErrors);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(numErrors >0 ){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not find Locale data");
|
||||
}else{
|
||||
errln("Number of Errors in UScript.getName() : " + numErrors);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void TestGetShortName(){
|
||||
@ -171,7 +220,7 @@ public class TestUScript extends TestFmwk{
|
||||
/* abbr should return */
|
||||
UScript.HAN, UScript.HANGUL, UScript.HEBREW, UScript.HIRAGANA,
|
||||
UScript.KANNADA, UScript.KATAKANA, UScript.KHMER, UScript.LAO,
|
||||
UScript.LATIN,
|
||||
UScript.LATIN,
|
||||
UScript.MALAYALAM, UScript.MONGOLIAN,
|
||||
};
|
||||
|
||||
@ -183,30 +232,31 @@ public class TestUScript extends TestFmwk{
|
||||
"Mlym", "Mong",
|
||||
};
|
||||
int i=0;
|
||||
int numErrors=0;
|
||||
while(i<testCodes.length){
|
||||
String shortName = UScript.getShortName(testCodes[i]);
|
||||
int numErrors=0;
|
||||
if(!expectedAbbr[i].equals(shortName)){
|
||||
logln("Error getting abbreviations Got: " +shortName+ " Expected: " +expectedAbbr[i]);
|
||||
numErrors++;
|
||||
}
|
||||
if(numErrors > 0){
|
||||
if(numErrors >0 ){
|
||||
errln("Errors UChar.getScriptAbbr() : "+numErrors);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(numErrors >0 ){
|
||||
if(TestUtil.isModularBuild()){
|
||||
infoln("Could not find Locale data");
|
||||
}else{
|
||||
errln("Number of Errors in UScript.getShortName() : " + numErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void TestGetScript(){
|
||||
int codepoints[] = {
|
||||
0x0000FF9D,
|
||||
0x0000FFBE,
|
||||
0x0000FFC7,
|
||||
0x0000FFCF,
|
||||
0x0000FFD7,
|
||||
0x0000FFDC,
|
||||
0x0000FF9D,
|
||||
0x0000FFBE,
|
||||
0x0000FFC7,
|
||||
0x0000FFCF,
|
||||
0x0000FFD7,
|
||||
0x0000FFDC,
|
||||
0x00010300,
|
||||
0x00010330,
|
||||
0x0001034A,
|
||||
@ -220,10 +270,10 @@ public class TestUScript extends TestFmwk{
|
||||
0x00000D02,
|
||||
0x00000D00,
|
||||
0x00000000,
|
||||
0x0001D169,
|
||||
0x0001D182,
|
||||
0x0001D18B,
|
||||
0x0001D1AD,
|
||||
0x0001D169,
|
||||
0x0001D182,
|
||||
0x0001D18B,
|
||||
0x0001D1AD,
|
||||
};
|
||||
|
||||
int expected[] = {
|
||||
@ -233,7 +283,7 @@ public class TestUScript extends TestFmwk{
|
||||
UScript.HANGUL ,
|
||||
UScript.HANGUL ,
|
||||
UScript.HANGUL ,
|
||||
UScript.OLD_ITALIC,
|
||||
UScript.OLD_ITALIC,
|
||||
UScript.GOTHIC ,
|
||||
UScript.GOTHIC ,
|
||||
UScript.DESERET ,
|
||||
@ -267,51 +317,7 @@ public class TestUScript extends TestFmwk{
|
||||
}
|
||||
if(!passed){
|
||||
errln("UScript.getScript failed.");
|
||||
}
|
||||
}
|
||||
public void TestAllCodepoints(){
|
||||
int code;
|
||||
String oldId="";
|
||||
String oldAbbrId="";
|
||||
for( int i =0; i <= 0x10ffff; i++){
|
||||
code =UScript.INVALID_CODE;
|
||||
code = UScript.getScript(i);
|
||||
if(code==UScript.INVALID_CODE){
|
||||
errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
|
||||
}
|
||||
String id =UScript.getName(code);
|
||||
String abbr = UScript.getShortName(code);
|
||||
String newId ="[:"+id+":];NFD";
|
||||
String newAbbrId ="[:"+abbr+":];NFD";
|
||||
if(!oldId.equals(newId)){
|
||||
try{
|
||||
Transliterator t = Transliterator.getInstance(newId);
|
||||
if(t==null){
|
||||
errln("Failed to create transliterator for "+hex(i)+
|
||||
" script code: " +id);
|
||||
}
|
||||
}catch(Exception e){
|
||||
errln("Failed to create transliterator for "+hex(i)
|
||||
+" script code: " +id
|
||||
+ " Exception: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
oldId = newId;
|
||||
if(!oldAbbrId.equals(newAbbrId)){
|
||||
try{
|
||||
Transliterator t = Transliterator.getInstance(newAbbrId);
|
||||
if(t==null){
|
||||
errln("Failed to create transliterator for "+hex(i)+
|
||||
" script code: " +abbr);
|
||||
}
|
||||
}catch(Exception e){
|
||||
errln("Failed to create transliterator for "+hex(i)
|
||||
+" script code: " +abbr
|
||||
+ " Exception: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
oldAbbrId = newAbbrId;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void TestScriptNames(){
|
||||
for(int i=0; i<UScript.CODE_LIMIT;i++){
|
||||
@ -324,5 +330,25 @@ public class TestUScript extends TestFmwk{
|
||||
errln("FAILED: getName for code : "+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void TestAllCodepoints(){
|
||||
int code;
|
||||
String oldId="";
|
||||
String oldAbbrId="";
|
||||
for( int i =0; i <= 0x10ffff; i++){
|
||||
code =UScript.INVALID_CODE;
|
||||
code = UScript.getScript(i);
|
||||
if(code==UScript.INVALID_CODE){
|
||||
errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
|
||||
}
|
||||
String id =UScript.getName(code);
|
||||
if(id.indexOf("INVALID")>=0){
|
||||
errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
|
||||
}
|
||||
String abbr = UScript.getShortName(code);
|
||||
if(abbr.indexOf("INV")>=0){
|
||||
errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -5,21 +5,28 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/BasicTest.java,v $
|
||||
* $Date: 2002/12/11 23:29:09 $
|
||||
* $Revision: 1.23 $
|
||||
* $Date: 2003/01/28 18:55:33 $
|
||||
* $Revision: 1.24 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
import java.text.StringCharacterIterator;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.impl.*;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import java.util.Random;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.NormalizerImpl;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.lang.UCharacterCategory;
|
||||
import com.ibm.icu.text.Normalizer;
|
||||
import com.ibm.icu.text.UCharacterIterator;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
|
||||
|
||||
public class BasicTest extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new BasicTest().run(args);
|
||||
@ -1216,41 +1223,6 @@ public class BasicTest extends TestFmwk {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TestDeprecatedAPI(){
|
||||
// instantiate a Normalizer from a CharacterIterator
|
||||
String s=Utility.unescape("a\u0308\uac00\\U0002f800");
|
||||
// make s a bit longer and more interesting
|
||||
java.text.CharacterIterator iter = new StringCharacterIterator(s+s);
|
||||
//test deprecated constructors
|
||||
Normalizer norm = new Normalizer(iter, Normalizer.NFC,0);
|
||||
Normalizer norm2 = new Normalizer(s,Normalizer.NFC,0);
|
||||
if(norm.next()!=0xe4) {
|
||||
errln("error in Normalizer(CharacterIterator).next()");
|
||||
}
|
||||
// test clone(), ==, and hashCode()
|
||||
Normalizer clone=(Normalizer)norm.clone();
|
||||
if(clone.getBeginIndex()!= norm.getBeginIndex()){
|
||||
errln("error in Normalizer.getBeginIndex()");
|
||||
}
|
||||
|
||||
if(clone.getEndIndex()!= norm.getEndIndex()){
|
||||
errln("error in Normalizer.getEndIndex()");
|
||||
}
|
||||
// test setOption() and getOption()
|
||||
clone.setOption(0xaa0000, true);
|
||||
clone.setOption(0x20000, false);
|
||||
if(clone.getOption(0x880000) ==0|| clone.getOption(0x20000)==1) {
|
||||
errln("error in Normalizer::setOption() or Normalizer::getOption()");
|
||||
}
|
||||
//test deprecated normalize method
|
||||
Normalizer.normalize(s,Normalizer.NFC,0);
|
||||
//test deprecated compose method
|
||||
Normalizer.compose(s,false,0);
|
||||
//test deprecated decompose method
|
||||
Normalizer.decompose(s,false,0);
|
||||
|
||||
}
|
||||
|
||||
// test APIs that are not otherwise used - improve test coverage
|
||||
|
@ -5,20 +5,24 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/ConformanceTest.java,v $
|
||||
* $Date: 2002/11/22 00:23:19 $
|
||||
* $Revision: 1.11 $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.12 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.io.*;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.text.Normalizer;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
|
||||
public class ConformanceTest extends TestFmwk {
|
||||
|
||||
@ -174,6 +178,9 @@ public class ConformanceTest extends TestFmwk {
|
||||
|
||||
out = iterativeNorm(new StringCharacterIterator(field[i]), Normalizer.NFD, buf, -1);
|
||||
pass &= assertEqual("D(-1)", field[i], out, field[2], "c3!=D(c" + (i+1));
|
||||
|
||||
cross(field[2] /*NFD String*/, field[1]/*NFC String*/, Normalizer.NFC);
|
||||
cross(field[1] /*NFC String*/, field[2]/*NFD String*/, Normalizer.NFD);
|
||||
}
|
||||
out = Normalizer.normalize(field[i], Normalizer.NFKC);
|
||||
pass &= assertEqual("KC", field[i], out, field[3], "c4!=KC(c" + (i+1));
|
||||
@ -205,7 +212,10 @@ public class ConformanceTest extends TestFmwk {
|
||||
|
||||
out = iterativeNorm(new StringCharacterIterator(field[i]), Normalizer.NFKD, buf, -1);
|
||||
pass &= assertEqual("KD(-1)", field[i], out, field[4], "c5!=KD(c" + (i+1));
|
||||
|
||||
|
||||
cross(field[4] /*NFKD String*/, field[3]/*NFKC String*/, Normalizer.NFKC);
|
||||
cross(field[3] /*NFKC String*/, field[4]/*NFKD String*/, Normalizer.NFKD);
|
||||
|
||||
}
|
||||
compare(field[1],field[2]);
|
||||
compare(field[0],field[1]);
|
||||
@ -315,6 +325,13 @@ public class ConformanceTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
}
|
||||
private void cross(String s1, String s2,Normalizer.Mode mode){
|
||||
String result = Normalizer.normalize(s1,mode);
|
||||
if(!result.equals(s2)){
|
||||
errln("cross test failed s1: " + Utility.hex(s1) + " s2: "
|
||||
+Utility.hex(s2));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Do a normalization using the iterative API in the given direction.
|
||||
* @param buf scratch buffer
|
||||
|
@ -4,19 +4,23 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source:
|
||||
* $Date:
|
||||
* $Revision:
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/NormalizationMonkeyTest.java,v $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.text.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.lang.UCharacterCategory;
|
||||
import com.ibm.icu.text.Normalizer;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
|
||||
public class NormalizationMonkeyTest extends TestFmwk {
|
||||
int loopCount = 100;
|
||||
int maxCharCount = 20;
|
||||
|
@ -4,39 +4,42 @@ import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.BitSet;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
import com.ibm.icu.dev.test.UTF16Util;
|
||||
|
||||
|
||||
/**
|
||||
* Builds the normalization tables. This is a separate class so that it
|
||||
* can be unloaded once not needed.<br>
|
||||
* Copyright © 1998-2002 Unicode, Inc. All Rights Reserved.<br>
|
||||
* Copyright ? 1998-2002 Unicode, Inc. All Rights Reserved.<br>
|
||||
* The Unicode Consortium makes no expressed or implied warranty of any
|
||||
* kind, and assumes no liability for errors or omissions.
|
||||
* No liability is assumed for incidental and consequential damages
|
||||
* in connection with or arising out of the use of the information here.
|
||||
* @author Mark Davis
|
||||
* Updates for supplementary code points:
|
||||
* Updates for supplementary code points:
|
||||
* Vladimir Weinstein & Markus Scherer
|
||||
*/
|
||||
class NormalizerBuilder {
|
||||
static final String copyright = "Copyright © 1998-1999 Unicode, Inc.";
|
||||
|
||||
static final String copyright = "Copyright ? 1998-1999 Unicode, Inc.";
|
||||
|
||||
/**
|
||||
* Testing flags
|
||||
*/
|
||||
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean GENERATING = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constants for the data file version to use.
|
||||
*/
|
||||
/*static final boolean NEW_VERSION = true;
|
||||
private static final String DIR = "D:\\UnicodeData\\" + (NEW_VERSION ? "WorkingGroups\\" : "");
|
||||
|
||||
|
||||
static final String UNIDATA_VERSION = NEW_VERSION ? "3.0.0d12" : "2.1.9";
|
||||
static final String EXCLUSIONS_VERSION = NEW_VERSION ? "1d4" : "1";
|
||||
|
||||
|
||||
public static final String UNICODE_DATA = DIR + "UnicodeData-" + UNIDATA_VERSION + ".txt";
|
||||
public static final String COMPOSITION_EXCLUSIONS = DIR + "CompositionExclusions-" + EXCLUSIONS_VERSION +".txt";
|
||||
*/
|
||||
@ -44,7 +47,7 @@ class NormalizerBuilder {
|
||||
/**
|
||||
* Called exactly once by NormalizerData to build the static data
|
||||
*/
|
||||
|
||||
|
||||
static NormalizerData build(boolean fullData) {
|
||||
try {
|
||||
IntHashtable canonicalClass = new IntHashtable(0);
|
||||
@ -56,14 +59,14 @@ class NormalizerBuilder {
|
||||
//System.out.println("Building Normalizer Data from file.");
|
||||
readExclusionList(isExcluded);
|
||||
//System.out.println(isExcluded.get(0x00C0));
|
||||
buildDecompositionTables(canonicalClass, decompose, compose,
|
||||
buildDecompositionTables(canonicalClass, decompose, compose,
|
||||
isCompatibility, isExcluded);
|
||||
} else { // for use in Applets
|
||||
//System.out.println("Building abridged data.");
|
||||
setMinimalDecomp(canonicalClass, decompose, compose,
|
||||
isCompatibility, isExcluded);
|
||||
setMinimalDecomp(canonicalClass, decompose, compose,
|
||||
isCompatibility, isExcluded);
|
||||
}
|
||||
return new NormalizerData(canonicalClass, decompose, compose,
|
||||
return new NormalizerData(canonicalClass, decompose, compose,
|
||||
isCompatibility, isExcluded);
|
||||
} catch (java.io.IOException e) {
|
||||
System.err.println("Can't load data file." + e + ", " + e.getMessage());
|
||||
@ -88,11 +91,11 @@ class NormalizerBuilder {
|
||||
System.err.println("Fail to read the file CompositionExclusions.txt!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
while (true) {
|
||||
|
||||
|
||||
// read a line, discarding comments and blank lines
|
||||
|
||||
|
||||
String line = in.readLine();
|
||||
if (line == null) break;
|
||||
int comment = line.indexOf('#'); // strip comments
|
||||
@ -102,7 +105,7 @@ class NormalizerBuilder {
|
||||
line = line.substring(0, line.indexOf(' '));
|
||||
}
|
||||
// store -1 in the excluded table for each character hit
|
||||
|
||||
|
||||
int value = Integer.parseInt(line,16);
|
||||
isExcluded.set(value);
|
||||
//System.out.println("Excluding " + hex(value));
|
||||
@ -110,12 +113,12 @@ class NormalizerBuilder {
|
||||
in.close();
|
||||
if (DEBUG) System.out.println("Done reading Exclusions");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds a decomposition table from a UnicodeData file
|
||||
*/
|
||||
private static void buildDecompositionTables(
|
||||
IntHashtable canonicalClass, IntStringHashtable decompose,
|
||||
IntHashtable canonicalClass, IntStringHashtable decompose,
|
||||
LongHashtable compose, BitSet isCompatibility, BitSet isExcluded)
|
||||
throws java.io.IOException {
|
||||
if (DEBUG) System.out.println("Reading Unicode Character Database");
|
||||
@ -127,14 +130,14 @@ class NormalizerBuilder {
|
||||
System.err.println("Failed to read UnicodeData.txt");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
int value;
|
||||
long pair;
|
||||
int counter = 0;
|
||||
while (true) {
|
||||
|
||||
|
||||
// read a line, discarding comments and blank lines
|
||||
|
||||
|
||||
String line = in.readLine();
|
||||
if (line == null) break;
|
||||
int comment = line.indexOf('#'); // strip comments
|
||||
@ -144,10 +147,10 @@ class NormalizerBuilder {
|
||||
counter++;
|
||||
if ((counter & 0xFF) == 0) System.out.println("At: " + line);
|
||||
}
|
||||
|
||||
|
||||
// find the values of the particular fields that we need
|
||||
// Sample line: 00C0;LATIN ...A GRAVE;Lu;0;L;0041 0300;;;;N;LATIN ... GRAVE;;;00E0;
|
||||
|
||||
|
||||
int start = 0;
|
||||
int end = line.indexOf(';'); // code
|
||||
value = Integer.parseInt(line.substring(start,end),16);
|
||||
@ -158,27 +161,27 @@ class NormalizerBuilder {
|
||||
String name = line.substring(start,end);
|
||||
end = line.indexOf(';',start=end+1); // general category
|
||||
end = line.indexOf(';',start=end+1); // canonical class
|
||||
|
||||
|
||||
// check consistency: canonical classes must be from 0 to 255
|
||||
|
||||
|
||||
int cc = Integer.parseInt(line.substring(start,end));
|
||||
if (cc != (cc & 0xFF)) System.err.println("Bad canonical class at: " + line);
|
||||
canonicalClass.put(value,cc);
|
||||
end = line.indexOf(';',start=end+1); // BIDI
|
||||
end = line.indexOf(';',start=end+1); // decomp
|
||||
|
||||
|
||||
// decomp requires more processing.
|
||||
// store whether it is canonical or compatibility.
|
||||
// store the decomp in one table, and the reverse mapping (from pairs) in another
|
||||
|
||||
|
||||
if (start != end) {
|
||||
String segment = line.substring(start, end);
|
||||
boolean compat = segment.charAt(0) == '<';
|
||||
if (compat) isCompatibility.set(value);
|
||||
String decomp = fromHex(segment);
|
||||
|
||||
|
||||
// a small snippet of code to generate the Applet data
|
||||
|
||||
|
||||
/*if (GENERATING) {
|
||||
if (value < 0xFF) {
|
||||
System.out.println(
|
||||
@ -188,28 +191,28 @@ class NormalizerBuilder {
|
||||
+ "// " + name);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// check consistency: all canon decomps must be singles or pairs!
|
||||
int decompLen = UTF16Util.countCodePoint(decomp);
|
||||
if (decompLen < 1 || decompLen > 2 && !compat) {
|
||||
System.err.println("Bad decomp at: " + line);
|
||||
}
|
||||
decompose.put(value, decomp);
|
||||
|
||||
|
||||
// only compositions are canonical pairs
|
||||
// skip if script exclusion
|
||||
|
||||
|
||||
if (!compat && !isExcluded.get(value)) {
|
||||
int first = '\u0000';
|
||||
int second = UTF16Util.nextCodePoint(decomp, 0);
|
||||
if (decompLen > 1) {
|
||||
first = second;
|
||||
second = UTF16Util.nextCodePoint(decomp,
|
||||
second = UTF16Util.nextCodePoint(decomp,
|
||||
UTF16Util.codePointLength(first));
|
||||
}
|
||||
|
||||
|
||||
// store composition pair in single integer
|
||||
|
||||
|
||||
pair = ((long)first << 32) | second;
|
||||
if (DEBUG && value == '\u00C0') {
|
||||
System.out.println("debug2: " + line);
|
||||
@ -222,13 +225,13 @@ class NormalizerBuilder {
|
||||
}
|
||||
in.close();
|
||||
if (DEBUG) System.out.println("Done reading Unicode Character Database");
|
||||
|
||||
|
||||
// add algorithmic Hangul decompositions
|
||||
// this is more compact if done at runtime, but for simplicity we
|
||||
// do it this way.
|
||||
|
||||
|
||||
if (DEBUG) System.out.println("Adding Hangul");
|
||||
|
||||
|
||||
for (int SIndex = 0; SIndex < SCount; ++SIndex) {
|
||||
int TIndex = SIndex % TCount;
|
||||
char first, second;
|
||||
@ -250,16 +253,16 @@ class NormalizerBuilder {
|
||||
/**
|
||||
* Hangul composition constants
|
||||
*/
|
||||
static final int
|
||||
static final int
|
||||
SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7,
|
||||
LCount = 19, VCount = 21, TCount = 28,
|
||||
NCount = VCount * TCount, // 588
|
||||
SCount = LCount * NCount; // 11172
|
||||
|
||||
|
||||
/**
|
||||
* For use in an applet: just load a minimal set of data.
|
||||
*/
|
||||
private static void setMinimalDecomp(IntHashtable canonicalClass, IntStringHashtable decompose,
|
||||
private static void setMinimalDecomp(IntHashtable canonicalClass, IntStringHashtable decompose,
|
||||
LongHashtable compose, BitSet isCompatibility, BitSet isExcluded) {
|
||||
String[] decomposeData = {
|
||||
"\u005E", "\u0020\u0302", "K",
|
||||
@ -412,10 +415,10 @@ class NormalizerBuilder {
|
||||
0x0360, 234,
|
||||
0x0361, 234
|
||||
};
|
||||
|
||||
|
||||
// build the same tables we would otherwise get from the
|
||||
// Unicode Character Database, just with limited data
|
||||
|
||||
|
||||
for (int i = 0; i < decomposeData.length; i+=3) {
|
||||
char value = decomposeData[i].charAt(0);
|
||||
String decomp = decomposeData[i+1];
|
||||
@ -427,19 +430,19 @@ class NormalizerBuilder {
|
||||
int second = UTF16Util.nextCodePoint(decomp, 0);
|
||||
if (decomp.length() > 1) {
|
||||
first = second;
|
||||
second = UTF16Util.nextCodePoint(decomp,
|
||||
second = UTF16Util.nextCodePoint(decomp,
|
||||
UTF16Util.codePointLength(first));
|
||||
}
|
||||
long pair = (first << 16) | second;
|
||||
compose.put(pair, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < classData.length;) {
|
||||
canonicalClass.put(classData[i++], classData[i++]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility: Parses a sequence of hex Unicode characters separated by spaces
|
||||
*/
|
||||
@ -449,8 +452,8 @@ class NormalizerBuilder {
|
||||
char c = source.charAt(i);
|
||||
switch (c) {
|
||||
case ' ': break; // ignore
|
||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
|
||||
case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
|
||||
case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||
int end = 0;
|
||||
int value = 0;
|
||||
@ -481,7 +484,7 @@ class NormalizerBuilder {
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility: Supplies a zero-padded hex representation of an integer (without 0x)
|
||||
*/
|
||||
@ -489,7 +492,7 @@ class NormalizerBuilder {
|
||||
String result = Long.toString(i & 0xFFFFFFFFL, 16).toUpperCase();
|
||||
return "00000000".substring(result.length(),8) + result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility: Supplies a zero-padded hex representation of a Unicode character (without 0x, \\u)
|
||||
*/
|
||||
@ -497,16 +500,16 @@ class NormalizerBuilder {
|
||||
String result = Integer.toString(i, 16).toUpperCase();
|
||||
return "0000".substring(result.length(),4) + result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility: Supplies a zero-padded hex representation of a Unicode character (without 0x, \\u)
|
||||
*/
|
||||
public static String hex(String s, String sep) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
if (i != 0) result.append(sep);
|
||||
result.append(hex(s.charAt(i)));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
public static String hex(String s, String sep) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
if (i != 0) result.append(sep);
|
||||
result.append(hex(s.charAt(i)));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package com.ibm.icu.dev.test.normalizer;
|
||||
import java.util.Hashtable;
|
||||
import java.util.BitSet;
|
||||
|
||||
import com.ibm.icu.dev.test.UTF16Util;
|
||||
|
||||
/**
|
||||
* Accesses the Normalization Data used for Forms C and D.<br>
|
||||
* Copyright © 1998-2002 Unicode, Inc. All Rights Reserved.<br>
|
||||
@ -11,12 +13,12 @@ import java.util.BitSet;
|
||||
* No liability is assumed for incidental and consequential damages
|
||||
* in connection with or arising out of the use of the information here.
|
||||
* @author Mark Davis
|
||||
* Updates for supplementary code points:
|
||||
* Updates for supplementary code points:
|
||||
* Vladimir Weinstein & Markus Scherer
|
||||
*/
|
||||
public class NormalizerData {
|
||||
static final String copyright = "Copyright © 1998-1999 Unicode, Inc.";
|
||||
|
||||
|
||||
/**
|
||||
* Constant for use in getPairwiseComposition
|
||||
*/
|
||||
@ -45,17 +47,17 @@ public class NormalizerData {
|
||||
|
||||
|
||||
/**
|
||||
* Gets recursive decomposition of a character from the
|
||||
* Gets recursive decomposition of a character from the
|
||||
* Unicode Character Database.
|
||||
* @param canonical If true
|
||||
* bit is on in this byte, then selects the recursive
|
||||
* bit is on in this byte, then selects the recursive
|
||||
* canonical decomposition, otherwise selects
|
||||
* the recursive compatibility and canonical decomposition.
|
||||
* @param ch the source character
|
||||
* @param buffer buffer to be filled with the decomposition
|
||||
*/
|
||||
public void getRecursiveDecomposition(boolean canonical, int ch, StringBuffer buffer) {
|
||||
String decomp = decompose.get(ch);
|
||||
String decomp = decompose.get(ch);
|
||||
if (decomp != null && !(canonical && isCompatibility.get(ch))) {
|
||||
for (int i = 0; i < decomp.length(); i+=UTF16Util.codePointLength(ch)) {
|
||||
ch = UTF16Util.nextCodePoint(decomp, i);
|
||||
@ -65,15 +67,15 @@ public class NormalizerData {
|
||||
UTF16Util.appendCodePoint(buffer, ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =================================================
|
||||
// PRIVATES
|
||||
// =================================================
|
||||
|
||||
|
||||
/**
|
||||
* Only accessed by NormalizerBuilder.
|
||||
*/
|
||||
NormalizerData(IntHashtable canonicalClass, IntStringHashtable decompose,
|
||||
NormalizerData(IntHashtable canonicalClass, IntStringHashtable decompose,
|
||||
LongHashtable compose, BitSet isCompatibility, BitSet isExcluded) {
|
||||
this.canonicalClass = canonicalClass;
|
||||
this.decompose = decompose;
|
||||
@ -81,21 +83,21 @@ public class NormalizerData {
|
||||
this.isCompatibility = isCompatibility;
|
||||
this.isExcluded = isExcluded;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Just accessible for testing.
|
||||
*/
|
||||
boolean getExcluded (char ch) {
|
||||
return isExcluded.get(ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Just accessible for testing.
|
||||
*/
|
||||
String getRawDecompositionMapping (char ch) {
|
||||
return decompose.get(ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For now, just use IntHashtable
|
||||
* Two-stage tables would be used in an optimized implementation.
|
||||
@ -112,22 +114,22 @@ public class NormalizerData {
|
||||
* index in a small array of ints.
|
||||
*/
|
||||
private IntStringHashtable decompose;
|
||||
|
||||
|
||||
/**
|
||||
* Maps from pairs of characters to single.
|
||||
* If there is no decomposition, the value is NOT_COMPOSITE.
|
||||
*/
|
||||
private LongHashtable compose;
|
||||
|
||||
|
||||
/**
|
||||
* Tells whether decomposition is canonical or not.
|
||||
*/
|
||||
private BitSet isCompatibility = new BitSet();
|
||||
|
||||
|
||||
/**
|
||||
* Tells whether character is script-excluded or not.
|
||||
* Used only while building, and for testing.
|
||||
*/
|
||||
|
||||
|
||||
private BitSet isExcluded = new BitSet();
|
||||
}
|
36
icu4j/src/com/ibm/icu/dev/test/normalizer/TestAll.java
Normal file
36
icu4j/src/com/ibm/icu/dev/test/normalizer/TestAll.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
public void TestNormalizer() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.normalizer.BasicTest(),
|
||||
new com.ibm.icu.dev.test.normalizer.ConformanceTest(),
|
||||
//new com.ibm.icu.dev.test.normalizer.TestDeprecatedNormalizerAPI(),
|
||||
new com.ibm.icu.dev.test.normalizer.TestCanonicalIterator(),
|
||||
new com.ibm.icu.dev.test.normalizer.NormalizationMonkeyTest(),
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/TestCanonicalIterator.java,v $
|
||||
* $Date: 2002/12/11 23:29:28 $
|
||||
* $Revision: 1.11 $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.12 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -14,11 +14,18 @@ package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.util.*;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.text.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Set;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.text.CanonicalIterator;
|
||||
import com.ibm.icu.text.Normalizer;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
|
||||
|
||||
// TODO: fit into test framework
|
||||
|
||||
@ -49,7 +56,7 @@ public class TestCanonicalIterator extends TestFmwk {
|
||||
CanonicalIterator slowIt = new CanonicalIterator("");
|
||||
slowIt.SKIP_ZEROS = false;
|
||||
*/
|
||||
Transliterator name = Transliterator.getInstance("[^\\u0020-\\u007F] name");
|
||||
//Transliterator name = Transliterator.getInstance("[^\\u0020-\\u007F] name");
|
||||
Set itSet = new TreeSet();
|
||||
Set slowItSet = new TreeSet();
|
||||
|
||||
@ -85,7 +92,7 @@ public class TestCanonicalIterator extends TestFmwk {
|
||||
logln("");
|
||||
lastMixedCounter = mixedCounter;
|
||||
}
|
||||
logln("\t" + mixedCounter + "\t" + name.transliterate(item)
|
||||
logln("\t" + mixedCounter + "\t" + hex(item)
|
||||
+ (item.equals(s) ? "\t(*original*)" : "")
|
||||
+ (item.equals(decomp) ? "\t(*decomp*)" : "")
|
||||
+ (item.equals(comp) ? "\t(*comp*)" : "")
|
||||
@ -237,17 +244,17 @@ public class TestCanonicalIterator extends TestFmwk {
|
||||
}
|
||||
}
|
||||
|
||||
Transliterator name = null;
|
||||
Transliterator hex = null;
|
||||
//Transliterator name = null;
|
||||
//Transliterator hex = null;
|
||||
|
||||
public String getReadable(Object obj) {
|
||||
if (obj == null) return "null";
|
||||
String s = obj.toString();
|
||||
if (s.length() == 0) return "";
|
||||
// set up for readable display
|
||||
if (name == null) name = Transliterator.getInstance("[^\\ -\\u007F] name");
|
||||
if (hex == null) hex = Transliterator.getInstance("[^\\ -\\u007F] hex");
|
||||
return "[" + (SHOW_NAMES ? name.transliterate(s) + "; " : "") + hex.transliterate(s) + "]";
|
||||
//if (name == null) name = Transliterator.getInstance("[^\\ -\\u007F] name");
|
||||
//if (hex == null) hex = Transliterator.getInstance("[^\\ -\\u007F] hex");
|
||||
return "[" + (SHOW_NAMES ? hex(s) + "; " : "") + hex(s) + "]";
|
||||
}
|
||||
|
||||
static String collectionToString(Collection col) {
|
||||
|
@ -4,20 +4,23 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/Attic/ExhaustiveTest.java,v $
|
||||
* $Date: 2002/06/20 01:16:24 $
|
||||
* $Revision: 1.11 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/TestDeprecatedNormalizerAPI.java,v $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.impl.NormalizerImpl;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.text.ComposedCharIter;
|
||||
import com.ibm.icu.text.Normalizer;
|
||||
import com.ibm.icu.text.StringCharacterIterator;
|
||||
|
||||
public class ExhaustiveTest extends TestFmwk
|
||||
public class TestDeprecatedNormalizerAPI extends TestFmwk
|
||||
{
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
@ -40,13 +43,46 @@ public class ExhaustiveTest extends TestFmwk
|
||||
|
||||
|
||||
|
||||
new ExhaustiveTest().run(args);
|
||||
new TestDeprecatedNormalizerAPI().run(args);
|
||||
}
|
||||
|
||||
public ExhaustiveTest() {
|
||||
public TestDeprecatedNormalizerAPI() {
|
||||
}
|
||||
|
||||
|
||||
public void TestNormalizerAPI(){
|
||||
// instantiate a Normalizer from a CharacterIterator
|
||||
String s=Utility.unescape("a\u0308\uac00\\U0002f800");
|
||||
// make s a bit longer and more interesting
|
||||
java.text.CharacterIterator iter = new StringCharacterIterator(s+s);
|
||||
//test deprecated constructors
|
||||
Normalizer norm = new Normalizer(iter, Normalizer.NFC,0);
|
||||
Normalizer norm2 = new Normalizer(s,Normalizer.NFC,0);
|
||||
if(norm.next()!=0xe4) {
|
||||
errln("error in Normalizer(CharacterIterator).next()");
|
||||
}
|
||||
// test clone(), ==, and hashCode()
|
||||
Normalizer clone=(Normalizer)norm.clone();
|
||||
if(clone.getBeginIndex()!= norm.getBeginIndex()){
|
||||
errln("error in Normalizer.getBeginIndex()");
|
||||
}
|
||||
|
||||
if(clone.getEndIndex()!= norm.getEndIndex()){
|
||||
errln("error in Normalizer.getEndIndex()");
|
||||
}
|
||||
// test setOption() and getOption()
|
||||
clone.setOption(0xaa0000, true);
|
||||
clone.setOption(0x20000, false);
|
||||
if(clone.getOption(0x880000) ==0|| clone.getOption(0x20000)==1) {
|
||||
errln("error in Normalizer::setOption() or Normalizer::getOption()");
|
||||
}
|
||||
//test deprecated normalize method
|
||||
Normalizer.normalize(s,Normalizer.NFC,0);
|
||||
//test deprecated compose method
|
||||
Normalizer.compose(s,false,0);
|
||||
//test deprecated decompose method
|
||||
Normalizer.decompose(s,false,0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run through all of the characters returned by a composed-char iterator
|
@ -1,223 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/Attic/UTF16Util.java,v $
|
||||
* $Date: 2002/12/17 07:31:26 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
/**
|
||||
* Utility class for supplementary code point
|
||||
* support. This one is written purely for updating
|
||||
* Normalization sample from the unicode.org site.
|
||||
* If you want the real thing, use UTF16 class
|
||||
* from ICU4J
|
||||
* @author Vladimir Weinstein, Markus Scherer
|
||||
*/
|
||||
public class UTF16Util {
|
||||
static final int suppOffset = (0xd800 << 10) + 0xdc00 - 0x10000;
|
||||
|
||||
/**
|
||||
* Method nextCodePoint. Returns the next code point
|
||||
* in a string.
|
||||
* @param s String in question
|
||||
* @param i index from which we want a code point
|
||||
* @return int codepoint at index i
|
||||
*/
|
||||
static final public int nextCodePoint(String s, int i) {
|
||||
int ch = s.charAt(i);
|
||||
if (0xd800 <= ch && ch <= 0xdbff && ++i < s.length()) {
|
||||
int ch2 = s.charAt(i);
|
||||
if (0xdc00 <= ch2 && ch2 <= 0xdfff) {
|
||||
ch = (ch << 10) + ch2 - suppOffset;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method prevCodePoint. Gets the code point preceding
|
||||
* index i (predecrement).
|
||||
* @param s String in question
|
||||
* @param i index in string
|
||||
* @return int codepoint at index --i
|
||||
*/
|
||||
static final public int prevCodePoint(String s, int i) {
|
||||
int ch = s.charAt(--i);
|
||||
if (0xdc00 <= ch && ch <= 0xdfff && --i >= 0) {
|
||||
int ch2 = s.charAt(i);
|
||||
if (0xd800 <= ch2 && ch2 <= 0xdbff) {
|
||||
ch = (ch2 << 10) + ch - suppOffset;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method nextCodePoint. Returns the next code point
|
||||
* in a string.
|
||||
* @param s StringBuffer in question
|
||||
* @param i index from which we want a code point
|
||||
* @return int codepoint at index i
|
||||
*/
|
||||
static final public int nextCodePoint(StringBuffer s, int i) {
|
||||
int ch = s.charAt(i);
|
||||
if (0xd800 <= ch && ch <= 0xdbff && ++i < s.length()) {
|
||||
int ch2 = s.charAt(i);
|
||||
if (0xdc00 <= ch2 && ch2 <= 0xdfff) {
|
||||
ch = (ch << 10) + ch2 - suppOffset;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method prevCodePoint. Gets the code point preceding
|
||||
* index i (predecrement).
|
||||
* @param s StringBuffer in question
|
||||
* @param i index in string
|
||||
* @return int codepoint at index --i
|
||||
*/
|
||||
static final public int prevCodePoint(StringBuffer s, int i) {
|
||||
int ch = s.charAt(--i);
|
||||
if (0xdc00 <= ch && ch <= 0xdfff && --i >= 0) {
|
||||
int ch2 = s.charAt(i);
|
||||
if (0xd800 <= ch2 && ch2 <= 0xdbff) {
|
||||
ch = (ch2 << 10) + ch - suppOffset;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method codePointLength. Returns the length
|
||||
* in UTF-16 code units of a given code point
|
||||
* @param c code point in question
|
||||
* @return int length in UTF-16 code units. Can be 1 or 2
|
||||
*/
|
||||
static final public int codePointLength(int c) {
|
||||
return c <= 0xffff ? 1 : 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method appendCodePoint. Appends a code point
|
||||
* to a StringBuffer
|
||||
* @param buffer StringBuffer in question
|
||||
* @param ch code point to append
|
||||
*/
|
||||
static final public void appendCodePoint(StringBuffer buffer, int ch) {
|
||||
if (ch <= 0xffff) {
|
||||
buffer.append((char)ch);
|
||||
} else {
|
||||
buffer.append((char)(0xd7c0 + (ch >> 10)));
|
||||
buffer.append((char)(0xdc00 + (ch & 0x3ff)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method insertCodePoint. Inserts a code point in
|
||||
* a StringBuffer
|
||||
* @param buffer StringBuffer in question
|
||||
* @param i index at which we want code point to be inserted
|
||||
* @param ch code point to be inserted
|
||||
*/
|
||||
static final public void insertCodePoint(StringBuffer buffer, int i, int ch) {
|
||||
if (ch <= 0xffff) {
|
||||
buffer.insert(i, (char)ch);
|
||||
} else {
|
||||
buffer.insert(i, (char)(0xd7c0 + (ch >> 10))).insert(i + 1, (char)(0xdc00 + (ch & 0x3ff)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setCodePointAt. Changes a code point at a
|
||||
* given index. Can change the length of the string.
|
||||
* @param buffer StringBuffer in question
|
||||
* @param i index at which we want to change the contents
|
||||
* @param ch replacement code point
|
||||
* @return int difference in resulting StringBuffer length
|
||||
*/
|
||||
static final public int setCodePointAt(StringBuffer buffer, int i, int ch) {
|
||||
int cp = nextCodePoint(buffer, i);
|
||||
|
||||
if (ch <= 0xffff && cp <= 0xffff) { // Both BMP
|
||||
buffer.setCharAt(i, (char)ch);
|
||||
return 0;
|
||||
} else if (ch > 0xffff && cp > 0xffff) { // Both supplementary
|
||||
buffer.setCharAt(i, (char)(0xd7c0 + (ch >> 10)));
|
||||
buffer.setCharAt(i+1, (char)(0xdc00 + (ch & 0x3ff)));
|
||||
return 0;
|
||||
} else if (ch <= 0xffff && cp > 0xffff) { // putting BMP instead of supplementary, buffer shrinks
|
||||
buffer.setCharAt(i, (char)ch);
|
||||
buffer.deleteCharAt(i+1);
|
||||
return -1;
|
||||
} else { //if (ch > 0xffff && cp <= 0xffff) { // putting supplementary instead of BMP, buffer grows
|
||||
buffer.setCharAt(i, (char)(0xd7c0 + (ch >> 10)));
|
||||
buffer.insert(i+1, (char)(0xdc00 + (ch & 0x3ff)));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method countCodePoint. Counts the UTF-32 code points
|
||||
* in a UTF-16 encoded string.
|
||||
* @param source String in question.
|
||||
* @return int number of code points in this string
|
||||
*/
|
||||
static final public int countCodePoint(String source)
|
||||
{
|
||||
int result = 0;
|
||||
char ch;
|
||||
boolean hadLeadSurrogate = false;
|
||||
|
||||
for (int i = 0; i < source.length(); ++ i)
|
||||
{
|
||||
ch = source.charAt(i);
|
||||
if (hadLeadSurrogate && 0xdc00 <= ch && ch <= 0xdfff) {
|
||||
hadLeadSurrogate = false; // count valid trail as zero
|
||||
}
|
||||
else
|
||||
{
|
||||
hadLeadSurrogate = (0xd800 <= ch && ch <= 0xdbff);
|
||||
++ result; // count others as 1
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method countCodePoint. Counts the UTF-32 code points
|
||||
* in a UTF-16 encoded string.
|
||||
* @param source StringBuffer in question.
|
||||
* @return int number of code points in this string
|
||||
*/
|
||||
static final public int countCodePoint(StringBuffer source)
|
||||
{
|
||||
int result = 0;
|
||||
char ch;
|
||||
boolean hadLeadSurrogate = false;
|
||||
|
||||
for (int i = 0; i < source.length(); ++ i)
|
||||
{
|
||||
ch = source.charAt(i);
|
||||
if (hadLeadSurrogate && 0xdc00 <= ch && ch <= 0xdfff) {
|
||||
hadLeadSurrogate = false; // count valid trail as zero
|
||||
}
|
||||
else
|
||||
{
|
||||
hadLeadSurrogate = (0xd800 <= ch && ch <= 0xdbff);
|
||||
++ result; // count others as 1
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -7,15 +7,17 @@
|
||||
* No liability is assumed for incidental and consequential damages
|
||||
* in connection with or arising out of the use of the information here.
|
||||
* @author Mark Davis
|
||||
* Updates for supplementary code points:
|
||||
* Updates for supplementary code points:
|
||||
* Vladimir Weinstein & Markus Scherer
|
||||
*/
|
||||
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
import com.ibm.icu.dev.test.UTF16Util;
|
||||
|
||||
public class UnicodeNormalizer {
|
||||
static final String copyright = "Copyright © 1998-1999 Unicode, Inc.";
|
||||
|
||||
|
||||
/**
|
||||
* Create a normalizer for a given form.
|
||||
*/
|
||||
@ -23,34 +25,34 @@ public class UnicodeNormalizer {
|
||||
this.form = form;
|
||||
if (data == null) data = NormalizerBuilder.build(fullData); // load 1st time
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Masks for the form selector
|
||||
*/
|
||||
static final byte
|
||||
static final byte
|
||||
COMPATIBILITY_MASK = 1,
|
||||
COMPOSITION_MASK = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Normalization Form Selector
|
||||
*/
|
||||
public static final byte
|
||||
D = 0 ,
|
||||
public static final byte
|
||||
D = 0 ,
|
||||
C = COMPOSITION_MASK,
|
||||
KD = COMPATIBILITY_MASK,
|
||||
KC = (byte)(COMPATIBILITY_MASK + COMPOSITION_MASK);
|
||||
|
||||
|
||||
/**
|
||||
* Normalizes text according to the chosen form,
|
||||
* Normalizes text according to the chosen form,
|
||||
* replacing contents of the target buffer.
|
||||
* @param source the original text, unnormalized
|
||||
* @param target the resulting normalized text
|
||||
*/
|
||||
public StringBuffer normalize(String source, StringBuffer target) {
|
||||
|
||||
|
||||
// First decompose the source into target,
|
||||
// then compose if the form requires.
|
||||
|
||||
|
||||
if (source.length() != 0) {
|
||||
internalDecompose(source, target);
|
||||
if ((form & COMPOSITION_MASK) != 0) {
|
||||
@ -68,11 +70,11 @@ public class UnicodeNormalizer {
|
||||
public String normalize(String source) {
|
||||
return normalize(source, new StringBuffer()).toString();
|
||||
}
|
||||
|
||||
|
||||
// ======================================
|
||||
// PRIVATES
|
||||
// ======================================
|
||||
|
||||
|
||||
/**
|
||||
* The current form.
|
||||
*/
|
||||
@ -82,7 +84,7 @@ public class UnicodeNormalizer {
|
||||
* Decomposes text, either canonical or compatibility,
|
||||
* replacing contents of the target buffer.
|
||||
* @param form the normalization form. If COMPATIBILITY_MASK
|
||||
* bit is on in this byte, then selects the recursive
|
||||
* bit is on in this byte, then selects the recursive
|
||||
* compatibility decomposition, otherwise selects
|
||||
* the recursive canonical decomposition.
|
||||
* @param source the original text, unnormalized
|
||||
@ -97,20 +99,20 @@ public class UnicodeNormalizer {
|
||||
ch = UTF16Util.nextCodePoint(source, i);
|
||||
i+=UTF16Util.codePointLength(ch);
|
||||
data.getRecursiveDecomposition(canonical, ch, buffer);
|
||||
|
||||
|
||||
// add all of the characters in the decomposition.
|
||||
// (may be just the original character, if there was
|
||||
// no decomposition mapping)
|
||||
|
||||
|
||||
for (int j = 0; j < buffer.length();) {
|
||||
ch = UTF16Util.nextCodePoint(buffer, j);
|
||||
j+=UTF16Util.codePointLength(ch);
|
||||
int chClass = data.getCanonicalClass(ch);
|
||||
int k = target.length(); // insertion point
|
||||
if (chClass != 0) {
|
||||
|
||||
|
||||
// bubble-sort combining marks as necessary
|
||||
|
||||
|
||||
int ch2;
|
||||
for (; k > 0; k -= UTF16Util.codePointLength(ch2)) {
|
||||
ch2 = UTF16Util.prevCodePoint(target, k);
|
||||
@ -129,15 +131,15 @@ public class UnicodeNormalizer {
|
||||
* output: the resulting normalized text.
|
||||
*/
|
||||
private void internalCompose(StringBuffer target) {
|
||||
|
||||
|
||||
int starterPos = 0;
|
||||
int starterCh = UTF16Util.nextCodePoint(target,0);
|
||||
int compPos = UTF16Util.codePointLength(starterCh);
|
||||
int lastClass = data.getCanonicalClass(starterCh);
|
||||
if (lastClass != 0) lastClass = 256; // fix for irregular combining sequence
|
||||
|
||||
|
||||
// Loop on the decomposed characters, combining where possible
|
||||
|
||||
|
||||
for (int decompPos = UTF16Util.codePointLength(starterCh); decompPos < target.length(); ) {
|
||||
int ch = UTF16Util.nextCodePoint(target, decompPos);
|
||||
decompPos += UTF16Util.codePointLength(ch);
|
||||
@ -162,17 +164,17 @@ public class UnicodeNormalizer {
|
||||
|
||||
/**
|
||||
* Contains normalization data from the Unicode Character Database.
|
||||
* use false for the minimal set, true for the real set.
|
||||
* use false for the minimal set, true for the real set.
|
||||
*/
|
||||
private static NormalizerData data = null;
|
||||
|
||||
|
||||
/**
|
||||
* Just accessible for testing.
|
||||
*/
|
||||
boolean getExcluded (char ch) {
|
||||
return data.getExcluded(ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Just accessible for testing.
|
||||
*/
|
||||
|
@ -5,19 +5,22 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/UnicodeNormalizerConformanceTest.java,v $
|
||||
* $Date: 2002/12/09 22:50:40 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.dev.test.normalizer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import com.ibm.icu.dev.test.TestUtil;
|
||||
import java.io.*;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
|
||||
|
||||
public class UnicodeNormalizerConformanceTest extends TestFmwk {
|
||||
|
||||
|
@ -4,9 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/rbbi/SimpleBITest.java,v $
|
||||
* $Date: 2002/02/16 03:05:16 $
|
||||
* $Revision: 1.6 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/rbbi/SimpleBITest.java,v $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.7 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -100,21 +100,21 @@ public class SimpleBITest extends TestFmwk{
|
||||
+ "statesmayofrightdo.Andforthesupportofthisdeclaration,withafirmrelianceontheprotectionofDivineProvidence,we"
|
||||
+ "mutuallypledgetoeachotherourlives,ourfortunesandoursacredhonor.\n";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SimpleBITest().run(args);
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SimpleBITest().run(args);
|
||||
}
|
||||
|
||||
public void testWordBreak() throws Exception {
|
||||
BreakIterator wordBreak = BreakIterator.getWordInstance(new Locale("en", "US", "TEST"));
|
||||
BreakIterator wordBreak =(BreakIterator) BreakIterator.getWordInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(wordBreak);
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
}
|
||||
|
||||
public void testLineBreak() throws Exception {
|
||||
BreakIterator lineBreak = BreakIterator.getLineInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(lineBreak);
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSentenceBreak() throws Exception {
|
||||
BreakIterator sentenceBreak = BreakIterator.getSentenceInstance(new Locale("en", "US", "TEST"));
|
||||
@ -136,7 +136,7 @@ public class SimpleBITest extends TestFmwk{
|
||||
fragment = testText.substring(lastP, p);
|
||||
} else {
|
||||
fragment = testText.substring(lastP);
|
||||
}
|
||||
}
|
||||
debugPrintln(": >" + fragment + "<");
|
||||
++breaks;
|
||||
lastP = p;
|
||||
|
35
icu4j/src/com/ibm/icu/dev/test/rbbi/TestAll.java
Normal file
35
icu4j/src/com/ibm/icu/dev/test/rbbi/TestAll.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/rbbi/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:34 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.rbbi;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
public void TestRuleBasedBreakIterator() throws Exception {
|
||||
run(new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.rbbi.SimpleBITest(),
|
||||
new com.ibm.icu.dev.test.rbbi.BreakIteratorTest(),
|
||||
new com.ibm.icu.dev.test.rbbi.RBBITest(),
|
||||
new com.ibm.icu.dev.test.rbbi.RBBIAPITest()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
40
icu4j/src/com/ibm/icu/dev/test/translit/TestAll.java
Normal file
40
icu4j/src/com/ibm/icu/dev/test/translit/TestAll.java
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/translit/TestAll.java,v $
|
||||
* $Date: 2003/01/28 18:55:35 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.translit;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
|
||||
new TestAll().run(args);
|
||||
}
|
||||
public void TestTranslit() throws Exception {
|
||||
run( new TestFmwk[] {
|
||||
new com.ibm.icu.dev.test.translit.TransliteratorTest(),
|
||||
new com.ibm.icu.dev.test.translit.UnicodeSetTest(),
|
||||
new com.ibm.icu.dev.test.translit.CompoundTransliteratorTest(),
|
||||
new com.ibm.icu.dev.test.translit.UnicodeToHexTransliteratorTest(),
|
||||
new com.ibm.icu.dev.test.translit.HexToUnicodeTransliteratorTest(),
|
||||
new com.ibm.icu.dev.test.translit.JamoTest(),
|
||||
new com.ibm.icu.dev.test.translit.ErrorTest(),
|
||||
new com.ibm.icu.dev.test.translit.RoundTripTest(),
|
||||
new com.ibm.icu.dev.test.translit.ReplaceableTest()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/translit/TransliteratorTest.java,v $
|
||||
* $Date: 2002/09/09 16:33:43 $
|
||||
* $Revision: 1.117 $
|
||||
* $Date: 2003/01/28 18:55:35 $
|
||||
* $Revision: 1.118 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -15,6 +15,7 @@ import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.impl.UtilityExtensions;
|
||||
import com.ibm.icu.util.CaseInsensitiveString;
|
||||
import java.util.*;
|
||||
|
||||
@ -332,7 +333,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
log = new StringBuffer(s.toString() + " => ");
|
||||
t.finishTransliteration(s, index);
|
||||
}
|
||||
Utility.formatInput(log, s, index);
|
||||
UtilityExtensions.formatInput(log, s, index);
|
||||
if (s.toString().equals(DATA[i+1])) {
|
||||
logln(log.toString());
|
||||
} else {
|
||||
@ -839,7 +840,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
|
||||
// round trip
|
||||
Transliterator t = Transliterator.getInstance("Any-Name;Name-Any");
|
||||
|
||||
|
||||
String s = "{\u00A0abc\u4E01\\N{x\u00B5\u0A81\uFFFD\u0004\u0009\u0081\uFFFF\u0004\\N{";
|
||||
expect(t, s, s);
|
||||
}
|
||||
@ -915,8 +916,8 @@ public class TransliteratorTest extends TestFmwk {
|
||||
{"\u212b", "A\u030a", "\u00c5" }, // angstrom_sign
|
||||
{"\u00c5", "A\u030a", "\u00c5" }, // A-ring
|
||||
|
||||
{"\u00fdffin", "y\u0301ffin", "\u00fdffin" }, //updated with 3.0
|
||||
{"\u00fd\uFB03n", "y\u0301\uFB03n", "\u00fd\uFB03n" }, //updated with 3.0
|
||||
{"\u00fdffin", "y\u0301ffin", "\u00fdffin" }, //updated with 3.0
|
||||
{"\u00fd\uFB03n", "y\u0301\uFB03n", "\u00fd\uFB03n" }, //updated with 3.0
|
||||
|
||||
{"Henry IV", "Henry IV", "Henry IV" },
|
||||
{"Henry \u2163", "Henry \u2163", "Henry \u2163" },
|
||||
@ -934,7 +935,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
// Input Decomposed Composed
|
||||
{"\uFB4f", "\u05D0\u05DC", "\u05D0\u05DC" }, // Alef-Lamed vs. Alef, Lamed
|
||||
|
||||
{"\u00fdffin", "y\u0301ffin", "\u00fdffin" }, //updated for 3.0
|
||||
{"\u00fdffin", "y\u0301ffin", "\u00fdffin" }, //updated for 3.0
|
||||
{"\u00fd\uFB03n", "y\u0301ffin", "\u00fdffin" }, // ffi ligature -> f + f + i
|
||||
|
||||
{"Henry IV", "Henry IV", "Henry IV" },
|
||||
@ -1155,7 +1156,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
"$iotasub = \\u0345 ;"+
|
||||
"($evowel $macron $accentMinus *) i > | $1 $iotasub ;",
|
||||
"([AEIOUYaeiouy]\\u0304[[\\u0300-\\u0345]&[:M:]-[\\u0338]]*)i > | $1 \\u0345;",
|
||||
|
||||
|
||||
RBT,
|
||||
"([AEIOUYaeiouy]\\u0304[[:M:]-[\\u0304\\u0345]]*)i > | $1 \\u0345;",
|
||||
"([AEIOUYaeiouy]\\u0304[[:M:]-[\\u0304\\u0345]]*)i > | $1 \\u0345;",
|
||||
@ -1266,7 +1267,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
expect(Transliterator.getInstance("Any-Hex/Unicode"),
|
||||
CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"),
|
||||
"U+10330U+10FF00U+E0061U+00A0");
|
||||
|
||||
|
||||
expect(Transliterator.getInstance("Any-Hex/C"),
|
||||
CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"),
|
||||
"\\U00010330\\U0010FF00\\U000E0061\\u00A0");
|
||||
@ -1819,10 +1820,10 @@ public class TransliteratorTest extends TestFmwk {
|
||||
public void TestTeluguLatinRT(){
|
||||
String[] source = {
|
||||
"raghur\u0101m vi\u015Bvan\u0101dha", /* Raghuram Viswanadha */
|
||||
"\u0101nand vaddir\u0101ju", /* Anand Vaddiraju */
|
||||
"\u0101nand vaddir\u0101ju", /* Anand Vaddiraju */
|
||||
"r\u0101j\u012Bv ka\u015Barab\u0101da", /* Rajeev Kasarabada */
|
||||
"san\u0304j\u012Bv ka\u015Barab\u0101da", /* sanjeev kasarabada */
|
||||
"san\u0304j\u012Bb sen'gupta", /* sanjib sengupata */
|
||||
"san\u0304j\u012Bb sen'gupta", /* sanjib sengupata */
|
||||
"amar\u0113ndra hanum\u0101nula", /* Amarendra hanumanula */
|
||||
"ravi kum\u0101r vi\u015Bvan\u0101dha", /* Ravi Kumar Viswanadha */
|
||||
"\u0101ditya kandr\u0113gula", /* Aditya Kandregula */
|
||||
@ -1971,7 +1972,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
expect.setCharAt(0,(char) (vIter.codepoint+0x0100));
|
||||
expect(trans,src.toString(),expect.toString());
|
||||
}
|
||||
|
||||
|
||||
expect.setCharAt(1,'\u0A70');
|
||||
while(nvIter.next()){
|
||||
//src.setCharAt(0,(char) nvIter.codepoint);
|
||||
@ -2275,6 +2276,56 @@ public class TransliteratorTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test is not in trnstst.cpp. This test has been moved from com/ibm/icu/dev/test/lang/TestUScript.java
|
||||
* during ICU4J modularization to remove dependency of tests on Transliterator.
|
||||
*/
|
||||
public void TestScriptAllCodepoints(){
|
||||
int code;
|
||||
String oldId="";
|
||||
String oldAbbrId="";
|
||||
for( int i =0; i <= 0x10ffff; i++){
|
||||
code =UScript.INVALID_CODE;
|
||||
code = UScript.getScript(i);
|
||||
if(code==UScript.INVALID_CODE){
|
||||
errln("UScript.getScript for codepoint 0x"+ hex(i)+" failed");
|
||||
}
|
||||
String id =UScript.getName(code);
|
||||
String abbr = UScript.getShortName(code);
|
||||
String newId ="[:"+id+":];NFD";
|
||||
String newAbbrId ="[:"+abbr+":];NFD";
|
||||
if(!oldId.equals(newId)){
|
||||
try{
|
||||
Transliterator t = Transliterator.getInstance(newId);
|
||||
if(t==null){
|
||||
errln("Failed to create transliterator for "+hex(i)+
|
||||
" script code: " +id);
|
||||
}
|
||||
}catch(Exception e){
|
||||
errln("Failed to create transliterator for "+hex(i)
|
||||
+" script code: " +id
|
||||
+ " Exception: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
oldId = newId;
|
||||
if(!oldAbbrId.equals(newAbbrId)){
|
||||
try{
|
||||
Transliterator t = Transliterator.getInstance(newAbbrId);
|
||||
if(t==null){
|
||||
errln("Failed to create transliterator for "+hex(i)+
|
||||
" script code: " +abbr);
|
||||
}
|
||||
}catch(Exception e){
|
||||
errln("Failed to create transliterator for "+hex(i)
|
||||
+" script code: " +abbr
|
||||
+ " Exception: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
oldAbbrId = newAbbrId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static final String[][] registerRules = {
|
||||
{"Any-Dev1", "x > X; y > Y;"},
|
||||
{"Any-Dev2", "XY > Z"},
|
||||
@ -2311,12 +2362,12 @@ public class TransliteratorTest extends TestFmwk {
|
||||
//TODO: enable this test once Titlecase works right
|
||||
//{"Title", "\uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
// "Ffi\u0131ii \u01C8\u01C9\u01C9 " + DESERET_DEE + DESERET_dee},
|
||||
|
||||
|
||||
{"Upper", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
"AB'CD FFIII\u0130 \u01C7\u01C7\u01C7 " + DESERET_DEE + DESERET_DEE},
|
||||
{"Lower", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
"ab'cd \uFB00i\u0131ii\u0307 \u01C9\u01C9\u01C9 " + DESERET_dee + DESERET_dee},
|
||||
|
||||
|
||||
{"Upper", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE},
|
||||
{"Lower", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE},
|
||||
|
||||
@ -2336,7 +2387,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
};
|
||||
|
||||
public void TestSpecialCases() {
|
||||
|
||||
|
||||
for (int i = 0; i < registerRules.length; ++i) {
|
||||
Transliterator t = Transliterator.createFromRules(registerRules[i][0],
|
||||
registerRules[i][1], Transliterator.FORWARD);
|
||||
@ -2350,7 +2401,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
String target = null;
|
||||
|
||||
// Automatic generation of targets, to make it simpler to add test cases (and more fail-safe)
|
||||
|
||||
|
||||
if (testCases[i].length > 2) target = testCases[i][2];
|
||||
else if (id.equalsIgnoreCase("NFD")) target = com.ibm.icu.text.Normalizer.normalize(source, com.ibm.icu.text.Normalizer.NFD);
|
||||
else if (id.equalsIgnoreCase("NFC")) target = com.ibm.icu.text.Normalizer.normalize(source, com.ibm.icu.text.Normalizer.NFC);
|
||||
@ -2459,14 +2510,14 @@ public class TransliteratorTest extends TestFmwk {
|
||||
// we have a few special cases. Any-Remove (pos.start = 0, but also = limit) and U+XXXXX?X?
|
||||
|
||||
if (pos.start == 0 && pos.limit != 0 && !t.getID().equals("Hex-Any/Unicode")) {
|
||||
errln("No Progress, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
errln("No Progress, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
|
||||
gotError = true;
|
||||
} else {
|
||||
logln("PASS Progress, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
logln("PASS Progress, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
|
||||
}
|
||||
t.finishTransliteration(test, pos);
|
||||
if (pos.start != pos.limit) {
|
||||
errln("Incomplete, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
errln("Incomplete, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
|
||||
gotError = true;
|
||||
}
|
||||
}
|
||||
@ -2491,7 +2542,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
errln("FAIL: toRules() => " + r +
|
||||
", expected " + rule);
|
||||
}
|
||||
|
||||
|
||||
expect(t, "The Quick Brown Fox",
|
||||
"T(t=\\u0074)he Q(q=\\u0071)uick B(b=\\u0062)rown F(f=\\u0066)ox");
|
||||
rule =
|
||||
@ -2510,7 +2561,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
errln("FAIL: toRules() => " + r +
|
||||
", expected " + rule);
|
||||
}
|
||||
|
||||
|
||||
expect(t, "\u0301",
|
||||
"U+0301 \\N{COMBINING ACUTE ACCENT}");
|
||||
}
|
||||
@ -2523,14 +2574,14 @@ public class TransliteratorTest extends TestFmwk {
|
||||
if (t != null) {
|
||||
errln("FAIL: createFromRules should have returned NULL");
|
||||
}
|
||||
errln("FAIL: Ok: . > $1; => no error");
|
||||
Transliterator t2= Transliterator.createFromRules("Test2", rule2, Transliterator.FORWARD);
|
||||
errln("FAIL: Ok: . > $1; => no error");
|
||||
Transliterator t2= Transliterator.createFromRules("Test2", rule2, Transliterator.FORWARD);
|
||||
if (t2 != null) {
|
||||
errln("FAIL: createFromRules should have returned NULL");
|
||||
}
|
||||
errln("FAIL: Ok: . > $1; => no error");
|
||||
} catch (IllegalArgumentException e) {
|
||||
logln("Ok: . > $1; => " + e.getMessage());
|
||||
errln("FAIL: Ok: . > $1; => no error");
|
||||
} catch (IllegalArgumentException e) {
|
||||
logln("Ok: . > $1; => " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2542,13 +2593,13 @@ public class TransliteratorTest extends TestFmwk {
|
||||
" [b{bc}] > z;" +
|
||||
"[{gd}] { e > q;" +
|
||||
" e } [{fg}] > r;" ;
|
||||
|
||||
|
||||
Transliterator t = Transliterator.createFromRules("Test", rule, Transliterator.FORWARD);
|
||||
if (t == null) {
|
||||
errln("FAIL: createFromRules failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
expect(t, "a aa ab bc d gd de gde gdefg ddefg",
|
||||
"y x yz z d gd de gdq gdqfg ddrfg");
|
||||
|
||||
@ -2559,13 +2610,13 @@ public class TransliteratorTest extends TestFmwk {
|
||||
" b > y;" +
|
||||
" c > z;" +
|
||||
" q [t {st} {rst}] { e > p;" ;
|
||||
|
||||
|
||||
t = Transliterator.createFromRules("Test", rule, Transliterator.FORWARD);
|
||||
if (t == null) {
|
||||
errln("FAIL: createFromRules failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
expect(t, "a ab abc qte qste qrste",
|
||||
"x x x qtp qstp qrstp");
|
||||
}
|
||||
@ -2624,7 +2675,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
public Transliterator getInstance(String ID) {
|
||||
return (Transliterator) m.get(new CaseInsensitiveString(ID));
|
||||
}
|
||||
|
||||
|
||||
static void unregister() {
|
||||
Iterator ids = m.keySet().iterator();
|
||||
while (ids.hasNext()) {
|
||||
@ -2641,7 +2692,7 @@ public class TransliteratorTest extends TestFmwk {
|
||||
public void TestAnyX() {
|
||||
Transliterator anyLatin =
|
||||
Transliterator.getInstance("Any-Latin", Transliterator.FORWARD);
|
||||
|
||||
|
||||
expect(anyLatin,
|
||||
"greek:\u03B1\u03B2\u03BA\u0391\u0392\u039A hiragana:\u3042\u3076\u304F cyrillic:\u0430\u0431\u0446",
|
||||
"greek:abkABK hiragana:abuku cyrillic:abc");
|
||||
@ -2781,16 +2832,16 @@ public class TransliteratorTest extends TestFmwk {
|
||||
rsource.replace(0, rsource.length(), "");
|
||||
if (pos != null) {
|
||||
rsource.replace(0, 0, source);
|
||||
v.add(Utility.formatInput(rsource, index));
|
||||
v.add(UtilityExtensions.formatInput(rsource, index));
|
||||
t.transliterate(rsource, index);
|
||||
v.add(Utility.formatInput(rsource, index));
|
||||
v.add(UtilityExtensions.formatInput(rsource, index));
|
||||
} else {
|
||||
for (int i=0; i<source.length(); ++i) {
|
||||
//v.add(i == 0 ? "" : " + " + source.charAt(i) + "");
|
||||
//log.append(source.charAt(i)).append(" -> "));
|
||||
t.transliterate(rsource, index, source.charAt(i));
|
||||
//v.add(Utility.formatInput(rsource, index) + source.substring(i+1));
|
||||
v.add(Utility.formatInput(rsource, index) +
|
||||
//v.add(UtilityExtensions.formatInput(rsource, index) + source.substring(i+1));
|
||||
v.add(UtilityExtensions.formatInput(rsource, index) +
|
||||
((i<source.length()-1)?(" + '" + source.charAt(i+1) + "' ->"):" =>"));
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceTest.java,v $
|
||||
* $Date: 2002/12/12 18:02:09 $
|
||||
* $Revision: 1.10 $
|
||||
* $Date: 2003/01/28 18:55:35 $
|
||||
* $Revision: 1.11 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -26,6 +26,7 @@ import com.ibm.icu.impl.ICULocaleService;
|
||||
import com.ibm.icu.impl.ICULocaleService.LocaleKey;
|
||||
import com.ibm.icu.impl.ICULocaleService.LocaleKeyFactory;
|
||||
import com.ibm.icu.impl.ICULocaleService.ICUResourceBundleFactory;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -69,6 +70,36 @@ public class ICUServiceTest extends TestFmwk
|
||||
public void confirmIdentical(String message, int lhs, int rhs) {
|
||||
logln(message + " lhs: " + lhs + " rhs: " + rhs, lhs == rhs);
|
||||
}
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the current default Locale as the locale, the default collator for
|
||||
* the locale as the comparator to sort the display names, and null for
|
||||
* the matchID.
|
||||
*/
|
||||
public SortedMap getDisplayNames(ICUService service) {
|
||||
Locale locale = Locale.getDefault();
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return service.getDisplayNames(locale, col, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names, and null for the matchID.
|
||||
*/
|
||||
public SortedMap getDisplayNames(ICUService service, Locale locale) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return service.getDisplayNames(locale, col, null);
|
||||
}
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names.
|
||||
*/
|
||||
public SortedMap getDisplayNames(ICUService service, Locale locale, String matchID) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return service.getDisplayNames(locale, col, matchID);
|
||||
}
|
||||
|
||||
// use locale keys
|
||||
static final class TestService extends ICUService {
|
||||
@ -236,7 +267,7 @@ public class ICUServiceTest extends TestFmwk
|
||||
|
||||
// iterate over the display names
|
||||
{
|
||||
Map dids = service.getDisplayNames(Locale.GERMANY);
|
||||
Map dids = getDisplayNames(service,Locale.GERMANY);
|
||||
Iterator iter = dids.entrySet().iterator();
|
||||
int count = 0;
|
||||
while (iter.hasNext()) {
|
||||
@ -267,7 +298,7 @@ public class ICUServiceTest extends TestFmwk
|
||||
// this time, we have seven display names
|
||||
// Rad dude's surfer gal 'replaces' later's surfer gal
|
||||
{
|
||||
Map dids = service.getDisplayNames();
|
||||
Map dids = getDisplayNames(service);
|
||||
Iterator iter = dids.entrySet().iterator();
|
||||
int count = 0;
|
||||
while (iter.hasNext()) {
|
||||
@ -389,7 +420,7 @@ public class ICUServiceTest extends TestFmwk
|
||||
// list only the spanish display names for es, spanish collation order
|
||||
// since we're using the default Key, only "es" is matched
|
||||
{
|
||||
logln("display names: " + service.getDisplayNames(LocaleUtility.getLocaleFromName("es"), "es"));
|
||||
logln("display names: " + getDisplayNames(service,LocaleUtility.getLocaleFromName("es"), "es"));
|
||||
}
|
||||
|
||||
// list the display names in reverse order
|
||||
@ -406,7 +437,7 @@ public class ICUServiceTest extends TestFmwk
|
||||
// this should be fast since the display names were cached.
|
||||
{
|
||||
logln("service display names for de_DE");
|
||||
Map names = service.getDisplayNames(LocaleUtility.getLocaleFromName("de_DE"));
|
||||
Map names = getDisplayNames(service,LocaleUtility.getLocaleFromName("de_DE"));
|
||||
StringBuffer buf = new StringBuffer("{");
|
||||
Iterator iter = names.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
@ -431,7 +462,7 @@ public class ICUServiceTest extends TestFmwk
|
||||
for (int i = 0; i < idNames.length; ++i) {
|
||||
String idName = idNames[i];
|
||||
buf.append("\n --- " + idName + " ---");
|
||||
Map names = service.getDisplayNames(LocaleUtility.getLocaleFromName(idName));
|
||||
Map names = getDisplayNames(service,LocaleUtility.getLocaleFromName(idName));
|
||||
Iterator iter = names.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry e = (Entry)iter.next();
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceTestSample.java,v $
|
||||
* $Date: 2002/08/13 22:10:20 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2003/01/28 18:55:35 $
|
||||
* $Revision: 1.3 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -15,12 +15,15 @@ package com.ibm.icu.dev.test.util;
|
||||
import com.ibm.icu.impl.ICULocaleService;
|
||||
import com.ibm.icu.impl.ICUService;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
import java.util.EventListener;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class ICUServiceTestSample {
|
||||
static public void main(String[] args) {
|
||||
@ -47,6 +50,7 @@ public class ICUServiceTestSample {
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This will be called in the notification thread of
|
||||
* ICUNotifier. ICUNotifier could spawn a (non-daemon) thread
|
||||
@ -110,101 +114,110 @@ public class ICUServiceTestSample {
|
||||
* notification. The service just implements 'hello'.
|
||||
*/
|
||||
static final class HelloService {
|
||||
private static ICUService registry;
|
||||
private String name;
|
||||
|
||||
private HelloService(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hello service...
|
||||
*/
|
||||
public String hello() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ": " + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deferred init.
|
||||
*/
|
||||
private static ICUService registry() {
|
||||
if (registry == null) {
|
||||
initRegistry();
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
|
||||
private static void initRegistry() {
|
||||
registry = new ICULocaleService() {
|
||||
protected boolean acceptsListener(EventListener l) {
|
||||
return true; // we already verify in our wrapper APIs
|
||||
}
|
||||
protected void notifyListener(EventListener l) {
|
||||
((HelloServiceListener)l).helloServiceChanged();
|
||||
}
|
||||
};
|
||||
|
||||
// initialize
|
||||
doRegister("Hello", "en");
|
||||
doRegister("Bonjour", "fr");
|
||||
doRegister("Ni Hao", "zh_CN");
|
||||
doRegister("Guten Tag", "de");
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom listener for changes to this service. We don't need to
|
||||
* point to the service since it is defined by this class and not
|
||||
* an object.
|
||||
*/
|
||||
public static interface HelloServiceListener extends EventListener {
|
||||
public void helloServiceChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe notification for this service.
|
||||
*/
|
||||
public static void addListener(HelloServiceListener l) {
|
||||
registry().addListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe notification for this service.
|
||||
*/
|
||||
public static void removeListener(HelloServiceListener l) {
|
||||
registry().removeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe access to the service.
|
||||
*/
|
||||
public static HelloService get(String id) {
|
||||
return (HelloService)registry().get(id);
|
||||
}
|
||||
|
||||
public static Set getVisibleIDs() {
|
||||
return registry().getVisibleIDs();
|
||||
}
|
||||
|
||||
public static Map getDisplayNames(Locale locale) {
|
||||
return registry().getDisplayNames(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new hello string for this locale.
|
||||
*/
|
||||
public static void register(String helloString, Locale locale) {
|
||||
if (helloString == null || locale == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
doRegister(helloString, LocaleUtility.canonicalLocaleString(locale.toString()));
|
||||
}
|
||||
|
||||
private static void doRegister(String hello, String id) {
|
||||
registry().registerObject(new HelloService(hello), id);
|
||||
}
|
||||
private static ICUService registry;
|
||||
private String name;
|
||||
|
||||
private HelloService(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hello service...
|
||||
*/
|
||||
public String hello() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ": " + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deferred init.
|
||||
*/
|
||||
private static ICUService registry() {
|
||||
if (registry == null) {
|
||||
initRegistry();
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
|
||||
private static void initRegistry() {
|
||||
registry = new ICULocaleService() {
|
||||
protected boolean acceptsListener(EventListener l) {
|
||||
return true; // we already verify in our wrapper APIs
|
||||
}
|
||||
protected void notifyListener(EventListener l) {
|
||||
((HelloServiceListener)l).helloServiceChanged();
|
||||
}
|
||||
};
|
||||
|
||||
// initialize
|
||||
doRegister("Hello", "en");
|
||||
doRegister("Bonjour", "fr");
|
||||
doRegister("Ni Hao", "zh_CN");
|
||||
doRegister("Guten Tag", "de");
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom listener for changes to this service. We don't need to
|
||||
* point to the service since it is defined by this class and not
|
||||
* an object.
|
||||
*/
|
||||
public static interface HelloServiceListener extends EventListener {
|
||||
public void helloServiceChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe notification for this service.
|
||||
*/
|
||||
public static void addListener(HelloServiceListener l) {
|
||||
registry().addListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe notification for this service.
|
||||
*/
|
||||
public static void removeListener(HelloServiceListener l) {
|
||||
registry().removeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-safe access to the service.
|
||||
*/
|
||||
public static HelloService get(String id) {
|
||||
return (HelloService)registry().get(id);
|
||||
}
|
||||
|
||||
public static Set getVisibleIDs() {
|
||||
return registry().getVisibleIDs();
|
||||
}
|
||||
|
||||
public static Map getDisplayNames(Locale locale) {
|
||||
return getDisplayNames(registry(),locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new hello string for this locale.
|
||||
*/
|
||||
public static void register(String helloString, Locale locale) {
|
||||
if (helloString == null || locale == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
doRegister(helloString, LocaleUtility.canonicalLocaleString(locale.toString()));
|
||||
}
|
||||
|
||||
private static void doRegister(String hello, String id) {
|
||||
registry().registerObject(new HelloService(hello), id);
|
||||
}
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names, and null for the matchID.
|
||||
*/
|
||||
public static SortedMap getDisplayNames(ICUService service, Locale locale) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return service.getDisplayNames(locale, col, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java,v $
|
||||
* $Date: 2002/10/02 20:20:25 $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2003/01/28 18:55:35 $
|
||||
* $Revision: 1.6 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -23,6 +23,8 @@ import com.ibm.icu.impl.ICULocaleData;
|
||||
import com.ibm.icu.impl.ICULocaleService;
|
||||
import com.ibm.icu.impl.ICULocaleService.LocaleKey;
|
||||
import com.ibm.icu.impl.ICULocaleService.ICUResourceBundleFactory;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -37,6 +39,7 @@ import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public class ICUServiceThreadTest extends TestFmwk
|
||||
{
|
||||
@ -83,7 +86,15 @@ public class ICUServiceThreadTest extends TestFmwk
|
||||
return "Factory_" + id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names, and null for the matchID.
|
||||
*/
|
||||
public static SortedMap getDisplayNames(ICUService service, Locale locale) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return service.getDisplayNames(locale, col, null);
|
||||
}
|
||||
private static final Random r = new Random();
|
||||
|
||||
private static String getCLV() {
|
||||
@ -178,6 +189,17 @@ public class ICUServiceThreadTest extends TestFmwk
|
||||
log.errln(name + msg);
|
||||
}
|
||||
}
|
||||
public void info(String msg) {
|
||||
if (logging()) {
|
||||
log.info(name + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void infoln(String msg) {
|
||||
if (logging()) {
|
||||
log.infoln(name + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class RegisterFactoryThread extends TestThread {
|
||||
@ -263,7 +285,7 @@ public class ICUServiceThreadTest extends TestFmwk
|
||||
}
|
||||
|
||||
protected void iterate() {
|
||||
Map names = service.getDisplayNames(locale);
|
||||
Map names = getDisplayNames(service,locale);
|
||||
Iterator iter = names.entrySet().iterator();
|
||||
int n = 10;
|
||||
while (--n >= 0 && iter.hasNext()) {
|
||||
|
@ -5,14 +5,14 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICUListResourceBundle.java,v $
|
||||
* $Date: 2002/08/13 23:40:52 $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2003/01/28 18:55:37 $
|
||||
* $Revision: 1.10 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* A list resource bundle that does redirection
|
||||
* A list resource bundle that does redirection
|
||||
* because otherwise some of our resource class files
|
||||
* are too big for the java runtime to handle.
|
||||
*/
|
||||
@ -34,7 +34,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
private static final String ICU_BUNDLE_NAME = "LocaleElements";
|
||||
private static final String ICU_PACKAGE_NAME ="com.ibm.icu.impl.data";
|
||||
private static final String ENCODING="UTF-8";
|
||||
|
||||
|
||||
protected ICUListResourceBundle() {
|
||||
}
|
||||
|
||||
@ -53,22 +53,22 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
* See base class description
|
||||
*/
|
||||
protected Object[][] getContents(){
|
||||
// we replace any redirected values with real values in a cloned array
|
||||
|
||||
if (realContents == null) {
|
||||
realContents = contents;
|
||||
for (int i = 0; i < contents.length; ++i) {
|
||||
Object newValue = getRedirectedResource((String)contents[i][0],contents[i][1]);
|
||||
if (newValue != null) {
|
||||
if (realContents == contents) {
|
||||
realContents = (Object[][])contents.clone();
|
||||
}
|
||||
realContents[i] = new Object[] { contents[i][0], newValue };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return realContents;
|
||||
// we replace any redirected values with real values in a cloned array
|
||||
|
||||
if (realContents == null) {
|
||||
realContents = contents;
|
||||
for (int i = 0; i < contents.length; ++i) {
|
||||
Object newValue = getRedirectedResource((String)contents[i][0],contents[i][1]);
|
||||
if (newValue != null) {
|
||||
if (realContents == contents) {
|
||||
realContents = (Object[][])contents.clone();
|
||||
}
|
||||
realContents[i] = new Object[] { contents[i][0], newValue };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return realContents;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,9 +76,9 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
* real value and return it.
|
||||
*/
|
||||
private Object getRedirectedResource(String key, Object value) {
|
||||
|
||||
if (value instanceof Object[][]) {
|
||||
Object[][] aValue = (Object[][])value;
|
||||
|
||||
if (value instanceof Object[][]) {
|
||||
Object[][] aValue = (Object[][])value;
|
||||
int i=0;
|
||||
while(i < aValue.length){
|
||||
int j=0;
|
||||
@ -87,91 +87,91 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}else if(value instanceof Alias){
|
||||
}
|
||||
}else if(value instanceof Alias){
|
||||
String cName = this.getClass().getName();
|
||||
visited.clear();
|
||||
visited.put(cName+key,"");
|
||||
visited.put(cName+key,"");
|
||||
return ((Alias)value).getResource(cName,key,visited);
|
||||
}else if(value instanceof RedirectedResource){
|
||||
return ((RedirectedResource)value).getResource(this);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static byte[] readToEOS(InputStream stream) {
|
||||
|
||||
ArrayList vec = new ArrayList();
|
||||
int count = 0;
|
||||
int pos = 0;
|
||||
final int MAXLENGTH = 0x8000; // max buffer size - 32K
|
||||
int length = 0x80; // start with small buffers and work up
|
||||
do {
|
||||
pos = 0;
|
||||
length = length >= MAXLENGTH ? MAXLENGTH : length * 2;
|
||||
byte[] buffer = new byte[length];
|
||||
try {
|
||||
do {
|
||||
int n = stream.read(buffer, pos, length - pos);
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
pos += n;
|
||||
} while (pos < length);
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
vec.add(buffer);
|
||||
count += pos;
|
||||
} while (pos == length);
|
||||
|
||||
|
||||
byte[] data = new byte[count];
|
||||
pos = 0;
|
||||
for (int i = 0; i < vec.size(); ++i) {
|
||||
byte[] buf = (byte[])vec.get(i);
|
||||
int len = Math.min(buf.length, count - pos);
|
||||
System.arraycopy(buf, 0, data, pos, len);
|
||||
pos += len;
|
||||
}
|
||||
return data;
|
||||
ArrayList vec = new ArrayList();
|
||||
int count = 0;
|
||||
int pos = 0;
|
||||
final int MAXLENGTH = 0x8000; // max buffer size - 32K
|
||||
int length = 0x80; // start with small buffers and work up
|
||||
do {
|
||||
pos = 0;
|
||||
length = length >= MAXLENGTH ? MAXLENGTH : length * 2;
|
||||
byte[] buffer = new byte[length];
|
||||
try {
|
||||
do {
|
||||
int n = stream.read(buffer, pos, length - pos);
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
pos += n;
|
||||
} while (pos < length);
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
vec.add(buffer);
|
||||
count += pos;
|
||||
} while (pos == length);
|
||||
|
||||
|
||||
byte[] data = new byte[count];
|
||||
pos = 0;
|
||||
for (int i = 0; i < vec.size(); ++i) {
|
||||
byte[] buf = (byte[])vec.get(i);
|
||||
int len = Math.min(buf.length, count - pos);
|
||||
System.arraycopy(buf, 0, data, pos, len);
|
||||
pos += len;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static char[] readToEOS(InputStreamReader stream) {
|
||||
ArrayList vec = new ArrayList();
|
||||
int count = 0;
|
||||
int pos = 0;
|
||||
final int MAXLENGTH = 0x8000; // max buffer size - 32K
|
||||
int length = 0x80; // start with small buffers and work up
|
||||
do {
|
||||
pos = 0;
|
||||
length = length >= MAXLENGTH ? MAXLENGTH : length * 2;
|
||||
char[] buffer = new char[length];
|
||||
try {
|
||||
do {
|
||||
int n = stream.read(buffer, pos, length - pos);
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
pos += n;
|
||||
} while (pos < length);
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
vec.add(buffer);
|
||||
count += pos;
|
||||
} while (pos == length);
|
||||
|
||||
char[] data = new char[count];
|
||||
pos = 0;
|
||||
for (int i = 0; i < vec.size(); ++i) {
|
||||
char[] buf = (char[])vec.get(i);
|
||||
int len = Math.min(buf.length, count - pos);
|
||||
System.arraycopy(buf, 0, data, pos, len);
|
||||
pos += len;
|
||||
}
|
||||
return data;
|
||||
ArrayList vec = new ArrayList();
|
||||
int count = 0;
|
||||
int pos = 0;
|
||||
final int MAXLENGTH = 0x8000; // max buffer size - 32K
|
||||
int length = 0x80; // start with small buffers and work up
|
||||
do {
|
||||
pos = 0;
|
||||
length = length >= MAXLENGTH ? MAXLENGTH : length * 2;
|
||||
char[] buffer = new char[length];
|
||||
try {
|
||||
do {
|
||||
int n = stream.read(buffer, pos, length - pos);
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
pos += n;
|
||||
} while (pos < length);
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
vec.add(buffer);
|
||||
count += pos;
|
||||
} while (pos == length);
|
||||
|
||||
char[] data = new char[count];
|
||||
pos = 0;
|
||||
for (int i = 0; i < vec.size(); ++i) {
|
||||
char[] buf = (char[])vec.get(i);
|
||||
int len = Math.min(buf.length, count - pos);
|
||||
System.arraycopy(buf, 0, data, pos, len);
|
||||
pos += len;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/*
|
||||
public static class CompressedString implements RedirectedResource{
|
||||
@ -201,18 +201,18 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
if(compressed==null){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if(expanded==null){
|
||||
expanded= Utility.RLEStringToByteArray(compressed);
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private interface RedirectedResource{
|
||||
public Object getResource(Object obj);
|
||||
}
|
||||
|
||||
|
||||
public static class ResourceBinary implements RedirectedResource{
|
||||
private byte[] expanded=null;
|
||||
private String resName=null;
|
||||
@ -221,16 +221,18 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
}
|
||||
public Object getResource(Object obj){
|
||||
if(expanded==null){
|
||||
InputStream stream = obj.getClass().getResourceAsStream(resName);
|
||||
if(stream==null){
|
||||
throw new MissingResourceException("",obj.getClass().getName(),resName);
|
||||
InputStream stream = obj.getClass().getResourceAsStream(resName);
|
||||
if(stream!=null){
|
||||
//throw new MissingResourceException("",obj.getClass().getName(),resName);
|
||||
expanded = readToEOS(stream);
|
||||
return expanded;
|
||||
}
|
||||
expanded = readToEOS(stream);
|
||||
|
||||
}
|
||||
return expanded;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ResourceString implements RedirectedResource{
|
||||
private char[] expanded=null;
|
||||
private String resName=null;
|
||||
@ -241,32 +243,34 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
if(expanded==null){
|
||||
// Resource strings are always UTF-8
|
||||
InputStream stream = obj.getClass().getResourceAsStream(resName);
|
||||
if(stream==null){
|
||||
throw new MissingResourceException("",obj.getClass().getName(),resName);
|
||||
if(stream!=null){
|
||||
//throw new MissingResourceException("",obj.getClass().getName(),resName);
|
||||
|
||||
try{
|
||||
InputStreamReader reader = new InputStreamReader(stream,ENCODING);
|
||||
expanded = readToEOS(reader);
|
||||
}catch(UnsupportedEncodingException ex){
|
||||
throw new RuntimeException("Could open converter for encoding: " +ENCODING);
|
||||
}
|
||||
return new String(expanded);
|
||||
}
|
||||
try{
|
||||
InputStreamReader reader = new InputStreamReader(stream,ENCODING);
|
||||
expanded = readToEOS(reader);
|
||||
}catch(UnsupportedEncodingException ex){
|
||||
throw new RuntimeException("Could open converter for encoding: " +ENCODING);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return new String(expanded);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Alias{
|
||||
public Alias(String path){
|
||||
pathToResource = path;
|
||||
};
|
||||
private final char RES_PATH_SEP_CHAR = '/';
|
||||
private String pathToResource;
|
||||
|
||||
|
||||
|
||||
|
||||
private Object getResource(String className,String parentKey, Hashtable visited){
|
||||
String packageName=null,bundleName=null, locale=null, keyPath=null;
|
||||
|
||||
|
||||
if(pathToResource.indexOf(RES_PATH_SEP_CHAR)==0){
|
||||
int i =pathToResource.indexOf(RES_PATH_SEP_CHAR,1);
|
||||
int j =pathToResource.indexOf(RES_PATH_SEP_CHAR,i+1);
|
||||
@ -276,12 +280,12 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
locale=pathToResource.substring(i+1,j);
|
||||
keyPath=pathToResource.substring(j+1,pathToResource.length());
|
||||
}
|
||||
//there is a path included
|
||||
//there is a path included
|
||||
if(bundleName.equals(ICUDATA)){
|
||||
bundleName = ICU_BUNDLE_NAME;
|
||||
packageName = ICU_PACKAGE_NAME;
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
//no path start with locale
|
||||
int i =pathToResource.indexOf(RES_PATH_SEP_CHAR);
|
||||
@ -292,7 +296,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
packageName=className.substring(0,j);
|
||||
bundleName=className.substring(j+1,className.indexOf("_"));
|
||||
keyPath=pathToResource.substring(i+1);
|
||||
|
||||
|
||||
if(i!=-1){
|
||||
locale = pathToResource.substring(0,i);
|
||||
}else{
|
||||
@ -300,19 +304,19 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
keyPath=parentKey;
|
||||
className=packageName+"."+bundleName+"_"+locale;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
ResourceBundle bundle = null;
|
||||
// getResourceBundle guarantees that the CLASSPATH will be searched
|
||||
// for loading the resource with name <bundleName>_<localeName>.class
|
||||
bundle = ICULocaleData.getResourceBundle(packageName,bundleName,locale);
|
||||
|
||||
|
||||
return findResource(bundle,className,keyPath, visited);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private boolean isIndex(String s){
|
||||
if(s.length()==1){
|
||||
char c = s.charAt(0);
|
||||
@ -346,9 +350,9 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
private Object findResource(Object o , String[] keys, int start){
|
||||
Object obj = o;
|
||||
if( start < keys.length && keys[start] !=null){
|
||||
if(obj instanceof Object[][]){
|
||||
obj = findResource((Object[][])obj,keys[start]);
|
||||
}else if(obj instanceof Object[] && isIndex(keys[start])){
|
||||
if(obj instanceof Object[][]){
|
||||
obj = findResource((Object[][])obj,keys[start]);
|
||||
}else if(obj instanceof Object[] && isIndex(keys[start])){
|
||||
obj = ((Object[])obj)[getIndex(keys[start])];
|
||||
}
|
||||
if(start+1 < keys.length && keys[start+1] !=null){
|
||||
@ -364,9 +368,9 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
if(visited.get(className+key)!=null){
|
||||
throw new MissingResourceException("Circular Aliases in bundle.",bundle.getClass().getName(),key);
|
||||
}
|
||||
|
||||
|
||||
visited.put(className+key,"");
|
||||
|
||||
|
||||
String[] keys = split(key,RES_PATH_SEP_CHAR);
|
||||
Object o =null;
|
||||
if(keys.length>0){
|
||||
@ -380,7 +384,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
if(o instanceof Object[][]){
|
||||
o = resolveAliases((Object[][])o,className,key,visited);
|
||||
}else if(o instanceof Object[]){
|
||||
o = resolveAliases((Object[])o,className,key,visited);
|
||||
o = resolveAliases((Object[])o,className,key,visited);
|
||||
}else if(o instanceof Alias){
|
||||
return ((Alias)o).getResource(className,key,visited);
|
||||
}
|
||||
@ -402,9 +406,9 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
private String[] split(String source, char delimiter){
|
||||
|
||||
|
||||
char[] src = source.toCharArray();
|
||||
int index = 0;
|
||||
int numdelimit=0;
|
||||
@ -420,8 +424,8 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
int old=0;
|
||||
for(int j=0;j<src.length;j++){
|
||||
if(src[j]==delimiter){
|
||||
values[index++] = new String(src,old,j-old);
|
||||
old=j+1/* skip after the delimiter*/;
|
||||
values[index++] = new String(src,old,j-old);
|
||||
old=j+1/* skip after the delimiter*/;
|
||||
}
|
||||
}
|
||||
if(old <src.length)
|
||||
@ -429,6 +433,6 @@ public class ICUListResourceBundle extends ListResourceBundle {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class ICULocaleData {
|
||||
|
||||
/**
|
||||
* Stores the locale information in a cache accessed by key (bundle prefix). The
|
||||
* cached objects are AvailEntries. The cache is held by a SoftReference
|
||||
* cached objects are AvailEntries. The cache is held by a SoftReference
|
||||
* so it can be GC'd.
|
||||
*/
|
||||
private static AvailEntry getAvailEntry(String key) {
|
||||
@ -161,7 +161,7 @@ public class ICULocaleData {
|
||||
* Gets a LocaleElements resource bundle.
|
||||
*/
|
||||
public static ResourceBundle getLocaleElements(String localeName) {
|
||||
return getResourceBundle(LOCALE_ELEMENTS, localeName);
|
||||
return getResourceBundle(LOCALE_ELEMENTS, localeName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,60 +170,62 @@ public class ICULocaleData {
|
||||
* class path?
|
||||
*/
|
||||
private static ResourceBundle instantiateBundle(String name, Locale l) {
|
||||
ResourceBundle rb = ResourceBundle.getBundle(name, l);
|
||||
return rb;
|
||||
ResourceBundle rb = ResourceBundle.getBundle(name, l);
|
||||
return rb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a resource bundle from the lookup chain.
|
||||
*/
|
||||
public static ResourceBundle getResourceBundle(String bundleName, String localeName) {
|
||||
Locale locale = LocaleUtility.getLocaleFromName(localeName);
|
||||
return getResourceBundle(bundleName, locale);
|
||||
Locale locale = LocaleUtility.getLocaleFromName(localeName);
|
||||
return getResourceBundle(bundleName, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a resource bundle from the lookup chain.
|
||||
*/
|
||||
public static ResourceBundle getResourceBundle(String bundleName, Locale locale) {
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
for (int i = 0; i < packageNames.length; ++i) {
|
||||
try {
|
||||
String path = packageNames[i] + "." + bundleName;
|
||||
if (debug) System.out.println("calling instantiateBundle: " + path + "_" + locale);
|
||||
ResourceBundle rb = instantiateBundle(path, locale);
|
||||
return rb;
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
if (debug) System.out.println(bundleName + "_" + locale + " not found in " + packageNames[i]);
|
||||
}
|
||||
}
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
for (int i = 0; i < packageNames.length; ++i) {
|
||||
try {
|
||||
String path = packageNames[i] + "." + bundleName;
|
||||
if (debug) System.out.println("calling instantiateBundle: " + path + "_" + locale);
|
||||
ResourceBundle rb = instantiateBundle(path, locale);
|
||||
return rb;
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
if (debug) System.out.println(bundleName + "_" + locale + " not found in " + packageNames[i]);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a resource bundle from the lookup chain.
|
||||
*/
|
||||
public static ResourceBundle getResourceBundle(String[] packages, String bundleName, String localeName) {
|
||||
Locale locale = LocaleUtility.getLocaleFromName(localeName);
|
||||
Locale locale = LocaleUtility.getLocaleFromName(localeName);
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
for (int i = 0; i < packages.length; ++i) {
|
||||
try {
|
||||
String path = packages[i] + "." + bundleName;
|
||||
if (debug) System.out.println("calling instantiateBundle: " + path + "_" + locale);
|
||||
ResourceBundle rb = instantiateBundle(path, locale);
|
||||
return rb;
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
if (debug) System.out.println(bundleName + "_" + locale + " not found in " + packages[i]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
for (int i = 0; i < packages.length; ++i) {
|
||||
try {
|
||||
String path = packages[i] + "." + bundleName;
|
||||
if (debug) System.out.println("calling instantiateBundle: " + path + "_" + locale);
|
||||
ResourceBundle rb = instantiateBundle(path, locale);
|
||||
return rb;
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
if (debug) System.out.println(bundleName + "_" + locale + " not found in " + packages[i]);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,28 +236,27 @@ public class ICULocaleData {
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
String path = packageName + "." + bundleName;
|
||||
if (debug) System.out.println("calling instantiateBundle: " + path + "_" + locale);
|
||||
ResourceBundle rb = instantiateBundle(path, locale);
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
if (debug) System.out.println(bundleName + "_" + locale + " not found in " + packageName);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get a resource bundle from the resource bundle path. Unlike getResourceBundle, this
|
||||
* returns an 'unparented' bundle that exactly matches the bundle name and locale name.
|
||||
*/
|
||||
public static ResourceBundle loadResourceBundle(String bundleName, Locale locale) {
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
return loadResourceBundle(bundleName, locale.toString());
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
return loadResourceBundle(bundleName, locale.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,43 +264,43 @@ public class ICULocaleData {
|
||||
* returns an 'unparented' bundle that exactly matches the bundle name and locale name.
|
||||
*/
|
||||
public static ResourceBundle loadResourceBundle(String bundleName, String localeName) {
|
||||
if (localeName != null && localeName.length() > 0) {
|
||||
bundleName = bundleName + "_" + localeName;
|
||||
}
|
||||
for (int i = 0; i < packageNames.length; ++i) {
|
||||
String name = packageNames[i] + "." + bundleName;
|
||||
try {
|
||||
if (name.indexOf("_zh_") == -1) { // DLF temporary hack
|
||||
Class rbclass = ICULocaleData.class.forName(name);
|
||||
ResourceBundle rb = (ResourceBundle)rbclass.newInstance();
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
if (debug) {
|
||||
System.out.println(bundleName + " not found in " + packageNames[i]);
|
||||
}
|
||||
// ignore, keep looking
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (debug) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println(bundleName + " not found.");
|
||||
}
|
||||
|
||||
return null;
|
||||
if (localeName != null && localeName.length() > 0) {
|
||||
bundleName = bundleName + "_" + localeName;
|
||||
}
|
||||
for (int i = 0; i < packageNames.length; ++i) {
|
||||
String name = packageNames[i] + "." + bundleName;
|
||||
try {
|
||||
if (name.indexOf("_zh_") == -1) { // DLF temporary hack
|
||||
Class rbclass = ICULocaleData.class.forName(name);
|
||||
ResourceBundle rb = (ResourceBundle)rbclass.newInstance();
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
if (debug) {
|
||||
System.out.println(bundleName + " not found in " + packageNames[i]);
|
||||
}
|
||||
// ignore, keep looking
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (debug) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println(bundleName + " not found.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========== privates ==========
|
||||
|
||||
private static Set createLocaleNameSet(String bundleName) {
|
||||
try {
|
||||
ResourceBundle index = getResourceBundle(bundleName, "index");
|
||||
String[] localeNames = index.getStringArray("InstalledLocales");
|
||||
try {
|
||||
ResourceBundle index = getResourceBundle(bundleName, "index");
|
||||
String[] localeNames = index.getStringArray("InstalledLocales");
|
||||
|
||||
// barf gag choke spit hack...
|
||||
// since java's Locale 'fixes' the locale string for some locales,
|
||||
@ -312,28 +313,28 @@ public class ICULocaleData {
|
||||
HashSet set = new HashSet();
|
||||
set.addAll(Arrays.asList(localeNames));
|
||||
return Collections.unmodifiableSet(set);
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
System.out.println("couldn't find index for bundleName: " + bundleName);
|
||||
Thread.dumpStack();
|
||||
}
|
||||
}
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
private static Locale[] createLocaleList(String bundleName) {
|
||||
try {
|
||||
ResourceBundle index = getResourceBundle(bundleName, "index");
|
||||
String[] localeNames = index.getStringArray("InstalledLocales");
|
||||
Locale[] locales = new Locale[localeNames.length];
|
||||
for (int i = 0; i < localeNames.length; ++i) {
|
||||
locales[i] = LocaleUtility.getLocaleFromName(localeNames[i]);
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
try {
|
||||
ResourceBundle index = getResourceBundle(bundleName, "index");
|
||||
String[] localeNames = index.getStringArray("InstalledLocales");
|
||||
Locale[] locales = new Locale[localeNames.length];
|
||||
for (int i = 0; i < localeNames.length; ++i) {
|
||||
locales[i] = LocaleUtility.getLocaleFromName(localeNames[i]);
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
System.out.println("couldn't find index for bundleName: " + bundleName);
|
||||
Thread.dumpStack();
|
||||
}
|
||||
return new Locale[0];
|
||||
}
|
||||
return new Locale[0];
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,14 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICUService.java,v $
|
||||
* $Date: 2002/12/12 18:02:09 $
|
||||
* $Revision: 1.13 $
|
||||
* $Date: 2003/01/28 18:55:38 $
|
||||
* $Revision: 1.14 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
import com.ibm.icu.text.Collator;
|
||||
//import com.ibm.icu.text.Collator;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -48,7 +48,7 @@ import java.util.TreeMap;
|
||||
* the actual id that was matched by a query when they use an id to
|
||||
* retrieve a service object.</p>
|
||||
*
|
||||
* <p>Service objects are instantiated by Factory objects registered with
|
||||
* <p>Service objects are instantiated by Factory objects registered with
|
||||
* the service. The service queries each Factory in turn, from most recently
|
||||
* registered to earliest registered, until one returns a service object.
|
||||
* If none responds with a service object, a fallback id is generated,
|
||||
@ -76,11 +76,11 @@ import java.util.TreeMap;
|
||||
* unique ids. Factories are associated with each simple ID and
|
||||
* the responsible factory can also return a human-readable localized
|
||||
* version of the simple ID, for use in user interfaces. ICUService
|
||||
* can also provide a sorted collection of the all the localized visible
|
||||
* can also provide a sorted collection of the all the localized visible
|
||||
* ids.</p>
|
||||
*
|
||||
* <p>ICUService implements ICUNotifier, so that clients can register
|
||||
* to receive notification when factories are added or removed from
|
||||
* to receive notification when factories are added or removed from
|
||||
* the service. ICUService provides a default EventListener subinterface,
|
||||
* ServiceListener, which can be registered with the service. When
|
||||
* the service changes, the ServiceListener's serviceChanged method
|
||||
@ -95,7 +95,7 @@ import java.util.TreeMap;
|
||||
* ICUService by overriding it, for example, to customize the Key and
|
||||
* fallback strategy. ICULocaleService is a customized service that
|
||||
* uses Locale names as ids and uses Keys that implement the standard
|
||||
* resource bundle fallback strategy.<p>
|
||||
* resource bundle fallback strategy.<p>
|
||||
*/
|
||||
public class ICUService extends ICUNotifier {
|
||||
protected final String name;
|
||||
@ -117,7 +117,7 @@ public class ICUService extends ICUNotifier {
|
||||
/**
|
||||
* Access to factories is protected by a read-write lock. This is
|
||||
* to allow multiple threads to read concurrently, but keep
|
||||
* changes to the factory list atomic with respect to all readers.
|
||||
* changes to the factory list atomic with respect to all readers.
|
||||
*/
|
||||
private final ICURWLock factoryLock = new ICURWLock();
|
||||
|
||||
@ -137,8 +137,8 @@ public class ICUService extends ICUNotifier {
|
||||
* The descriptor contains an optional prefix, followed by '/'
|
||||
* and the currentID. Factories that handle complex keys,
|
||||
* for example number format factories that generate multiple
|
||||
* kinds of formatters for the same locale, use the descriptor
|
||||
* to provide a fully unique identifier for the service object,
|
||||
* kinds of formatters for the same locale, use the descriptor
|
||||
* to provide a fully unique identifier for the service object,
|
||||
* while using the currentID (in this case, the locale string),
|
||||
* as the visible IDs that can be localized.
|
||||
*
|
||||
@ -148,9 +148,9 @@ public class ICUService extends ICUNotifier {
|
||||
public static class Key {
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Construct a key from an id.
|
||||
*/
|
||||
/**
|
||||
* Construct a key from an id.
|
||||
*/
|
||||
public Key(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class ICUService extends ICUNotifier {
|
||||
|
||||
/**
|
||||
* Return the canonical version of the original ID. This implementation
|
||||
* returns the original ID unchanged.
|
||||
* returns the original ID unchanged.
|
||||
*/
|
||||
public String canonicalID() {
|
||||
return id;
|
||||
@ -172,7 +172,7 @@ public class ICUService extends ICUNotifier {
|
||||
|
||||
/**
|
||||
* Return the (canonical) current ID. This implementation
|
||||
* returns the canonical ID.
|
||||
* returns the canonical ID.
|
||||
*/
|
||||
public String currentID() {
|
||||
return canonicalID();
|
||||
@ -185,7 +185,7 @@ public class ICUService extends ICUNotifier {
|
||||
* factory may handle all descriptors for an ID, or just a
|
||||
* particular descriptor. The factory can either parse the
|
||||
* descriptor or use custom API on the key in order to
|
||||
* instantiate the service.
|
||||
* instantiate the service.
|
||||
*/
|
||||
public String currentDescriptor() {
|
||||
return "/" + currentID();
|
||||
@ -194,16 +194,16 @@ public class ICUService extends ICUNotifier {
|
||||
/**
|
||||
* If the key has a fallback, modify the key and return true,
|
||||
* otherwise return false. The current ID will change if there
|
||||
* is a fallback. No currentIDs should be repeated, and fallback
|
||||
* must eventually return false. This implmentation has no fallbacks
|
||||
* and always returns false.
|
||||
*/
|
||||
* is a fallback. No currentIDs should be repeated, and fallback
|
||||
* must eventually return false. This implmentation has no fallbacks
|
||||
* and always returns false.
|
||||
*/
|
||||
public boolean fallback() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a key created from id would eventually fallback to match the
|
||||
* If a key created from id would eventually fallback to match the
|
||||
* canonical ID of this key, return true.
|
||||
*/
|
||||
public boolean isFallbackOf(String id) {
|
||||
@ -215,13 +215,13 @@ public class ICUService extends ICUNotifier {
|
||||
* Factories generate the service objects maintained by the
|
||||
* service. A factory generates a service object from a key,
|
||||
* updates id->factory mappings, and returns the display name for
|
||||
* a supported id.
|
||||
* a supported id.
|
||||
*/
|
||||
public static interface Factory {
|
||||
|
||||
/**
|
||||
* Create a service object from the key, if this factory
|
||||
* supports the key. Otherwise, return null.
|
||||
* supports the key. Otherwise, return null.
|
||||
*
|
||||
* <p>If the factory supports the key, then it can call
|
||||
* the service's getKey(Key, String[], Factory) method
|
||||
@ -230,11 +230,11 @@ public class ICUService extends ICUNotifier {
|
||||
* registration with the service. This can change the
|
||||
* key, so any information required from the key should
|
||||
* be extracted before making such a callback.
|
||||
*/
|
||||
*/
|
||||
public Object create(Key key, ICUService service);
|
||||
|
||||
/**
|
||||
* Update the result IDs (not descriptors) to reflect the IDs
|
||||
/**
|
||||
* Update the result IDs (not descriptors) to reflect the IDs
|
||||
* this factory handles. This function and getDisplayName are
|
||||
* used to support ICUService.getDisplayNames. Basically, the
|
||||
* factory has to determine which IDs it will permit to be
|
||||
@ -242,15 +242,15 @@ public class ICUService extends ICUNotifier {
|
||||
* display names for. In most cases this reflects the IDs that
|
||||
* the factory directly supports.
|
||||
*/
|
||||
public void updateVisibleIDs(Map result);
|
||||
public void updateVisibleIDs(Map result);
|
||||
|
||||
/**
|
||||
* Return the display name for this id in the provided locale.
|
||||
* This is an localized id, not a descriptor. If the id is
|
||||
/**
|
||||
* Return the display name for this id in the provided locale.
|
||||
* This is an localized id, not a descriptor. If the id is
|
||||
* not visible or not defined by the factory, return null.
|
||||
* If locale is null, return id unchanged.
|
||||
*/
|
||||
public String getDisplayName(String id, Locale locale);
|
||||
*/
|
||||
public String getDisplayName(String id, Locale locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,63 +263,63 @@ public class ICUService extends ICUNotifier {
|
||||
* for its ID if visible is false.
|
||||
*/
|
||||
public static class SimpleFactory implements Factory {
|
||||
protected Object instance;
|
||||
protected String id;
|
||||
protected boolean visible;
|
||||
protected Object instance;
|
||||
protected String id;
|
||||
protected boolean visible;
|
||||
|
||||
/**
|
||||
* Convenience constructor that calls SimpleFactory(Object, String, boolean)
|
||||
* with visible true.
|
||||
*/
|
||||
public SimpleFactory(Object instance, String id) {
|
||||
this(instance, id, true);
|
||||
}
|
||||
/**
|
||||
* Convenience constructor that calls SimpleFactory(Object, String, boolean)
|
||||
* with visible true.
|
||||
*/
|
||||
public SimpleFactory(Object instance, String id) {
|
||||
this(instance, id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a simple factory that maps a single id to a single
|
||||
* service instance. If visible is true, the id will be visible.
|
||||
* Neither the instance nor the id can be null.
|
||||
*/
|
||||
public SimpleFactory(Object instance, String id, boolean visible) {
|
||||
if (instance == null || id == null) {
|
||||
throw new IllegalArgumentException("Instance or id is null");
|
||||
}
|
||||
this.instance = instance;
|
||||
this.id = id;
|
||||
this.visible = visible;
|
||||
}
|
||||
/**
|
||||
* Construct a simple factory that maps a single id to a single
|
||||
* service instance. If visible is true, the id will be visible.
|
||||
* Neither the instance nor the id can be null.
|
||||
*/
|
||||
public SimpleFactory(Object instance, String id, boolean visible) {
|
||||
if (instance == null || id == null) {
|
||||
throw new IllegalArgumentException("Instance or id is null");
|
||||
}
|
||||
this.instance = instance;
|
||||
this.id = id;
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service instance if the factory's id is equal to
|
||||
/**
|
||||
* Return the service instance if the factory's id is equal to
|
||||
* the key's currentID. Service is ignored.
|
||||
*/
|
||||
public Object create(Key key, ICUService service) {
|
||||
if (id.equals(key.currentID())) {
|
||||
return instance;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
public Object create(Key key, ICUService service) {
|
||||
if (id.equals(key.currentID())) {
|
||||
return instance;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If visible, adds a mapping from id -> this to the result,
|
||||
/**
|
||||
* If visible, adds a mapping from id -> this to the result,
|
||||
* otherwise removes id from result.
|
||||
*/
|
||||
public void updateVisibleIDs(Map result) {
|
||||
if (visible) {
|
||||
*/
|
||||
public void updateVisibleIDs(Map result) {
|
||||
if (visible) {
|
||||
result.put(id, this);
|
||||
} else {
|
||||
result.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If this.id equals id, returns id regardless of locale,
|
||||
* otherwise returns null. (This default implementation has
|
||||
* no localized id information.)
|
||||
/**
|
||||
* If this.id equals id, returns id regardless of locale,
|
||||
* otherwise returns null. (This default implementation has
|
||||
* no localized id information.)
|
||||
*/
|
||||
public String getDisplayName(String id, Locale locale) {
|
||||
return (visible && this.id.equals(id)) ? id : null;
|
||||
}
|
||||
public String getDisplayName(String id, Locale locale) {
|
||||
return (visible && this.id.equals(id)) ? id : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugging.
|
||||
@ -339,7 +339,7 @@ public class ICUService extends ICUNotifier {
|
||||
* createKey to create a key for the provided descriptor.
|
||||
*/
|
||||
public Object get(String descriptor) {
|
||||
return getKey(createKey(descriptor), null);
|
||||
return getKey(createKey(descriptor), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -348,7 +348,7 @@ public class ICUService extends ICUNotifier {
|
||||
*/
|
||||
public Object get(String descriptor, String[] actualReturn) {
|
||||
if (descriptor == null) {
|
||||
throw new NullPointerException("descriptor must not be null");
|
||||
throw new NullPointerException("descriptor must not be null");
|
||||
}
|
||||
return getKey(createKey(descriptor), actualReturn);
|
||||
}
|
||||
@ -371,7 +371,7 @@ public class ICUService extends ICUNotifier {
|
||||
* registered factory, in order. If none generates a service
|
||||
* object for the key, repeats the process with each fallback of
|
||||
* the key, until either one returns a service object, or the key
|
||||
* has no fallback.</p>
|
||||
* has no fallback.</p>
|
||||
*
|
||||
* <p>If key is null, just returns null.</p>
|
||||
*/
|
||||
@ -379,38 +379,38 @@ public class ICUService extends ICUNotifier {
|
||||
return getKey(key, actualReturn, null);
|
||||
}
|
||||
|
||||
|
||||
public Object getKey(Key key, String[] actualReturn, Factory factory) {
|
||||
if (factories.size() == 0) {
|
||||
return handleDefault(key, actualReturn);
|
||||
}
|
||||
|
||||
boolean debug = false;
|
||||
public Object getKey(Key key, String[] actualReturn, Factory factory) {
|
||||
if (factories.size() == 0) {
|
||||
return handleDefault(key, actualReturn);
|
||||
}
|
||||
|
||||
boolean debug = false;
|
||||
if (debug) System.out.println("Service: " + name + " key: " + key);
|
||||
|
||||
CacheEntry result = null;
|
||||
if (key != null) {
|
||||
try {
|
||||
// The factory list can't be modified until we're done,
|
||||
// otherwise we might update the cache with an invalid result.
|
||||
// The cache has to stay in synch with the factory list.
|
||||
factoryLock.acquireRead();
|
||||
CacheEntry result = null;
|
||||
if (key != null) {
|
||||
try {
|
||||
// The factory list can't be modified until we're done,
|
||||
// otherwise we might update the cache with an invalid result.
|
||||
// The cache has to stay in synch with the factory list.
|
||||
factoryLock.acquireRead();
|
||||
|
||||
Map cache = null;
|
||||
SoftReference cref = cacheref; // copy so we don't need to sync on this
|
||||
if (cref != null) {
|
||||
cache = (Map)cref.get();
|
||||
}
|
||||
if (cache == null) {
|
||||
// synchronized since additions and queries on the cache must be atomic
|
||||
// they can be interleaved, though
|
||||
cache = Collections.synchronizedMap(new HashMap());
|
||||
cref = new SoftReference(cache);
|
||||
}
|
||||
Map cache = null;
|
||||
SoftReference cref = cacheref; // copy so we don't need to sync on this
|
||||
if (cref != null) {
|
||||
cache = (Map)cref.get();
|
||||
}
|
||||
if (cache == null) {
|
||||
// synchronized since additions and queries on the cache must be atomic
|
||||
// they can be interleaved, though
|
||||
cache = Collections.synchronizedMap(new HashMap());
|
||||
cref = new SoftReference(cache);
|
||||
}
|
||||
|
||||
String currentDescriptor = null;
|
||||
ArrayList cacheDescriptorList = null;
|
||||
boolean putInCache = false;
|
||||
String currentDescriptor = null;
|
||||
ArrayList cacheDescriptorList = null;
|
||||
boolean putInCache = false;
|
||||
|
||||
int NDebug = 0;
|
||||
|
||||
@ -430,103 +430,103 @@ public class ICUService extends ICUNotifier {
|
||||
cacheResult = false;
|
||||
}
|
||||
|
||||
outer:
|
||||
do {
|
||||
currentDescriptor = key.currentDescriptor();
|
||||
outer:
|
||||
do {
|
||||
currentDescriptor = key.currentDescriptor();
|
||||
if (debug) System.out.println(name + "[" + NDebug++ + "] looking for: " + currentDescriptor);
|
||||
result = (CacheEntry)cache.get(currentDescriptor);
|
||||
if (result != null) {
|
||||
result = (CacheEntry)cache.get(currentDescriptor);
|
||||
if (result != null) {
|
||||
if (debug) System.out.println(name + " found with descriptor: " + currentDescriptor);
|
||||
break outer;
|
||||
} else {
|
||||
break outer;
|
||||
} else {
|
||||
if (debug) System.out.println("did not find: " + currentDescriptor + " in cache");
|
||||
}
|
||||
|
||||
// first test of cache failed, so we'll have to update
|
||||
// the cache if we eventually succeed-- that is, if we're
|
||||
// first test of cache failed, so we'll have to update
|
||||
// the cache if we eventually succeed-- that is, if we're
|
||||
// going to update the cache at all.
|
||||
putInCache = cacheResult;
|
||||
putInCache = cacheResult;
|
||||
|
||||
int n = 0;
|
||||
int index = startIndex;
|
||||
while (index < limit) {
|
||||
while (index < limit) {
|
||||
Factory f = (Factory)factories.get(index++);
|
||||
if (debug) System.out.println("trying factory[" + (index-1) + "] " + f.toString());
|
||||
Object service = f.create(key, this);
|
||||
if (service != null) {
|
||||
result = new CacheEntry(currentDescriptor, service);
|
||||
Object service = f.create(key, this);
|
||||
if (service != null) {
|
||||
result = new CacheEntry(currentDescriptor, service);
|
||||
if (debug) System.out.println(name + " factory supported: " + currentDescriptor + ", caching");
|
||||
break outer;
|
||||
} else {
|
||||
break outer;
|
||||
} else {
|
||||
if (debug) System.out.println("factory did not support: " + currentDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// prepare to load the cache with all additional ids that
|
||||
// will resolve to result, assuming we'll succeed. We
|
||||
// don't want to keep querying on an id that's going to
|
||||
// fallback to the one that succeeded, we want to hit the
|
||||
// cache the first time next goaround.
|
||||
if (cacheDescriptorList == null) {
|
||||
cacheDescriptorList = new ArrayList(5);
|
||||
}
|
||||
cacheDescriptorList.add(currentDescriptor);
|
||||
// prepare to load the cache with all additional ids that
|
||||
// will resolve to result, assuming we'll succeed. We
|
||||
// don't want to keep querying on an id that's going to
|
||||
// fallback to the one that succeeded, we want to hit the
|
||||
// cache the first time next goaround.
|
||||
if (cacheDescriptorList == null) {
|
||||
cacheDescriptorList = new ArrayList(5);
|
||||
}
|
||||
cacheDescriptorList.add(currentDescriptor);
|
||||
|
||||
} while (key.fallback());
|
||||
} while (key.fallback());
|
||||
|
||||
if (result != null) {
|
||||
if (putInCache) {
|
||||
cache.put(result.actualDescriptor, result);
|
||||
if (cacheDescriptorList != null) {
|
||||
Iterator iter = cacheDescriptorList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (result != null) {
|
||||
if (putInCache) {
|
||||
cache.put(result.actualDescriptor, result);
|
||||
if (cacheDescriptorList != null) {
|
||||
Iterator iter = cacheDescriptorList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String desc = (String)iter.next();
|
||||
if (debug) System.out.println(name + " adding descriptor: '" + desc + "' for actual: '" + result.actualDescriptor + "'");
|
||||
|
||||
cache.put(desc, result);
|
||||
}
|
||||
}
|
||||
// Atomic update. We held the read lock all this time
|
||||
// so we know our cache is consistent with the factory list.
|
||||
// We might stomp over a cache that some other thread
|
||||
// rebuilt, but that's the breaks. They're both good.
|
||||
cacheref = cref;
|
||||
}
|
||||
cache.put(desc, result);
|
||||
}
|
||||
}
|
||||
// Atomic update. We held the read lock all this time
|
||||
// so we know our cache is consistent with the factory list.
|
||||
// We might stomp over a cache that some other thread
|
||||
// rebuilt, but that's the breaks. They're both good.
|
||||
cacheref = cref;
|
||||
}
|
||||
|
||||
if (actualReturn != null) {
|
||||
if (actualReturn != null) {
|
||||
// strip null prefix
|
||||
if (result.actualDescriptor.indexOf("/") == 0) {
|
||||
actualReturn[0] = result.actualDescriptor.substring(1);
|
||||
} else {
|
||||
actualReturn[0] = result.actualDescriptor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (debug) System.out.println("found in service: " + name);
|
||||
|
||||
return result.service;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseRead();
|
||||
}
|
||||
}
|
||||
return result.service;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseRead();
|
||||
}
|
||||
}
|
||||
|
||||
if (debug) System.out.println("not found in service: " + name);
|
||||
|
||||
return handleDefault(key, actualReturn);
|
||||
return handleDefault(key, actualReturn);
|
||||
}
|
||||
private SoftReference cacheref;
|
||||
|
||||
|
||||
// Record the actual id for this service in the cache, so we can return it
|
||||
// even if we succeed later with a different id.
|
||||
private static final class CacheEntry {
|
||||
final String actualDescriptor;
|
||||
final Object service;
|
||||
CacheEntry(String actualDescriptor, Object service) {
|
||||
this.actualDescriptor = actualDescriptor;
|
||||
this.service = service;
|
||||
}
|
||||
final String actualDescriptor;
|
||||
final Object service;
|
||||
CacheEntry(String actualDescriptor, Object service) {
|
||||
this.actualDescriptor = actualDescriptor;
|
||||
this.service = service;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -577,41 +577,41 @@ public class ICUService extends ICUNotifier {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map from visible ids to factories.
|
||||
* Return a map from visible ids to factories.
|
||||
*/
|
||||
private Map getVisibleIDMap() {
|
||||
Map idcache = null;
|
||||
SoftReference ref = idref;
|
||||
SoftReference ref = idref;
|
||||
if (ref != null) {
|
||||
idcache = (Map)ref.get();
|
||||
}
|
||||
while (idcache == null) {
|
||||
synchronized (this) { // or idref-only lock?
|
||||
if (ref == idref || idref == null) {
|
||||
// no other thread updated idref before we got the lock, so
|
||||
// grab the factory list and update it ourselves
|
||||
try {
|
||||
factoryLock.acquireRead();
|
||||
idcache = new HashMap();
|
||||
ListIterator lIter = factories.listIterator(factories.size());
|
||||
while (lIter.hasPrevious()) {
|
||||
Factory f = (Factory)lIter.previous();
|
||||
f.updateVisibleIDs(idcache);
|
||||
}
|
||||
idcache = Collections.unmodifiableMap(idcache);
|
||||
idref = new SoftReference(idcache);
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseRead();
|
||||
}
|
||||
} else {
|
||||
// another thread updated idref, but gc may have stepped
|
||||
// in and undone its work, leaving idcache null. If so,
|
||||
// retry.
|
||||
ref = idref;
|
||||
idcache = (Map)ref.get();
|
||||
}
|
||||
}
|
||||
synchronized (this) { // or idref-only lock?
|
||||
if (ref == idref || idref == null) {
|
||||
// no other thread updated idref before we got the lock, so
|
||||
// grab the factory list and update it ourselves
|
||||
try {
|
||||
factoryLock.acquireRead();
|
||||
idcache = new HashMap();
|
||||
ListIterator lIter = factories.listIterator(factories.size());
|
||||
while (lIter.hasPrevious()) {
|
||||
Factory f = (Factory)lIter.previous();
|
||||
f.updateVisibleIDs(idcache);
|
||||
}
|
||||
idcache = Collections.unmodifiableMap(idcache);
|
||||
idref = new SoftReference(idcache);
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseRead();
|
||||
}
|
||||
} else {
|
||||
// another thread updated idref, but gc may have stepped
|
||||
// in and undone its work, leaving idcache null. If so,
|
||||
// retry.
|
||||
ref = idref;
|
||||
idcache = (Map)ref.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return idcache;
|
||||
@ -623,7 +623,7 @@ public class ICUService extends ICUNotifier {
|
||||
* uses the current default locale.
|
||||
*/
|
||||
public String getDisplayName(String id) {
|
||||
return getDisplayName(id, Locale.getDefault());
|
||||
return getDisplayName(id, Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -632,32 +632,32 @@ public class ICUService extends ICUNotifier {
|
||||
* null.
|
||||
*/
|
||||
public String getDisplayName(String id, Locale locale) {
|
||||
Map m = getVisibleIDMap();
|
||||
Factory f = (Factory)m.get(id);
|
||||
return f != null ? f.getDisplayName(id, locale) : null;
|
||||
Map m = getVisibleIDMap();
|
||||
Factory f = (Factory)m.get(id);
|
||||
return f != null ? f.getDisplayName(id, locale) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the current default Locale as the locale, the default collator for
|
||||
* the locale as the comparator to sort the display names, and null for
|
||||
* the matchID.
|
||||
*/
|
||||
public SortedMap getDisplayNames() {
|
||||
/*public SortedMap getDisplayNames() {
|
||||
Locale locale = Locale.getDefault();
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getDisplayNames(locale, col, null);
|
||||
}
|
||||
return getDisplayNames(locale, col, null);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names, and null for the matchID.
|
||||
*/
|
||||
public SortedMap getDisplayNames(Locale locale) {
|
||||
/*public SortedMap getDisplayNames(Locale locale) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getDisplayNames(locale, col, null);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
@ -672,10 +672,10 @@ public class ICUService extends ICUNotifier {
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names.
|
||||
*/
|
||||
public SortedMap getDisplayNames(Locale locale, String matchID) {
|
||||
/*public SortedMap getDisplayNames(Locale locale, String matchID) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getDisplayNames(locale, col, matchID);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Return a snapshot of the mapping from display names to visible
|
||||
@ -684,37 +684,37 @@ public class ICUService extends ICUNotifier {
|
||||
* no guarantee that all and only the ids in the returned map will
|
||||
* be visible and supported by the service in subsequent calls,
|
||||
* nor is there any guarantee that the current display names match
|
||||
* those in the set. The display names are sorted based on the
|
||||
* those in the set. The display names are sorted based on the
|
||||
* comparator provided.
|
||||
*/
|
||||
public SortedMap getDisplayNames(Locale locale, Comparator col, String matchID) {
|
||||
SortedMap dncache = null;
|
||||
LocaleRef ref = dnref;
|
||||
LocaleRef ref = dnref;
|
||||
if (ref != null) {
|
||||
dncache = (SortedMap)ref.get(locale, col);
|
||||
}
|
||||
|
||||
while (dncache == null) {
|
||||
synchronized (this) {
|
||||
if (ref == dnref || dnref == null) {
|
||||
dncache = new TreeMap(col); // sorted
|
||||
|
||||
Map m = getVisibleIDMap();
|
||||
Iterator ei = m.entrySet().iterator();
|
||||
while (ei.hasNext()) {
|
||||
Entry e = (Entry)ei.next();
|
||||
String id = (String)e.getKey();
|
||||
Factory f = (Factory)e.getValue();
|
||||
dncache.put(f.getDisplayName(id, locale), id);
|
||||
}
|
||||
synchronized (this) {
|
||||
if (ref == dnref || dnref == null) {
|
||||
dncache = new TreeMap(col); // sorted
|
||||
|
||||
dncache = Collections.unmodifiableSortedMap(dncache);
|
||||
dnref = new LocaleRef(dncache, locale, col);
|
||||
} else {
|
||||
ref = dnref;
|
||||
dncache = ref.get(locale, col);
|
||||
}
|
||||
}
|
||||
Map m = getVisibleIDMap();
|
||||
Iterator ei = m.entrySet().iterator();
|
||||
while (ei.hasNext()) {
|
||||
Entry e = (Entry)ei.next();
|
||||
String id = (String)e.getKey();
|
||||
Factory f = (Factory)e.getValue();
|
||||
dncache.put(f.getDisplayName(id, locale), id);
|
||||
}
|
||||
|
||||
dncache = Collections.unmodifiableSortedMap(dncache);
|
||||
dnref = new LocaleRef(dncache, locale, col);
|
||||
} else {
|
||||
ref = dnref;
|
||||
dncache = ref.get(locale, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Key matchKey = createKey(matchID);
|
||||
@ -733,45 +733,45 @@ public class ICUService extends ICUNotifier {
|
||||
return result;
|
||||
}
|
||||
|
||||
// we define a class so we get atomic simultaneous access to the
|
||||
// we define a class so we get atomic simultaneous access to the
|
||||
// locale, comparator, and corresponding map.
|
||||
private static class LocaleRef {
|
||||
private final Locale locale;
|
||||
private SoftReference ref;
|
||||
private final Locale locale;
|
||||
private SoftReference ref;
|
||||
private Comparator col;
|
||||
|
||||
LocaleRef(Map dnCache, Locale locale, Comparator col) {
|
||||
this.locale = locale;
|
||||
LocaleRef(Map dnCache, Locale locale, Comparator col) {
|
||||
this.locale = locale;
|
||||
this.col = col;
|
||||
this.ref = new SoftReference(dnCache);
|
||||
}
|
||||
this.ref = new SoftReference(dnCache);
|
||||
}
|
||||
|
||||
SortedMap get(Locale locale, Comparator col) {
|
||||
SortedMap get(Locale locale, Comparator col) {
|
||||
SortedMap m = (SortedMap)ref.get();
|
||||
if (m != null &&
|
||||
if (m != null &&
|
||||
this.locale.equals(locale) &&
|
||||
(this.col == col || (this.col != null && this.col.equals(col)))) {
|
||||
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private LocaleRef dnref;
|
||||
|
||||
/**
|
||||
* Return a snapshot of the currently registered factories. There
|
||||
* is no guarantee that the list will still match the current
|
||||
* factory list of the service subsequent to this call.
|
||||
* factory list of the service subsequent to this call.
|
||||
*/
|
||||
public final List factories() {
|
||||
try {
|
||||
factoryLock.acquireRead();
|
||||
return new ArrayList(factories);
|
||||
}
|
||||
finally{
|
||||
factoryLock.releaseRead();
|
||||
}
|
||||
try {
|
||||
factoryLock.acquireRead();
|
||||
return new ArrayList(factories);
|
||||
}
|
||||
finally{
|
||||
factoryLock.releaseRead();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -783,15 +783,15 @@ public class ICUService extends ICUNotifier {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an object with the provided id. The id will be
|
||||
* Register an object with the provided id. The id will be
|
||||
* canonicalized. The canonicalized ID will be returned by
|
||||
* getVisibleIDs if visible is true.
|
||||
*/
|
||||
public Factory registerObject(Object obj, String id, boolean visible) {
|
||||
String canonicalID = createKey(id).canonicalID();
|
||||
return registerFactory(new SimpleFactory(obj, canonicalID, visible));
|
||||
return registerFactory(new SimpleFactory(obj, canonicalID, visible));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a Factory. Returns the factory if the service accepts
|
||||
* the factory, otherwise returns null. The default implementation
|
||||
@ -801,16 +801,16 @@ public class ICUService extends ICUNotifier {
|
||||
if (factory == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
try {
|
||||
factoryLock.acquireWrite();
|
||||
factories.add(0, factory);
|
||||
clearCaches();
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseWrite();
|
||||
}
|
||||
notifyChanged();
|
||||
return factory;
|
||||
try {
|
||||
factoryLock.acquireWrite();
|
||||
factories.add(0, factory);
|
||||
clearCaches();
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseWrite();
|
||||
}
|
||||
notifyChanged();
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -819,26 +819,26 @@ public class ICUService extends ICUNotifier {
|
||||
* removed.
|
||||
*/
|
||||
public final boolean unregisterFactory(Factory factory) {
|
||||
if (factory == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (factory == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
factoryLock.acquireWrite();
|
||||
if (factories.remove(factory)) {
|
||||
result = true;
|
||||
clearCaches();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseWrite();
|
||||
}
|
||||
boolean result = false;
|
||||
try {
|
||||
factoryLock.acquireWrite();
|
||||
if (factories.remove(factory)) {
|
||||
result = true;
|
||||
clearCaches();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseWrite();
|
||||
}
|
||||
|
||||
if (result) {
|
||||
notifyChanged();
|
||||
}
|
||||
return result;
|
||||
if (result) {
|
||||
notifyChanged();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -846,15 +846,15 @@ public class ICUService extends ICUNotifier {
|
||||
* lock is acquired and then reInitializeFactories is called.
|
||||
*/
|
||||
public final void reset() {
|
||||
try {
|
||||
factoryLock.acquireWrite();
|
||||
reInitializeFactories();
|
||||
clearCaches();
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseWrite();
|
||||
}
|
||||
notifyChanged();
|
||||
try {
|
||||
factoryLock.acquireWrite();
|
||||
reInitializeFactories();
|
||||
clearCaches();
|
||||
}
|
||||
finally {
|
||||
factoryLock.releaseWrite();
|
||||
}
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -862,10 +862,10 @@ public class ICUService extends ICUNotifier {
|
||||
* this clears the list. Subclasses can override to provide other
|
||||
* default initialization of the factory list. Subclasses must
|
||||
* not call this method directly, as it must only be called while
|
||||
* holding write access to the factory list.
|
||||
* holding write access to the factory list.
|
||||
*/
|
||||
protected void reInitializeFactories() {
|
||||
factories.clear();
|
||||
factories.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -893,12 +893,12 @@ public class ICUService extends ICUNotifier {
|
||||
* synchronized on this.
|
||||
*/
|
||||
protected void clearCaches() {
|
||||
// we don't synchronize on these because methods that use them
|
||||
// copy before use, and check for changes if they modify the
|
||||
// caches.
|
||||
cacheref = null;
|
||||
idref = null;
|
||||
dnref = null;
|
||||
// we don't synchronize on these because methods that use them
|
||||
// copy before use, and check for changes if they modify the
|
||||
// caches.
|
||||
cacheref = null;
|
||||
idref = null;
|
||||
dnref = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -908,7 +908,7 @@ public class ICUService extends ICUNotifier {
|
||||
* the resolution of ids changes, but not the visible ids themselves.
|
||||
*/
|
||||
protected void clearServiceCache() {
|
||||
cacheref = null;
|
||||
cacheref = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -919,24 +919,24 @@ public class ICUService extends ICUNotifier {
|
||||
* acceptsListener and notifyListener as appropriate.
|
||||
*/
|
||||
public static interface ServiceListener extends EventListener {
|
||||
public void serviceChanged(ICUService service);
|
||||
public void serviceChanged(ICUService service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the listener is accepted; by default this
|
||||
* requires a ServiceListener. Subclasses can override to accept
|
||||
* different listeners.
|
||||
* different listeners.
|
||||
*/
|
||||
protected boolean acceptsListener(EventListener l) {
|
||||
return l instanceof ServiceListener;
|
||||
return l instanceof ServiceListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the listener, which by default is a ServiceListener.
|
||||
* Subclasses can override to use a different listener.
|
||||
* Subclasses can override to use a different listener.
|
||||
*/
|
||||
protected void notifyListener(EventListener l) {
|
||||
((ServiceListener)l).serviceChanged(this);
|
||||
((ServiceListener)l).serviceChanged(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -944,11 +944,11 @@ public class ICUService extends ICUNotifier {
|
||||
* This also resets the statistics. Used for debugging purposes.
|
||||
*/
|
||||
public String stats() {
|
||||
ICURWLock.Stats stats = factoryLock.resetStats();
|
||||
if (stats != null) {
|
||||
return stats.toString();
|
||||
}
|
||||
return "no stats";
|
||||
ICURWLock.Stats stats = factoryLock.resetStats();
|
||||
if (stats != null) {
|
||||
return stats.toString();
|
||||
}
|
||||
return "no stats";
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -90,23 +90,23 @@ public final class UPropertyAliases implements ICUBinary.Authenticate {
|
||||
* See icu4c/src/common/propname.h.
|
||||
*/
|
||||
private static final byte DATA_FORMAT_ID[] = {'p', 'n', 'a', 'm'};
|
||||
|
||||
|
||||
/**
|
||||
* File version that this class understands.
|
||||
* See icu4c/src/common/propname.h.
|
||||
*/
|
||||
private static final byte DATA_FORMAT_VERSION = 1;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the datafile
|
||||
*/
|
||||
private static final String DATA_FILE_NAME = "data/pnames.icu";
|
||||
|
||||
|
||||
/**
|
||||
* Buffer size of datafile. The whole file is < 16k.
|
||||
*/
|
||||
private static final int DATA_BUFFER_SIZE = 8192;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Constructor
|
||||
|
||||
@ -298,7 +298,9 @@ public final class UPropertyAliases implements ICUBinary.Authenticate {
|
||||
|
||||
public short getShort(int enumProbe) {
|
||||
if (enumProbe < enumStart || enumProbe >= enumLimit) {
|
||||
throw new IllegalArgumentException("Invalid enum");
|
||||
throw new IllegalArgumentException("Invalid enum. enumStart = " +enumStart +
|
||||
" enumLimit = " + enumLimit +
|
||||
" enumProbe = " + enumProbe );
|
||||
}
|
||||
return offsetArray[enumProbe - enumStart];
|
||||
}
|
||||
@ -478,15 +480,15 @@ public final class UPropertyAliases implements ICUBinary.Authenticate {
|
||||
* and valueMap). It also knows how to read various structures.
|
||||
*/
|
||||
static class Builder extends ICUBinaryStream {
|
||||
|
||||
|
||||
// map[i] = offset of object i. We need maps for all of our
|
||||
// arrays. The arrays are indexed by offset in the raw binary
|
||||
// file; we need to translate that to index.
|
||||
|
||||
|
||||
private short stringPool_map[];
|
||||
|
||||
|
||||
private short valueMap_map[];
|
||||
|
||||
|
||||
private short nameGroup_map[];
|
||||
|
||||
public Builder(byte raw[]) {
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
|
||||
* $Date: 2003/01/14 19:32:37 $
|
||||
* $Revision: 1.34 $
|
||||
* $Date: 2003/01/28 18:55:38 $
|
||||
* $Revision: 1.35 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -19,7 +19,7 @@ public final class Utility {
|
||||
|
||||
private static final char APOSTROPHE = '\'';
|
||||
private static final char BACKSLASH = '\\';
|
||||
|
||||
|
||||
/**
|
||||
* Convenience utility to compare two Object[]s.
|
||||
* Ought to be in System
|
||||
@ -110,7 +110,7 @@ public final class Utility {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience utility to compare two int[]s.
|
||||
* @param len the length to compare.
|
||||
@ -1123,7 +1123,7 @@ public final class Utility {
|
||||
}
|
||||
|
||||
return -1; // text ended before end of pat
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an integer at pos, either of the form \d+ or of the form
|
||||
@ -1224,10 +1224,10 @@ public final class Utility {
|
||||
}
|
||||
|
||||
static final char DIGITS[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z'
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z'
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1243,57 +1243,57 @@ public final class Utility {
|
||||
* <code>StringBuffer</code> in the given radix. This is
|
||||
* done recursively since it is easiest to generate the low-
|
||||
* order digit first, but it must be appended last.
|
||||
*
|
||||
*
|
||||
* @param result is the <code>StringBuffer</code> to append to
|
||||
* @param n is the positive integer
|
||||
* @param radix is the radix, from 2 to 36 inclusive
|
||||
* @param minDigits is the minimum number of digits to append.
|
||||
*/
|
||||
private static void recursiveAppendNumber(StringBuffer result, int n,
|
||||
private static void recursiveAppendNumber(StringBuffer result, int n,
|
||||
int radix, int minDigits)
|
||||
{
|
||||
int digit = n % radix;
|
||||
{
|
||||
int digit = n % radix;
|
||||
|
||||
if (n >= radix || minDigits > 1) {
|
||||
recursiveAppendNumber(result, n / radix, radix, minDigits - 1);
|
||||
}
|
||||
if (n >= radix || minDigits > 1) {
|
||||
recursiveAppendNumber(result, n / radix, radix, minDigits - 1);
|
||||
}
|
||||
|
||||
result.append(DIGITS[digit]);
|
||||
}
|
||||
result.append(DIGITS[digit]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a number to the given StringBuffer in the given radix.
|
||||
* Standard digits '0'-'9' are used and letters 'A'-'Z' for
|
||||
* radices 11 through 36.
|
||||
* @param result the digits of the number are appended here
|
||||
* @param n the number to be converted to digits; may be negative.
|
||||
* If negative, a '-' is prepended to the digits.
|
||||
* @param radix a radix from 2 to 36 inclusive.
|
||||
* @param minDigits the minimum number of digits, not including
|
||||
* any '-', to produce. Values less than 2 have no effect. One
|
||||
* digit is always emitted regardless of this parameter.
|
||||
* @return a reference to result
|
||||
*/
|
||||
public static StringBuffer appendNumber(StringBuffer result, int n,
|
||||
/**
|
||||
* Append a number to the given StringBuffer in the given radix.
|
||||
* Standard digits '0'-'9' are used and letters 'A'-'Z' for
|
||||
* radices 11 through 36.
|
||||
* @param result the digits of the number are appended here
|
||||
* @param n the number to be converted to digits; may be negative.
|
||||
* If negative, a '-' is prepended to the digits.
|
||||
* @param radix a radix from 2 to 36 inclusive.
|
||||
* @param minDigits the minimum number of digits, not including
|
||||
* any '-', to produce. Values less than 2 have no effect. One
|
||||
* digit is always emitted regardless of this parameter.
|
||||
* @return a reference to result
|
||||
*/
|
||||
public static StringBuffer appendNumber(StringBuffer result, int n,
|
||||
int radix, int minDigits)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (radix < 2 || radix > 36) {
|
||||
throw new IllegalArgumentException("Illegal radix " + radix);
|
||||
}
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (radix < 2 || radix > 36) {
|
||||
throw new IllegalArgumentException("Illegal radix " + radix);
|
||||
}
|
||||
|
||||
|
||||
int abs = n;
|
||||
int abs = n;
|
||||
|
||||
if (n < 0) {
|
||||
abs = -n;
|
||||
result.append("-");
|
||||
}
|
||||
if (n < 0) {
|
||||
abs = -n;
|
||||
result.append("-");
|
||||
}
|
||||
|
||||
recursiveAppendNumber(result, abs, radix, minDigits);
|
||||
recursiveAppendNumber(result, abs, radix, minDigits);
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an unsigned 31-bit integer at the given offset. Use
|
||||
@ -1406,92 +1406,28 @@ public final class Utility {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugging purposes; format the given text in the form
|
||||
* aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
|
||||
* and limit, and the || indicate the start and limit.
|
||||
*/
|
||||
public static String formatInput(ReplaceableString input,
|
||||
Transliterator.Position pos) {
|
||||
StringBuffer appendTo = new StringBuffer();
|
||||
formatInput(appendTo, input, pos);
|
||||
return com.ibm.icu.impl.Utility.escape(appendTo.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugging purposes; format the given text in the form
|
||||
* aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
|
||||
* and limit, and the || indicate the start and limit.
|
||||
*/
|
||||
public static StringBuffer formatInput(StringBuffer appendTo,
|
||||
ReplaceableString input,
|
||||
Transliterator.Position pos) {
|
||||
if (0 <= pos.contextStart &&
|
||||
pos.contextStart <= pos.start &&
|
||||
pos.start <= pos.limit &&
|
||||
pos.limit <= pos.contextLimit &&
|
||||
pos.contextLimit <= input.length()) {
|
||||
|
||||
String a, b, c, d, e;
|
||||
//a = input.substring(0, pos.contextStart);
|
||||
b = input.substring(pos.contextStart, pos.start);
|
||||
c = input.substring(pos.start, pos.limit);
|
||||
d = input.substring(pos.limit, pos.contextLimit);
|
||||
//e = input.substring(pos.contextLimit, input.length());
|
||||
appendTo.//append(a).
|
||||
append('{').append(b).
|
||||
append('|').append(c).append('|').append(d).
|
||||
append('}')
|
||||
//.append(e)
|
||||
;
|
||||
} else {
|
||||
appendTo.append("INVALID Position {cs=" +
|
||||
pos.contextStart + ", s=" + pos.start + ", l=" +
|
||||
pos.limit + ", cl=" + pos.contextLimit + "} on " +
|
||||
input);
|
||||
}
|
||||
return appendTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*/
|
||||
public static String formatInput(Replaceable input,
|
||||
Transliterator.Position pos) {
|
||||
return formatInput((ReplaceableString) input, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*/
|
||||
public static StringBuffer formatInput(StringBuffer appendTo,
|
||||
Replaceable input,
|
||||
Transliterator.Position pos) {
|
||||
return formatInput(appendTo, (ReplaceableString) input, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to StringBuffer.getChars, version 1.3.
|
||||
* Since JDK 1.2 implements StringBuffer.getChars differently, this method
|
||||
* Since JDK 1.2 implements StringBuffer.getChars differently, this method
|
||||
* is here to provide consistent results.
|
||||
* To be removed after JDK 1.2 ceased to be the reference platform.
|
||||
* @param src source string buffer
|
||||
* @param srcBegin offset to the start of the src to retrieve from
|
||||
* @param srcEnd offset to the end of the src to retrieve from
|
||||
* @param dst char array to store the retrieved chars
|
||||
* @param dstBegin offset to the start of the destination char array to
|
||||
* @param dstBegin offset to the start of the destination char array to
|
||||
* store the retrieved chars
|
||||
* @draft since ICU4J 2.0
|
||||
*/
|
||||
public static void getChars(StringBuffer src, int srcBegin, int srcEnd,
|
||||
char dst[], int dstBegin)
|
||||
{
|
||||
if (srcBegin == srcEnd) {
|
||||
public static void getChars(StringBuffer src, int srcBegin, int srcEnd,
|
||||
char dst[], int dstBegin)
|
||||
{
|
||||
if (srcBegin == srcEnd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
src.getChars(srcBegin, srcEnd, dst, dstBegin);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a character to a rule that is being built up. To flush
|
||||
* the quoteBuf to rule, make one final call with isLiteral == true.
|
||||
@ -1631,15 +1567,15 @@ public final class Utility {
|
||||
true, escapeUnprintable, quoteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares 2 unsigned integers
|
||||
* @param source 32 bit unsigned integer
|
||||
* @param target 32 bit unsigned integer
|
||||
* @return 0 if equals, 1 if source is greater than target and -1
|
||||
* @return 0 if equals, 1 if source is greater than target and -1
|
||||
* otherwise
|
||||
*/
|
||||
public static final int compareUnsigned(int source, int target)
|
||||
public static final int compareUnsigned(int source, int target)
|
||||
{
|
||||
if (source == target) {
|
||||
return 0;
|
||||
@ -1647,7 +1583,7 @@ public final class Utility {
|
||||
if (source >= 0) {
|
||||
if (source < target || target < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (source < target && target < 0) {
|
||||
// source < 0, so
|
||||
@ -1656,48 +1592,48 @@ public final class Utility {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the highest bit in a positive integer. This is done
|
||||
* by doing a binary search through the bits.
|
||||
*
|
||||
* @param n is the integer
|
||||
*
|
||||
* @return the bit number of the highest bit, with 0 being
|
||||
* the low order bit, or -1 if <code>n</code> is not positive
|
||||
*/
|
||||
public static final byte highBit(int n)
|
||||
{
|
||||
if (n <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
byte bit = 0;
|
||||
|
||||
if (n >= 1 << 16) {
|
||||
n >>= 16;
|
||||
bit += 16;
|
||||
}
|
||||
|
||||
if (n >= 1 << 8) {
|
||||
n >>= 8;
|
||||
bit += 8;
|
||||
}
|
||||
|
||||
if (n >= 1 << 4) {
|
||||
n >>= 4;
|
||||
bit += 4;
|
||||
}
|
||||
|
||||
if (n >= 1 << 2) {
|
||||
n >>= 2;
|
||||
bit += 2;
|
||||
}
|
||||
|
||||
if (n >= 1 << 1) {
|
||||
n >>= 1;
|
||||
bit += 1;
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
/**
|
||||
* Find the highest bit in a positive integer. This is done
|
||||
* by doing a binary search through the bits.
|
||||
*
|
||||
* @param n is the integer
|
||||
*
|
||||
* @return the bit number of the highest bit, with 0 being
|
||||
* the low order bit, or -1 if <code>n</code> is not positive
|
||||
*/
|
||||
public static final byte highBit(int n)
|
||||
{
|
||||
if (n <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
byte bit = 0;
|
||||
|
||||
if (n >= 1 << 16) {
|
||||
n >>= 16;
|
||||
bit += 16;
|
||||
}
|
||||
|
||||
if (n >= 1 << 8) {
|
||||
n >>= 8;
|
||||
bit += 8;
|
||||
}
|
||||
|
||||
if (n >= 1 << 4) {
|
||||
n >>= 4;
|
||||
bit += 4;
|
||||
}
|
||||
|
||||
if (n >= 1 << 2) {
|
||||
n >>= 2;
|
||||
bit += 2;
|
||||
}
|
||||
|
||||
if (n >= 1 << 1) {
|
||||
n >>= 1;
|
||||
bit += 1;
|
||||
}
|
||||
|
||||
return bit;
|
||||
}
|
||||
}
|
||||
|
121
icu4j/src/com/ibm/icu/impl/UtilityExtensions.java
Normal file
121
icu4j/src/com/ibm/icu/impl/UtilityExtensions.java
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2002-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/UtilityExtensions.java,v $
|
||||
* $Date: 2003/01/28 18:55:38 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
import com.ibm.icu.text.Replaceable;
|
||||
import com.ibm.icu.text.ReplaceableString;
|
||||
import com.ibm.icu.text.UnicodeMatcher;
|
||||
import com.ibm.icu.text.Transliterator;
|
||||
/**
|
||||
* @author Ram
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class UtilityExtensions {
|
||||
/**
|
||||
* Append the given string to the rule. Calls the single-character
|
||||
* version of appendToRule for each character.
|
||||
*/
|
||||
public static void appendToRule(StringBuffer rule,
|
||||
String text,
|
||||
boolean isLiteral,
|
||||
boolean escapeUnprintable,
|
||||
StringBuffer quoteBuf) {
|
||||
for (int i=0; i<text.length(); ++i) {
|
||||
// Okay to process in 16-bit code units here
|
||||
Utility.appendToRule(rule, text.charAt(i), isLiteral, escapeUnprintable, quoteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a matcher reference, which may be null, append its
|
||||
* pattern as a literal to the given rule.
|
||||
*/
|
||||
public static void appendToRule(StringBuffer rule,
|
||||
UnicodeMatcher matcher,
|
||||
boolean escapeUnprintable,
|
||||
StringBuffer quoteBuf) {
|
||||
if (matcher != null) {
|
||||
appendToRule(rule, matcher.toPattern(escapeUnprintable),
|
||||
true, escapeUnprintable, quoteBuf);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* For debugging purposes; format the given text in the form
|
||||
* aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
|
||||
* and limit, and the || indicate the start and limit.
|
||||
*/
|
||||
public static String formatInput(ReplaceableString input,
|
||||
Transliterator.Position pos) {
|
||||
StringBuffer appendTo = new StringBuffer();
|
||||
formatInput(appendTo, input, pos);
|
||||
return com.ibm.icu.impl.Utility.escape(appendTo.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugging purposes; format the given text in the form
|
||||
* aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
|
||||
* and limit, and the || indicate the start and limit.
|
||||
*/
|
||||
public static StringBuffer formatInput(StringBuffer appendTo,
|
||||
ReplaceableString input,
|
||||
Transliterator.Position pos) {
|
||||
if (0 <= pos.contextStart &&
|
||||
pos.contextStart <= pos.start &&
|
||||
pos.start <= pos.limit &&
|
||||
pos.limit <= pos.contextLimit &&
|
||||
pos.contextLimit <= input.length()) {
|
||||
|
||||
String a, b, c, d, e;
|
||||
//a = input.substring(0, pos.contextStart);
|
||||
b = input.substring(pos.contextStart, pos.start);
|
||||
c = input.substring(pos.start, pos.limit);
|
||||
d = input.substring(pos.limit, pos.contextLimit);
|
||||
//e = input.substring(pos.contextLimit, input.length());
|
||||
appendTo.//append(a).
|
||||
append('{').append(b).
|
||||
append('|').append(c).append('|').append(d).
|
||||
append('}')
|
||||
//.append(e)
|
||||
;
|
||||
} else {
|
||||
appendTo.append("INVALID Position {cs=" +
|
||||
pos.contextStart + ", s=" + pos.start + ", l=" +
|
||||
pos.limit + ", cl=" + pos.contextLimit + "} on " +
|
||||
input);
|
||||
}
|
||||
return appendTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*/
|
||||
public static String formatInput(Replaceable input,
|
||||
Transliterator.Position pos) {
|
||||
return formatInput((ReplaceableString) input, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*/
|
||||
public static StringBuffer formatInput(StringBuffer appendTo,
|
||||
Replaceable input,
|
||||
Transliterator.Position pos) {
|
||||
return formatInput(appendTo, (ReplaceableString) input, pos);
|
||||
}
|
||||
|
||||
}
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/UCharacter.java,v $
|
||||
* $Date: 2003/01/25 00:05:03 $
|
||||
* $Revision: 1.61 $
|
||||
* $Date: 2003/01/28 18:55:39 $
|
||||
* $Revision: 1.62 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -47,7 +47,7 @@ import com.ibm.icu.impl.UPropertyAliases;
|
||||
* E.g. In Windows <br>
|
||||
* <code>set CLASSPATH=%CLASSPATH%;$JAR_FILE_PATH/ucharacter.jar</code>.<br>
|
||||
* Otherwise, another method would be to copy the files uprops.dat and
|
||||
* unames.icu from the icu4j source subdirectory
|
||||
* unames.icu from the icu4j source subdirectory
|
||||
* <i>$ICU4J_SRC/src/com.ibm.icu.impl.data</i> to your class directory
|
||||
* <i>$ICU4J_CLASS/com.ibm.icu.impl.data</i>.
|
||||
* </p>
|
||||
@ -2771,6 +2771,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static String getName(int ch)
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return NAME_.getName(ch, UCharacterNameChoice.UNICODE_CHAR_NAME);
|
||||
}
|
||||
|
||||
@ -2787,6 +2790,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static String getName1_0(int ch)
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return NAME_.getName(ch,
|
||||
UCharacterNameChoice.UNICODE_10_CHAR_NAME);
|
||||
}
|
||||
@ -2811,6 +2817,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static String getExtendedName(int ch)
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return NAME_.getName(ch, UCharacterNameChoice.EXTENDED_CHAR_NAME);
|
||||
}
|
||||
|
||||
@ -2829,7 +2838,9 @@ public final class UCharacter
|
||||
if (ch < UCharacter.MIN_VALUE || ch > UCharacter.MAX_VALUE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
String result = NAME_.getGroupName(ch,
|
||||
UCharacterNameChoice.ISO_COMMENT_);
|
||||
return result;
|
||||
@ -2846,7 +2857,10 @@ public final class UCharacter
|
||||
* @stable ICU 2.1
|
||||
*/
|
||||
public static int getCharFromName(String name)
|
||||
{
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return NAME_.getCharFromName(
|
||||
UCharacterNameChoice.UNICODE_CHAR_NAME, name);
|
||||
}
|
||||
@ -2863,6 +2877,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static int getCharFromName1_0(String name)
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return NAME_.getCharFromName(
|
||||
UCharacterNameChoice.UNICODE_10_CHAR_NAME, name);
|
||||
}
|
||||
@ -2888,6 +2905,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static int getCharFromExtendedName(String name)
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return NAME_.getCharFromName(
|
||||
UCharacterNameChoice.EXTENDED_CHAR_NAME, name);
|
||||
}
|
||||
@ -3520,6 +3540,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static ValueIterator getNameIterator()
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return new UCharacterNameIterator(NAME_,
|
||||
UCharacterNameChoice.UNICODE_CHAR_NAME);
|
||||
}
|
||||
@ -3545,6 +3568,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static ValueIterator getName1_0Iterator()
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return new UCharacterNameIterator(NAME_,
|
||||
UCharacterNameChoice.UNICODE_10_CHAR_NAME);
|
||||
}
|
||||
@ -3570,6 +3596,9 @@ public final class UCharacter
|
||||
*/
|
||||
public static ValueIterator getExtendedNameIterator()
|
||||
{
|
||||
if(NAME_==null){
|
||||
throw new RuntimeException("Could not load unames.icu");
|
||||
}
|
||||
return new UCharacterNameIterator(NAME_,
|
||||
UCharacterNameChoice.EXTENDED_CHAR_NAME);
|
||||
}
|
||||
@ -3904,24 +3933,26 @@ public final class UCharacter
|
||||
/**
|
||||
* Database storing the sets of character name
|
||||
*/
|
||||
static final UCharacterName NAME_;
|
||||
static UCharacterName NAME_ = null;
|
||||
|
||||
/**
|
||||
* Singleton object encapsulating the imported pnames.icu property aliases
|
||||
*/
|
||||
static final UPropertyAliases PNAMES_;
|
||||
static UPropertyAliases PNAMES_ = null;
|
||||
|
||||
// block to initialise name database and unicode 1.0 data
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
NAME_ = UCharacterName.getInstance();
|
||||
PNAMES_ = new UPropertyAliases();
|
||||
NAME_ = UCharacterName.getInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e.getMessage());
|
||||
//throw new RuntimeException(e.getMessage());
|
||||
// DONOT throw an exception
|
||||
// we might be building ICU modularly wothout names.icu and pnames.icu
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/UCharacterNameIterator.java,v $
|
||||
* $Date: 2002/09/19 21:18:14 $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2003/01/28 18:55:40 $
|
||||
* $Revision: 1.5 $
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@ -19,7 +19,7 @@ import com.ibm.icu.impl.UCharacterNameChoice;
|
||||
|
||||
/**
|
||||
* <p>Class enabling iteration of the codepoints and their names.</p>
|
||||
* <p>Result of each iteration contains a valid codepoint that has valid
|
||||
* <p>Result of each iteration contains a valid codepoint that has valid
|
||||
* name.</p>
|
||||
* <p>See UCharacter.getNameIterator() for an example of use.</p>
|
||||
* @author synwee
|
||||
@ -27,10 +27,10 @@ import com.ibm.icu.impl.UCharacterNameChoice;
|
||||
*/
|
||||
class UCharacterNameIterator implements ValueIterator
|
||||
{
|
||||
// public methods ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Gets the next result for this iteration and returns
|
||||
// public methods ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Gets the next result for this iteration and returns
|
||||
* true if we are not at the end of the iteration, false otherwise.</p>
|
||||
* <p>If the return boolean is a false, the contents of elements will not
|
||||
* be updated.</p>
|
||||
@ -41,155 +41,158 @@ class UCharacterNameIterator implements ValueIterator
|
||||
*/
|
||||
public boolean next(ValueIterator.Element element)
|
||||
{
|
||||
if (m_current_ >= m_limit_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_choice_ != UCharacterNameChoice.UNICODE_10_CHAR_NAME) {
|
||||
int length = m_name_.getAlgorithmLength();
|
||||
if (m_algorithmIndex_ < length) {
|
||||
while (m_algorithmIndex_ < length) {
|
||||
// find the algorithm range that could contain m_current_
|
||||
if (m_algorithmIndex_ < 0 ||
|
||||
m_name_.getAlgorithmEnd(m_algorithmIndex_) <
|
||||
m_current_) {
|
||||
m_algorithmIndex_ ++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_algorithmIndex_ < length) {
|
||||
// interleave the data-driven ones with the algorithmic ones
|
||||
// iterate over all algorithmic ranges; assume that they are
|
||||
// in ascending order
|
||||
int start = m_name_.getAlgorithmStart(m_algorithmIndex_);
|
||||
if (m_current_ < start) {
|
||||
// this should get rid of those codepoints that are not
|
||||
// in the algorithmic range
|
||||
int end = start;
|
||||
if (m_limit_ <= start) {
|
||||
end = m_limit_;
|
||||
}
|
||||
if (!iterateGroup(element, end)) {
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_current_ >= m_limit_) {
|
||||
// after iterateGroup fails, current codepoint may be
|
||||
// greater than limit
|
||||
return false;
|
||||
}
|
||||
|
||||
element.integer = m_current_;
|
||||
element.value = m_name_.getAlgorithmName(m_algorithmIndex_,
|
||||
m_current_);
|
||||
// reset the group index if we are in the algorithmic names
|
||||
m_groupIndex_ = -1;
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// enumerate the character names after the last algorithmic range
|
||||
if (!iterateGroup(element, m_limit_)) {
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
else if (m_choice_ == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
|
||||
if (!iterateExtended(element, m_limit_)) {
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if (m_current_ >= m_limit_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_choice_ != UCharacterNameChoice.UNICODE_10_CHAR_NAME) {
|
||||
int length = m_name_.getAlgorithmLength();
|
||||
if (m_algorithmIndex_ < length) {
|
||||
while (m_algorithmIndex_ < length) {
|
||||
// find the algorithm range that could contain m_current_
|
||||
if (m_algorithmIndex_ < 0 ||
|
||||
m_name_.getAlgorithmEnd(m_algorithmIndex_) <
|
||||
m_current_) {
|
||||
m_algorithmIndex_ ++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_algorithmIndex_ < length) {
|
||||
// interleave the data-driven ones with the algorithmic ones
|
||||
// iterate over all algorithmic ranges; assume that they are
|
||||
// in ascending order
|
||||
int start = m_name_.getAlgorithmStart(m_algorithmIndex_);
|
||||
if (m_current_ < start) {
|
||||
// this should get rid of those codepoints that are not
|
||||
// in the algorithmic range
|
||||
int end = start;
|
||||
if (m_limit_ <= start) {
|
||||
end = m_limit_;
|
||||
}
|
||||
if (!iterateGroup(element, end)) {
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_current_ >= m_limit_) {
|
||||
// after iterateGroup fails, current codepoint may be
|
||||
// greater than limit
|
||||
return false;
|
||||
}
|
||||
|
||||
element.integer = m_current_;
|
||||
element.value = m_name_.getAlgorithmName(m_algorithmIndex_,
|
||||
m_current_);
|
||||
// reset the group index if we are in the algorithmic names
|
||||
m_groupIndex_ = -1;
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// enumerate the character names after the last algorithmic range
|
||||
if (!iterateGroup(element, m_limit_)) {
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
else if (m_choice_ == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
|
||||
if (!iterateExtended(element, m_limit_)) {
|
||||
m_current_ ++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Resets the iterator to start iterating from the integer index
|
||||
* <p>Resets the iterator to start iterating from the integer index
|
||||
* UCharacter.MIN_VALUE or X if a setRange(X, Y) has been called previously.
|
||||
* </p>
|
||||
* @draft 2.1
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
m_current_ = m_start_;
|
||||
m_groupIndex_ = -1;
|
||||
m_algorithmIndex_ = -1;
|
||||
m_current_ = m_start_;
|
||||
m_groupIndex_ = -1;
|
||||
m_algorithmIndex_ = -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Restricts the range of integers to iterate and resets the iteration
|
||||
* <p>Restricts the range of integers to iterate and resets the iteration
|
||||
* to begin at the index argument start.</p>
|
||||
* <p>If setRange(start, end) is not performed before next(element) is
|
||||
* called, the iteration will start from the integer index
|
||||
* <p>If setRange(start, end) is not performed before next(element) is
|
||||
* called, the iteration will start from the integer index
|
||||
* UCharacter.MIN_VALUE and end at UCharacter.MAX_VALUE.</p>
|
||||
* <p>
|
||||
* If this range is set outside the range of UCharacter.MIN_VALUE and
|
||||
* If this range is set outside the range of UCharacter.MIN_VALUE and
|
||||
* UCharacter.MAX_VALUE, next(element) will always return false.
|
||||
* </p>
|
||||
* @param start first integer in range to iterate
|
||||
* @param limit 1 integer after the last integer in range
|
||||
* @exception IllegalArgumentException thrown when attempting to set an
|
||||
* @param limit 1 integer after the last integer in range
|
||||
* @exception IllegalArgumentException thrown when attempting to set an
|
||||
* illegal range. E.g limit <= start
|
||||
* @draft 2.1
|
||||
*/
|
||||
public void setRange(int start, int limit)
|
||||
{
|
||||
if (start >= limit) {
|
||||
throw new IllegalArgumentException(
|
||||
"start or limit has to be valid Unicode codepoints and start < limit");
|
||||
}
|
||||
if (start < UCharacter.MIN_VALUE) {
|
||||
m_start_ = UCharacter.MIN_VALUE;
|
||||
}
|
||||
else {
|
||||
m_start_ = start;
|
||||
}
|
||||
|
||||
if (limit > UCharacter.MAX_VALUE + 1) {
|
||||
m_limit_ = UCharacter.MAX_VALUE + 1;
|
||||
}
|
||||
else {
|
||||
m_limit_ = limit;
|
||||
}
|
||||
m_current_ = m_start_;
|
||||
if (start >= limit) {
|
||||
throw new IllegalArgumentException(
|
||||
"start or limit has to be valid Unicode codepoints and start < limit");
|
||||
}
|
||||
if (start < UCharacter.MIN_VALUE) {
|
||||
m_start_ = UCharacter.MIN_VALUE;
|
||||
}
|
||||
else {
|
||||
m_start_ = start;
|
||||
}
|
||||
|
||||
if (limit > UCharacter.MAX_VALUE + 1) {
|
||||
m_limit_ = UCharacter.MAX_VALUE + 1;
|
||||
}
|
||||
else {
|
||||
m_limit_ = limit;
|
||||
}
|
||||
m_current_ = m_start_;
|
||||
}
|
||||
|
||||
// protected constructor ---------------------------------------------
|
||||
|
||||
|
||||
// protected constructor ---------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name name data
|
||||
* @param choice name choice from the class
|
||||
* @param choice name choice from the class
|
||||
* com.ibm.icu.lang.UCharacterNameChoice
|
||||
* @draft 2.1
|
||||
*/
|
||||
protected UCharacterNameIterator(UCharacterName name, int choice)
|
||||
{
|
||||
m_name_ = name;
|
||||
// no explicit choice in UCharacter so no checks on choice
|
||||
m_choice_ = choice;
|
||||
m_start_ = UCharacter.MIN_VALUE;
|
||||
m_limit_ = UCharacter.MAX_VALUE + 1;
|
||||
m_current_ = m_start_;
|
||||
if(name==null){
|
||||
throw new IllegalArgumentException("UCharacterName name argument cannot be null. Missing unames.icu?");
|
||||
}
|
||||
m_name_ = name;
|
||||
// no explicit choice in UCharacter so no checks on choice
|
||||
m_choice_ = choice;
|
||||
m_start_ = UCharacter.MIN_VALUE;
|
||||
m_limit_ = UCharacter.MAX_VALUE + 1;
|
||||
m_current_ = m_start_;
|
||||
}
|
||||
|
||||
|
||||
// private data members ---------------------------------------------
|
||||
|
||||
/**
|
||||
* Name data
|
||||
*/
|
||||
private UCharacterName m_name_;
|
||||
/**
|
||||
* Name choice
|
||||
*/
|
||||
private int m_choice_;
|
||||
/**
|
||||
|
||||
/**
|
||||
* Name data
|
||||
*/
|
||||
private UCharacterName m_name_;
|
||||
/**
|
||||
* Name choice
|
||||
*/
|
||||
private int m_choice_;
|
||||
/**
|
||||
* Start iteration range
|
||||
*/
|
||||
private int m_start_;
|
||||
@ -212,125 +215,125 @@ class UCharacterNameIterator implements ValueIterator
|
||||
/**
|
||||
* Group use
|
||||
*/
|
||||
private static char GROUP_OFFSETS_[] =
|
||||
private static char GROUP_OFFSETS_[] =
|
||||
new char[UCharacterName.LINES_PER_GROUP_ + 1];
|
||||
private static char GROUP_LENGTHS_[] =
|
||||
private static char GROUP_LENGTHS_[] =
|
||||
new char[UCharacterName.LINES_PER_GROUP_ + 1];
|
||||
|
||||
|
||||
// private methods --------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Group name iteration, iterate all the names in the current 32-group and
|
||||
* Group name iteration, iterate all the names in the current 32-group and
|
||||
* returns the first codepoint that has a valid name.
|
||||
* @param result stores the result codepoint and name
|
||||
* @param limit last codepoint + 1 in range to search
|
||||
* @return false if a codepoint with a name is found in group and we can
|
||||
* bail from further iteration, true to continue on with the
|
||||
* iteration
|
||||
* @param result stores the result codepoint and name
|
||||
* @param limit last codepoint + 1 in range to search
|
||||
* @return false if a codepoint with a name is found in group and we can
|
||||
* bail from further iteration, true to continue on with the
|
||||
* iteration
|
||||
*/
|
||||
private boolean iterateSingleGroup(ValueIterator.Element result, int limit)
|
||||
private boolean iterateSingleGroup(ValueIterator.Element result, int limit)
|
||||
{
|
||||
synchronized(GROUP_OFFSETS_) {
|
||||
synchronized(GROUP_LENGTHS_) {
|
||||
int index = m_name_.getGroupLengths(m_groupIndex_, GROUP_OFFSETS_,
|
||||
GROUP_LENGTHS_);
|
||||
while (m_current_ < limit) {
|
||||
int offset = m_name_.getGroupOffset(m_current_);
|
||||
String name = m_name_.getGroupName(
|
||||
index + GROUP_OFFSETS_[offset],
|
||||
GROUP_LENGTHS_[offset], m_choice_);
|
||||
if ((name == null || name.length() == 0) &&
|
||||
m_choice_ == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
|
||||
name = m_name_.getExtendedName(m_current_);
|
||||
}
|
||||
if (name != null && name.length() > 0) {
|
||||
result.integer = m_current_;
|
||||
result.value = name;
|
||||
return false;
|
||||
}
|
||||
++ m_current_;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group name iteration, iterate all the names in the current 32-group and
|
||||
synchronized(GROUP_OFFSETS_) {
|
||||
synchronized(GROUP_LENGTHS_) {
|
||||
int index = m_name_.getGroupLengths(m_groupIndex_, GROUP_OFFSETS_,
|
||||
GROUP_LENGTHS_);
|
||||
while (m_current_ < limit) {
|
||||
int offset = m_name_.getGroupOffset(m_current_);
|
||||
String name = m_name_.getGroupName(
|
||||
index + GROUP_OFFSETS_[offset],
|
||||
GROUP_LENGTHS_[offset], m_choice_);
|
||||
if ((name == null || name.length() == 0) &&
|
||||
m_choice_ == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
|
||||
name = m_name_.getExtendedName(m_current_);
|
||||
}
|
||||
if (name != null && name.length() > 0) {
|
||||
result.integer = m_current_;
|
||||
result.value = name;
|
||||
return false;
|
||||
}
|
||||
++ m_current_;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group name iteration, iterate all the names in the current 32-group and
|
||||
* returns the first codepoint that has a valid name.
|
||||
* @param result stores the result codepoint and name
|
||||
* @param limit last codepoint + 1 in range to search
|
||||
* @return false if a codepoint with a name is found in group and we can
|
||||
* bail from further iteration, true to continue on with the
|
||||
* iteration
|
||||
* @param result stores the result codepoint and name
|
||||
* @param limit last codepoint + 1 in range to search
|
||||
* @return false if a codepoint with a name is found in group and we can
|
||||
* bail from further iteration, true to continue on with the
|
||||
* iteration
|
||||
*/
|
||||
private boolean iterateGroup(ValueIterator.Element result, int limit)
|
||||
{
|
||||
if (m_groupIndex_ < 0) {
|
||||
m_groupIndex_ = m_name_.getGroup(m_current_);
|
||||
}
|
||||
|
||||
while (m_groupIndex_ < m_name_.m_groupcount_ &&
|
||||
m_current_ < limit) {
|
||||
// iterate till the last group or the last codepoint
|
||||
int startMSB = m_name_.getCodepointMSB(m_current_);
|
||||
int gMSB = m_name_.getGroupMSB(m_groupIndex_); // can be -1
|
||||
if (startMSB == gMSB) {
|
||||
if (startMSB == m_name_.getCodepointMSB(limit - 1)) {
|
||||
// if start and limit - 1 are in the same group, then enumerate
|
||||
// only in that one
|
||||
return iterateSingleGroup(result, limit);
|
||||
}
|
||||
// enumerate characters in the partial start group
|
||||
// if (m_name_.getGroupOffset(m_current_) != 0) {
|
||||
if (!iterateSingleGroup(result,
|
||||
m_name_.getGroupLimit(gMSB))) {
|
||||
return false;
|
||||
if (m_groupIndex_ < 0) {
|
||||
m_groupIndex_ = m_name_.getGroup(m_current_);
|
||||
}
|
||||
|
||||
while (m_groupIndex_ < m_name_.m_groupcount_ &&
|
||||
m_current_ < limit) {
|
||||
// iterate till the last group or the last codepoint
|
||||
int startMSB = m_name_.getCodepointMSB(m_current_);
|
||||
int gMSB = m_name_.getGroupMSB(m_groupIndex_); // can be -1
|
||||
if (startMSB == gMSB) {
|
||||
if (startMSB == m_name_.getCodepointMSB(limit - 1)) {
|
||||
// if start and limit - 1 are in the same group, then enumerate
|
||||
// only in that one
|
||||
return iterateSingleGroup(result, limit);
|
||||
}
|
||||
++ m_groupIndex_; // continue with the next group
|
||||
}
|
||||
else if (startMSB > gMSB) {
|
||||
// make sure that we start enumerating with the first group
|
||||
// after start
|
||||
m_groupIndex_ ++;
|
||||
}
|
||||
else {
|
||||
int gMIN = m_name_.getGroupMin(gMSB);
|
||||
if (gMIN > limit) {
|
||||
gMIN = limit;
|
||||
}
|
||||
if (m_choice_ == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
|
||||
if (!iterateExtended(result, gMIN)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_current_ = gMIN;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate extended names.
|
||||
* @param result stores the result codepoint and name
|
||||
* @param limit last codepoint + 1 in range to search
|
||||
* @return false if a codepoint with a name is found and we can
|
||||
* bail from further iteration, true to continue on with the
|
||||
* iteration (this will always be false for valid codepoints)
|
||||
*/
|
||||
private boolean iterateExtended(ValueIterator.Element result,
|
||||
int limit)
|
||||
{
|
||||
// enumerate characters in the partial start group
|
||||
// if (m_name_.getGroupOffset(m_current_) != 0) {
|
||||
if (!iterateSingleGroup(result,
|
||||
m_name_.getGroupLimit(gMSB))) {
|
||||
return false;
|
||||
}
|
||||
++ m_groupIndex_; // continue with the next group
|
||||
}
|
||||
else if (startMSB > gMSB) {
|
||||
// make sure that we start enumerating with the first group
|
||||
// after start
|
||||
m_groupIndex_ ++;
|
||||
}
|
||||
else {
|
||||
int gMIN = m_name_.getGroupMin(gMSB);
|
||||
if (gMIN > limit) {
|
||||
gMIN = limit;
|
||||
}
|
||||
if (m_choice_ == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
|
||||
if (!iterateExtended(result, gMIN)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_current_ = gMIN;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate extended names.
|
||||
* @param result stores the result codepoint and name
|
||||
* @param limit last codepoint + 1 in range to search
|
||||
* @return false if a codepoint with a name is found and we can
|
||||
* bail from further iteration, true to continue on with the
|
||||
* iteration (this will always be false for valid codepoints)
|
||||
*/
|
||||
private boolean iterateExtended(ValueIterator.Element result,
|
||||
int limit)
|
||||
{
|
||||
while (m_current_ < limit) {
|
||||
String name = m_name_.getExtendedOr10Name(m_current_);
|
||||
if (name != null && name.length() > 0) {
|
||||
String name = m_name_.getExtendedOr10Name(m_current_);
|
||||
if (name != null && name.length() > 0) {
|
||||
result.integer = m_current_;
|
||||
result.value = name;
|
||||
return false;
|
||||
result.value = name;
|
||||
return false;
|
||||
}
|
||||
++ m_current_;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ public final class UScript {
|
||||
*/
|
||||
private static final String copyrightNotice
|
||||
= "Copyright \u00a92001 IBM Corp. All rights reserved.";
|
||||
|
||||
|
||||
/**
|
||||
* Invalid code
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
*/
|
||||
public static final int INVALID_CODE = -1;
|
||||
/**
|
||||
* Common
|
||||
@ -268,24 +268,25 @@ public final class UScript {
|
||||
* Limit
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
public static final int CODE_LIMIT = 46;
|
||||
|
||||
public static final int CODE_LIMIT = 46;
|
||||
|
||||
private static final int SCRIPT_MASK = 0x0000007f;
|
||||
private static final UCharacterProperty prop= UCharacterProperty.getInstance();
|
||||
|
||||
|
||||
private static final String INVALID_NAME = "Invalid";
|
||||
/**
|
||||
* Helper function to find the code from locale.
|
||||
* @param Locale the locale.
|
||||
*/
|
||||
private static int[] findCodeFromLocale(Locale locale) {
|
||||
|
||||
ResourceBundle rb = ICULocaleData.getLocaleElements(locale);
|
||||
|
||||
if (rb==null) {
|
||||
throw new MissingResourceException("Could not find data for {0} {1}", "com.ibm.icu.impl.dataLocaleElements", locale.toString());
|
||||
}
|
||||
// if rb is not a strict fallback of the requested locale, return null
|
||||
if (rb==null || !LocaleUtility.isFallbackOf(rb.getLocale(), locale)) {
|
||||
if(!LocaleUtility.isFallbackOf(rb.getLocale(), locale)){
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] scripts = rb.getStringArray("LocaleScript");
|
||||
int[] result = new int[scripts.length];
|
||||
int w = 0;
|
||||
@ -293,7 +294,7 @@ public final class UScript {
|
||||
int code = UCharacter.getPropertyValueEnum(UProperty.SCRIPT,
|
||||
scripts[i]);
|
||||
result[w++] = code;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (w < result.length) {
|
||||
@ -302,23 +303,23 @@ public final class UScript {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Returns MALAYAM given "Malayam" OR "Mlym".
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* @param locale Locale
|
||||
* @return The script codes array. null if the the code cannot be found.
|
||||
* @return The script codes array. null if the the code cannot be found.
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
public static final int[] getCode(Locale locale){
|
||||
return findCodeFromLocale(locale);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Returns MALAYAM given "Malayam" OR "Mlym".
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
*
|
||||
* <p>Note: To search by short or long script alias only, use
|
||||
* UCharacater.getPropertyValueEnum(UProperty.SCRIPT, alias)
|
||||
@ -339,11 +340,11 @@ public final class UScript {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the script code associated with the given codepoint.
|
||||
* Returns UScript.MALAYAM given 0x0D02
|
||||
* Returns UScript.MALAYAM given 0x0D02
|
||||
* @param codepoint UChar32 codepoint
|
||||
* @return The script code
|
||||
* @return The script code
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
public static final int getScript(int codepoint){
|
||||
@ -351,11 +352,11 @@ public final class UScript {
|
||||
return (int)(prop.getAdditional(codepoint,0) & SCRIPT_MASK);
|
||||
}else{
|
||||
throw new IllegalArgumentException(Integer.toString(codepoint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a script name associated with the given script code.
|
||||
* Gets a script name associated with the given script code.
|
||||
* Returns "Malayam" given MALAYAM
|
||||
* @param scriptCode int script code
|
||||
* @return script name as a string in full as given in TR#24
|
||||
@ -366,11 +367,11 @@ public final class UScript {
|
||||
scriptCode,
|
||||
UProperty.NameChoice.LONG);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a script name associated with the given script code.
|
||||
* Gets a script name associated with the given script code.
|
||||
* Returns "Mlym" given MALAYAM
|
||||
* @param scriptCode int script code
|
||||
* @param scriptCode int script code
|
||||
* @return script abbreviated name as a string as given in TR#24
|
||||
* @stable ICU 2.4
|
||||
*/
|
||||
|
@ -3,8 +3,8 @@
|
||||
* Copyright (c) 2002, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
*****************************************************************
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/AnyTransliterator.java,v $
|
||||
* $Revision: 1.1 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/AnyTransliterator.java,v $
|
||||
* $Revision: 1.2 $
|
||||
*****************************************************************
|
||||
* Date Name Description
|
||||
* 06/06/2002 aliu Creation.
|
||||
@ -17,12 +17,12 @@ import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
/**
|
||||
* A transliterator that translates multiple input scripts to a single
|
||||
* output script. It is named Any-T or Any-T/V, where T is the target
|
||||
* and V is the optional variant. The target T is a script.
|
||||
*
|
||||
*
|
||||
* <p>An AnyTransliterator partitions text into runs of the same
|
||||
* script, together with adjacent COMMON or INHERITED characters.
|
||||
* After determining the script of each run, it transliterates from
|
||||
@ -34,7 +34,7 @@ import java.util.Map;
|
||||
* <p>At startup, all possible AnyTransliterators are registered with
|
||||
* the system, as determined by examining the registered script
|
||||
* transliterators.
|
||||
*
|
||||
*
|
||||
* @since ICU 2.2
|
||||
* @author Alan Liu
|
||||
*/
|
||||
@ -42,13 +42,13 @@ class AnyTransliterator extends Transliterator {
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Constants
|
||||
|
||||
|
||||
static final char TARGET_SEP = '-';
|
||||
static final char VARIANT_SEP = '/';
|
||||
static final String ANY = "Any";
|
||||
static final String NULL_ID = "Null";
|
||||
static final String LATIN_PIVOT = "-Latin;Latin-";
|
||||
|
||||
|
||||
/**
|
||||
* Cache mapping UScriptCode values to Transliterator*.
|
||||
*/
|
||||
@ -132,7 +132,7 @@ class AnyTransliterator extends Transliterator {
|
||||
super(id, null);
|
||||
targetScript = theTargetScript;
|
||||
cache = new HashMap();
|
||||
|
||||
|
||||
target = theTarget;
|
||||
if (theVariant.length() > 0) {
|
||||
target = theTarget + VARIANT_SEP + theVariant;
|
||||
@ -157,10 +157,10 @@ class AnyTransliterator extends Transliterator {
|
||||
if (t == null) {
|
||||
String sourceName = UScript.getName(source);
|
||||
String id = sourceName + TARGET_SEP + target;
|
||||
|
||||
|
||||
t = Transliterator.getInstance(id, FORWARD);
|
||||
if (t == null) {
|
||||
|
||||
|
||||
// Try to pivot around Latin, our most common script
|
||||
id = sourceName + LATIN_PIVOT + target;
|
||||
t = Transliterator.getInstance(id, FORWARD);
|
||||
@ -196,7 +196,7 @@ class AnyTransliterator extends Transliterator {
|
||||
// Only process each target once
|
||||
if (seen.contains(target)) continue;
|
||||
seen.add(target);
|
||||
|
||||
|
||||
// Get the script code for the target. If not a script, ignore.
|
||||
int targetScript = scriptNameToCode(target);
|
||||
if (targetScript == UScript.INVALID_CODE) continue;
|
||||
@ -204,7 +204,7 @@ class AnyTransliterator extends Transliterator {
|
||||
for (Enumeration v=Transliterator.getAvailableVariants(source, target);
|
||||
v.hasMoreElements(); ) {
|
||||
String variant = (String) v.nextElement();
|
||||
|
||||
|
||||
String id;
|
||||
id = TransliteratorIDParser.STVtoID(ANY, target, variant);
|
||||
AnyTransliterator trans = new AnyTransliterator(id, target, variant,
|
||||
@ -221,10 +221,14 @@ class AnyTransliterator extends Transliterator {
|
||||
* UScript.INVALID_CODE if not found.
|
||||
*/
|
||||
private static int scriptNameToCode(String name) {
|
||||
int[] codes = UScript.getCode(name);
|
||||
return codes != null ? codes[0] : UScript.INVALID_CODE;
|
||||
try{
|
||||
int[] codes = UScript.getCode(name);
|
||||
return codes != null ? codes[0] : UScript.INVALID_CODE;
|
||||
}catch( MissingResourceException e){
|
||||
return UScript.INVALID_CODE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
// ScriptRunIterator
|
||||
|
||||
|
@ -5,32 +5,19 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakIterator.java,v $
|
||||
* $Date: 2002/12/12 23:26:56 $
|
||||
* $Revision: 1.14 $
|
||||
* $Date: 2003/01/28 18:55:41 $
|
||||
* $Revision: 1.15 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import com.ibm.icu.impl.ICULocaleData;
|
||||
import com.ibm.icu.impl.ICULocaleService;
|
||||
import com.ibm.icu.impl.ICULocaleService.LocaleKey;
|
||||
import com.ibm.icu.impl.ICULocaleService.ICUResourceBundleFactory;
|
||||
import com.ibm.icu.impl.ICUService;
|
||||
import com.ibm.icu.impl.ICUService.Factory;
|
||||
import com.ibm.icu.impl.ICUService.Key;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.URL;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* A class that locates boundaries in text. This class defines a protocol for
|
||||
@ -558,6 +545,53 @@ public abstract class BreakIterator implements Cloneable
|
||||
return getBreakInstance(where, KIND_TITLE);
|
||||
}
|
||||
|
||||
|
||||
private static Class BI_FACTORY = null;
|
||||
private static Method REGISTER_INSTANCE = null;
|
||||
private static Method UNREGISTER = null;
|
||||
private static Method CREATE_BREAK_INSTANCE = null;
|
||||
private static Method GET_AVAILABLE_LOCALES = null;
|
||||
|
||||
private static final void setupService(){
|
||||
try{
|
||||
// load the class
|
||||
BI_FACTORY = Class.forName("com.ibm.icu.text.BreakIteratorFactory");
|
||||
|
||||
// get the reference to registerInstance method
|
||||
Class[] argTypes = { BreakIterator.class, Locale.class, int.class};
|
||||
REGISTER_INSTANCE = BI_FACTORY.getDeclaredMethod("registerInstance",argTypes);
|
||||
|
||||
// get the reference to unregister method
|
||||
argTypes = new Class[1];
|
||||
argTypes[0] = Object.class;
|
||||
UNREGISTER = BI_FACTORY.getDeclaredMethod("unregisterFactory",argTypes);
|
||||
|
||||
// get the reference to create instance method
|
||||
argTypes = new Class[2];
|
||||
argTypes[0] = Locale.class;
|
||||
argTypes[1] = int.class;
|
||||
|
||||
CREATE_BREAK_INSTANCE = BI_FACTORY.getDeclaredMethod("createBreakInstance",argTypes);
|
||||
|
||||
// get the reference to getAvailableLocales
|
||||
GET_AVAILABLE_LOCALES = BI_FACTORY.getDeclaredMethod("getAvailableLocales",null);
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
private static final Object invoke(Method method, Object[] args){
|
||||
try{
|
||||
|
||||
return method.invoke(null,args);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new break iterator of the indicated kind, to use in the given locale.
|
||||
* Clones of the iterator will be returned
|
||||
@ -570,12 +604,21 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public static Object registerInstance(BreakIterator iter, Locale locale, int kind) {
|
||||
try {
|
||||
return getService().registerObject(iter, locale, kind);
|
||||
/* try {
|
||||
Class[] argTypes = { BreakIterator.class, Locale.class, int.class };
|
||||
Method regInstance = BI_FACTORY.getMethod("registerInstance",argTypes);
|
||||
Object[] args = {iter,locale, new Integer(kind)};
|
||||
return regInstance.invoke(null,args);
|
||||
}
|
||||
catch (IndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException("unknown kind: " + kind);
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}*/
|
||||
Object[] args = {iter,locale, new Integer(kind)};
|
||||
if(BI_FACTORY==null){
|
||||
setupService();
|
||||
}
|
||||
return invoke(REGISTER_INSTANCE,args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -586,44 +629,26 @@ public abstract class BreakIterator implements Cloneable
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public static boolean unregister(Object key) {
|
||||
if (service != null) {
|
||||
return service.unregisterFactory((Factory)key);
|
||||
/*try {
|
||||
Class[] argTypes = { Object.class };
|
||||
Method unregister = BI_FACTORY.getMethod("unregister",argTypes);
|
||||
Object[] args = {key};
|
||||
Boolean retVal = (Boolean) unregister.invoke(null,args);
|
||||
return retVal.booleanValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ICULocaleService service;
|
||||
private static ICULocaleService getService() {
|
||||
if (service == null) {
|
||||
ICULocaleService newService = new ICULocaleService("BreakIterator");
|
||||
|
||||
class RBBreakIteratorFactory extends ICUResourceBundleFactory {
|
||||
protected Object handleCreate(Locale loc, int kind, ICUService service) {
|
||||
return createBreakInstance(loc, kind);
|
||||
}
|
||||
}
|
||||
newService.registerFactory(new RBBreakIteratorFactory());
|
||||
|
||||
synchronized (BreakIterator.class) {
|
||||
if (service == null) {
|
||||
service = newService;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}*/
|
||||
Object[] args = {key};
|
||||
if(BI_FACTORY==null){
|
||||
setupService();
|
||||
}
|
||||
return service;
|
||||
return ((Boolean)invoke(UNREGISTER,args)).booleanValue();
|
||||
}
|
||||
|
||||
private static final String[] KIND_NAMES = {
|
||||
"Character", "Word", "Line", "Sentence", "Title"
|
||||
};
|
||||
|
||||
private static BreakIterator createBreakInstance(Locale locale, int kind) {
|
||||
String prefix = KIND_NAMES[kind];
|
||||
return createBreakInstance(locale,
|
||||
kind,
|
||||
prefix + "BreakRules",
|
||||
prefix + "BreakDictionary");
|
||||
}
|
||||
|
||||
|
||||
// end of registration
|
||||
|
||||
@ -637,47 +662,18 @@ public abstract class BreakIterator implements Cloneable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BreakIterator result = createBreakInstance(where, kind);
|
||||
Object[] args = new Object[]{where, new Integer(kind)};
|
||||
|
||||
if(BI_FACTORY==null){
|
||||
setupService();
|
||||
}
|
||||
BreakIterator result = (BreakIterator)invoke(CREATE_BREAK_INSTANCE,
|
||||
args);
|
||||
BreakIteratorCache cache = new BreakIteratorCache(where, result);
|
||||
iterCache[kind] = new SoftReference(cache);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BreakIterator createBreakInstance(Locale where,
|
||||
int kind,
|
||||
String rulesName,
|
||||
String dictionaryName) {
|
||||
|
||||
// System.out.println("rulesName: "+rulesName);
|
||||
// System.out.println("dictionaryName: "+dictionaryName);
|
||||
ResourceBundle bundle = ICULocaleData.getResourceBundle("BreakIteratorRules", where);
|
||||
String[] classNames = bundle.getStringArray("BreakIteratorClasses");
|
||||
|
||||
String rules = bundle.getString(rulesName);
|
||||
|
||||
if (classNames[kind].equals("RuleBasedBreakIterator")) {
|
||||
return new RuleBasedBreakIterator(rules);
|
||||
}
|
||||
else if (classNames[kind].equals("DictionaryBasedBreakIterator")) {
|
||||
try {
|
||||
// System.out.println(dictionaryName);
|
||||
Object t = bundle.getObject(dictionaryName);
|
||||
// System.out.println(t);
|
||||
URL url = (URL)t;
|
||||
InputStream dictionary = url.openStream();
|
||||
return new DictionaryBasedBreakIterator(rules, dictionary);
|
||||
}
|
||||
catch(IOException e) {
|
||||
}
|
||||
catch(MissingResourceException e) {
|
||||
}
|
||||
return new RuleBasedBreakIterator(rules);
|
||||
}
|
||||
else
|
||||
throw new IllegalArgumentException("Invalid break iterator class \"" +
|
||||
classNames[kind] + "\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of locales for which BreakIterators can be used.
|
||||
@ -686,11 +682,10 @@ public abstract class BreakIterator implements Cloneable
|
||||
*/
|
||||
public static synchronized Locale[] getAvailableLocales()
|
||||
{
|
||||
if (service == null) {
|
||||
return ICULocaleData.getAvailableLocales();
|
||||
} else {
|
||||
return service.getAvailableLocales();
|
||||
if(BI_FACTORY==null){
|
||||
setupService();
|
||||
}
|
||||
return (Locale[]) invoke(GET_AVAILABLE_LOCALES, null);
|
||||
}
|
||||
|
||||
private static final class BreakIteratorCache {
|
||||
|
126
icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java
Normal file
126
icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2002-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java,v $
|
||||
* $Date: 2003/01/28 18:55:41 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.ibm.icu.impl.ICULocaleData;
|
||||
import com.ibm.icu.impl.ICULocaleService;
|
||||
import com.ibm.icu.impl.ICULocaleService.LocaleKey;
|
||||
import com.ibm.icu.impl.ICULocaleService.ICUResourceBundleFactory;
|
||||
import com.ibm.icu.impl.ICUService;
|
||||
import com.ibm.icu.impl.ICUService.Factory;
|
||||
import com.ibm.icu.impl.ICUService.Key;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
|
||||
|
||||
/**
|
||||
* @author Ram
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
class BreakIteratorFactory {
|
||||
private static ICULocaleService service;
|
||||
static ICULocaleService getService() {
|
||||
if (service == null) {
|
||||
ICULocaleService newService = new ICULocaleService("BreakIterator");
|
||||
|
||||
class RBBreakIteratorFactory extends ICUResourceBundleFactory {
|
||||
protected Object handleCreate(Locale loc, int kind, ICUService service) {
|
||||
return createBreakInstance(loc, kind);
|
||||
}
|
||||
}
|
||||
newService.registerFactory(new RBBreakIteratorFactory());
|
||||
|
||||
synchronized (BreakIterator.class) {
|
||||
if (service == null) {
|
||||
service = newService;
|
||||
}
|
||||
}
|
||||
}
|
||||
return service;
|
||||
}
|
||||
static boolean unregisterFactory(Object key) {
|
||||
if (service != null) {
|
||||
return service.unregisterFactory((Factory)key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static synchronized Locale[] getAvailableLocales()
|
||||
{
|
||||
if (service == null) {
|
||||
return ICULocaleData.getAvailableLocales();
|
||||
} else {
|
||||
return service.getAvailableLocales();
|
||||
}
|
||||
}
|
||||
|
||||
static Object registerInstance(BreakIterator iter, Locale locale, int kind){
|
||||
return getService().registerObject(iter, locale, kind);
|
||||
}
|
||||
|
||||
static BreakIterator createBreakInstance(Locale where,
|
||||
int kind,
|
||||
String rulesName,
|
||||
String dictionaryName) {
|
||||
|
||||
// System.out.println("rulesName: "+rulesName);
|
||||
// System.out.println("dictionaryName: "+dictionaryName);
|
||||
ResourceBundle bundle = ICULocaleData.getResourceBundle("BreakIteratorRules", where);
|
||||
String[] classNames = bundle.getStringArray("BreakIteratorClasses");
|
||||
|
||||
String rules = bundle.getString(rulesName);
|
||||
|
||||
if (classNames[kind].equals("RuleBasedBreakIterator")) {
|
||||
return new RuleBasedBreakIterator(rules);
|
||||
}
|
||||
else if (classNames[kind].equals("DictionaryBasedBreakIterator")) {
|
||||
try {
|
||||
// System.out.println(dictionaryName);
|
||||
Object t = bundle.getObject(dictionaryName);
|
||||
// System.out.println(t);
|
||||
URL url = (URL)t;
|
||||
InputStream dictionary = url.openStream();
|
||||
return new DictionaryBasedBreakIterator(rules, dictionary);
|
||||
}
|
||||
catch(IOException e) {
|
||||
}
|
||||
catch(MissingResourceException e) {
|
||||
}
|
||||
return new RuleBasedBreakIterator(rules);
|
||||
}
|
||||
else
|
||||
throw new IllegalArgumentException("Invalid break iterator class \"" +
|
||||
classNames[kind] + "\"");
|
||||
}
|
||||
private static final String[] KIND_NAMES = {
|
||||
"Character", "Word", "Line", "Sentence", "Title"
|
||||
};
|
||||
|
||||
static BreakIterator createBreakInstance(Locale locale, int kind) {
|
||||
String prefix = KIND_NAMES[kind];
|
||||
|
||||
return createBreakInstance( locale, kind,
|
||||
prefix + "BreakRules",
|
||||
prefix + "BreakDictionary" );
|
||||
}
|
||||
}
|
@ -4,21 +4,18 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakTransliterator.java,v $
|
||||
* $Date: 2002/11/22 00:29:00 $
|
||||
* $Revision: 1.3 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakTransliterator.java,v $
|
||||
* $Date: 2003/01/28 18:55:41 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.text;
|
||||
//import com.ibm.icu.dev.demo.impl.*;
|
||||
//import com.ibm.icu.lang.*;
|
||||
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import java.util.Locale;
|
||||
import java.text.CharacterIterator;
|
||||
//import java.util.*;
|
||||
//import java.util.ArrayList;
|
||||
//import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the specified characters at word breaks. To restrict it to particular characters, use a filter.
|
||||
@ -29,35 +26,35 @@ final class BreakTransliterator extends Transliterator {
|
||||
private String insertion;
|
||||
private int[] boundaries = new int[50];
|
||||
private int boundaryCount = 0;
|
||||
|
||||
|
||||
public BreakTransliterator(String ID, UnicodeFilter filter, BreakIterator bi, String insertion) {
|
||||
super(ID, filter);
|
||||
if (bi == null) bi = BreakIterator.getWordInstance(new Locale("th", "TH"));
|
||||
if (bi == null) bi = (BreakIterator) BreakIterator.getWordInstance(new Locale("th", "TH"));
|
||||
this.bi = bi;
|
||||
this.insertion = insertion;
|
||||
}
|
||||
|
||||
|
||||
public BreakTransliterator(String ID, UnicodeFilter filter) {
|
||||
this(ID, filter, null, " ");
|
||||
}
|
||||
|
||||
|
||||
public String getInsertion() {
|
||||
return insertion;
|
||||
}
|
||||
|
||||
|
||||
public void setInsertion(String insertion) {
|
||||
this.insertion = insertion;
|
||||
}
|
||||
|
||||
|
||||
public BreakIterator getBreakIterator() {
|
||||
return bi;
|
||||
}
|
||||
|
||||
|
||||
public void setBreakIterator(BreakIterator bi) {
|
||||
this.bi = bi;
|
||||
}
|
||||
|
||||
static final int LETTER_OR_MARK_MASK =
|
||||
|
||||
static final int LETTER_OR_MARK_MASK =
|
||||
(1<<Character.UPPERCASE_LETTER)
|
||||
| (1<<Character.LOWERCASE_LETTER)
|
||||
| (1<<Character.TITLECASE_LETTER)
|
||||
@ -78,10 +75,10 @@ final class BreakTransliterator extends Transliterator {
|
||||
bi.setText(new StringCharacterIterator(new String(tempBuffer), pos.start, pos.limit, pos.start));
|
||||
*/
|
||||
// end debugging
|
||||
|
||||
|
||||
// To make things much easier, we will stack the boundaries, and then insert at the end.
|
||||
// generally, we won't need too many, since we will be filtered.
|
||||
|
||||
|
||||
for(boundary = bi.first(); boundary != bi.DONE && boundary < pos.limit; boundary = bi.next()) {
|
||||
if (boundary == 0) continue;
|
||||
// HACK: Check to see that preceeding item was a letter
|
||||
@ -90,44 +87,44 @@ final class BreakTransliterator extends Transliterator {
|
||||
int type = UCharacter.getType(cp);
|
||||
//System.out.println(Integer.toString(cp,16) + " (before): " + type);
|
||||
if (((1<<type) & LETTER_OR_MARK_MASK) == 0) continue;
|
||||
|
||||
|
||||
cp = UTF16.charAt(text, boundary);
|
||||
type = UCharacter.getType(cp);
|
||||
//System.out.println(Integer.toString(cp,16) + " (after): " + type);
|
||||
if (((1<<type) & LETTER_OR_MARK_MASK) == 0) continue;
|
||||
|
||||
|
||||
if (boundaryCount >= boundaries.length) { // realloc if necessary
|
||||
int[] temp = new int[boundaries.length * 2];
|
||||
System.arraycopy(boundaries, 0, temp, 0, boundaries.length);
|
||||
boundaries = temp;
|
||||
}
|
||||
|
||||
|
||||
boundaries[boundaryCount++] = boundary;
|
||||
//System.out.println(boundary);
|
||||
}
|
||||
|
||||
|
||||
int delta = 0;
|
||||
int lastBoundary = 0;
|
||||
|
||||
|
||||
if (boundaryCount != 0) { // if we found something, adjust
|
||||
delta = boundaryCount * insertion.length();
|
||||
lastBoundary = boundaries[boundaryCount-1];
|
||||
|
||||
|
||||
// we do this from the end backwards, so that we don't have to keep updating.
|
||||
|
||||
|
||||
while (boundaryCount > 0) {
|
||||
boundary = boundaries[--boundaryCount];
|
||||
text.replace(boundary, boundary, insertion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now fix up the return values
|
||||
pos.contextLimit += delta;
|
||||
pos.limit += delta;
|
||||
pos.start = incremental ? lastBoundary + delta : pos.limit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Registers standard variants with the system. Called by
|
||||
* Transliterator during initialization.
|
||||
@ -144,9 +141,9 @@ final class BreakTransliterator extends Transliterator {
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
// Hack, just to get a real character iterator.
|
||||
|
||||
|
||||
static final class ReplaceableCharacterIterator implements CharacterIterator
|
||||
{
|
||||
private Replaceable text;
|
||||
@ -384,5 +381,5 @@ final class BreakTransliterator extends Transliterator {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,9 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CanonicalIterator.java,v $
|
||||
* $Date: 2002/09/17 19:11:52 $
|
||||
* $Revision: 1.12 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CanonicalIterator.java,v $
|
||||
* $Date: 2003/01/28 18:55:41 $
|
||||
* $Revision: 1.13 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -16,6 +16,8 @@ import com.ibm.icu.lang.*;
|
||||
import java.util.*;
|
||||
import com.ibm.icu.impl.NormalizerImpl;
|
||||
import com.ibm.icu.impl.USerializedSet;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
|
||||
/**
|
||||
* This class allows one to iterate through all the strings that are canonically equivalent to a given
|
||||
* string. For example, here are some sample results:
|
||||
@ -44,24 +46,24 @@ public final class CanonicalIterator {
|
||||
/**
|
||||
* Construct a CanonicalIterator object
|
||||
* @param source string to get results for
|
||||
* @draft ICU 2.4
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public CanonicalIterator(String source) {
|
||||
setSource(source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the NFD form of the current source we are iterating over.
|
||||
* @return gets the source: NOTE: it is the NFD form of the source originally passed in
|
||||
* @draft ICU 2.4
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the iterator so that one can start again from the beginning.
|
||||
* @draft ICU 2.4
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public void reset() {
|
||||
done = false;
|
||||
@ -69,27 +71,27 @@ public final class CanonicalIterator {
|
||||
current[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next canonically equivalent string.
|
||||
* <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
|
||||
* <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
|
||||
* @return the next string that is canonically equivalent. The value null is returned when
|
||||
* the iteration is done.
|
||||
* @draft ICU 2.4
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public String next() {
|
||||
if (done) return null;
|
||||
|
||||
|
||||
// construct return value
|
||||
|
||||
|
||||
buffer.setLength(0); // delete old contents
|
||||
for (int i = 0; i < pieces.length; ++i) {
|
||||
buffer.append(pieces[i][current[i]]);
|
||||
}
|
||||
String result = buffer.toString();
|
||||
|
||||
|
||||
// find next value for next time
|
||||
|
||||
|
||||
for (int i = current.length - 1; ; --i) {
|
||||
if (i < 0) {
|
||||
done = true;
|
||||
@ -101,34 +103,34 @@ public final class CanonicalIterator {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a new source for this iterator. Allows object reuse.
|
||||
* @param set the source string to iterate against. This allows the same iterator to be used
|
||||
* while changing the source string, saving object creation.
|
||||
* @draft ICU 2.4
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public void setSource(String newSource) {
|
||||
source = Normalizer.normalize(newSource, Normalizer.NFD);
|
||||
done = false;
|
||||
|
||||
|
||||
// catch degenerate case
|
||||
if (newSource.length() == 0) {
|
||||
pieces = new String[1][];
|
||||
current = new int[1];
|
||||
pieces[0] = new String[]{""};
|
||||
return;
|
||||
}
|
||||
|
||||
if (newSource.length() == 0) {
|
||||
pieces = new String[1][];
|
||||
current = new int[1];
|
||||
pieces[0] = new String[]{""};
|
||||
return;
|
||||
}
|
||||
|
||||
// find the segments
|
||||
List list = new ArrayList();
|
||||
int cp;
|
||||
int start = 0;
|
||||
|
||||
// i should be the end of the first code point
|
||||
|
||||
int i = UTF16.findOffsetFromCodePoint(source, 1);
|
||||
|
||||
|
||||
// i should be the end of the first code point
|
||||
|
||||
int i = UTF16.findOffsetFromCodePoint(source, 1);
|
||||
|
||||
for (; i < source.length(); i += UTF16.getCharCount(i)) {
|
||||
cp = UTF16.charAt(source, i);
|
||||
if (NormalizerImpl.isCanonSafeStart(cp)) {
|
||||
@ -137,7 +139,7 @@ public final class CanonicalIterator {
|
||||
}
|
||||
}
|
||||
list.add(source.substring(start, i)); // add last one
|
||||
|
||||
|
||||
// allocate the arrays, and find the strings that are CE to each segment
|
||||
pieces = new String[list.size()][];
|
||||
current = new int[list.size()];
|
||||
@ -146,18 +148,18 @@ public final class CanonicalIterator {
|
||||
pieces[i] = getEquivalents((String) list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple implementation of permutation.
|
||||
* <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
|
||||
* Simple implementation of permutation.
|
||||
* <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
|
||||
* @param source the string to find permutations for
|
||||
* @param the set to add the results to
|
||||
* @internal
|
||||
*/
|
||||
public static void permute(String source, boolean skipZeros, Set output) {
|
||||
// TODO: optimize
|
||||
// TODO: optimize
|
||||
//if (PROGRESS) System.out.println("Permute: " + source);
|
||||
|
||||
|
||||
// optimization:
|
||||
// if zero or one character, just return a set with it
|
||||
// we check for length < 2 to keep from counting code points all the time
|
||||
@ -165,26 +167,26 @@ public final class CanonicalIterator {
|
||||
output.add(source);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// otherwise iterate through the string, and recursively permute all the other characters
|
||||
Set subpermute = new HashSet();
|
||||
int cp;
|
||||
for (int i = 0; i < source.length(); i += UTF16.getCharCount(cp)) {
|
||||
cp = UTF16.charAt(source, i);
|
||||
|
||||
// optimization:
|
||||
// if the character is canonical combining class zero,
|
||||
// don't permute it
|
||||
if (skipZeros && i != 0 && UCharacter.getCombiningClass(cp) == 0) {
|
||||
//System.out.println("Skipping " + Utility.hex(UTF16.valueOf(source, i)));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// optimization:
|
||||
// if the character is canonical combining class zero,
|
||||
// don't permute it
|
||||
if (skipZeros && i != 0 && UCharacter.getCombiningClass(cp) == 0) {
|
||||
//System.out.println("Skipping " + Utility.hex(UTF16.valueOf(source, i)));
|
||||
continue;
|
||||
}
|
||||
|
||||
// see what the permutations of the characters before and after this one are
|
||||
subpermute.clear();
|
||||
permute(source.substring(0,i)
|
||||
+ source.substring(i + UTF16.getCharCount(cp)), skipZeros, subpermute);
|
||||
|
||||
permute(source.substring(0,i)
|
||||
+ source.substring(i + UTF16.getCharCount(cp)), skipZeros, subpermute);
|
||||
|
||||
// prefix this character to all of them
|
||||
String chStr = UTF16.valueOf(source, i);
|
||||
Iterator it = subpermute.iterator();
|
||||
@ -196,9 +198,9 @@ public final class CanonicalIterator {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// FOR TESTING
|
||||
|
||||
|
||||
/**
|
||||
*@return the set of "safe starts", characters that are class zero AND are never non-initial in a decomposition.
|
||||
*@internal
|
||||
@ -217,14 +219,14 @@ public final class CanonicalIterator {
|
||||
return (UnicodeSet) result.clone();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// ===================== PRIVATES ==============================
|
||||
|
||||
|
||||
// debug
|
||||
private static boolean PROGRESS = false; // debug progress
|
||||
private static Transliterator NAME = PROGRESS ? Transliterator.getInstance("name") : null;
|
||||
//private static Transliterator NAME = PROGRESS ? Transliterator.getInstance("name") : null;
|
||||
private static boolean SKIP_ZEROS = true;
|
||||
|
||||
|
||||
// fields
|
||||
private String source;
|
||||
private boolean done;
|
||||
@ -233,108 +235,108 @@ public final class CanonicalIterator {
|
||||
// Note: C will need two more fields, since arrays there don't have lengths
|
||||
// int pieces_length;
|
||||
// int[] pieces_lengths;
|
||||
|
||||
|
||||
// transient fields
|
||||
private transient StringBuffer buffer = new StringBuffer();
|
||||
|
||||
|
||||
|
||||
|
||||
// we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
|
||||
private String[] getEquivalents(String segment) {
|
||||
Set result = new HashSet();
|
||||
Set basic = getEquivalents2(segment);
|
||||
Set permutations = new HashSet();
|
||||
|
||||
|
||||
// now get all the permutations
|
||||
// add only the ones that are canonically equivalent
|
||||
// TODO: optimize by not permuting any class zero.
|
||||
Iterator it = basic.iterator();
|
||||
while (it.hasNext()) {
|
||||
String item = (String) it.next();
|
||||
permutations.clear();
|
||||
permutations.clear();
|
||||
permute(item, SKIP_ZEROS, permutations);
|
||||
Iterator it2 = permutations.iterator();
|
||||
while (it2.hasNext()) {
|
||||
String possible = (String) it2.next();
|
||||
|
||||
/*
|
||||
String attempt = Normalizer.normalize(possible, Normalizer.DECOMP, 0);
|
||||
if (attempt.equals(segment)) {
|
||||
|
||||
/*
|
||||
String attempt = Normalizer.normalize(possible, Normalizer.DECOMP, 0);
|
||||
if (attempt.equals(segment)) {
|
||||
*/
|
||||
if (Normalizer.compare(possible, segment,0)==0) {
|
||||
|
||||
if (PROGRESS) System.out.println("Adding Permutation: " + NAME.transliterate(possible));
|
||||
result.add(possible);
|
||||
|
||||
if (PROGRESS) System.out.println("Adding Permutation: " + Utility.hex(possible));
|
||||
result.add(possible);
|
||||
|
||||
} else {
|
||||
if (PROGRESS) System.out.println("-Skipping Permutation: " + NAME.transliterate(possible));
|
||||
if (PROGRESS) System.out.println("-Skipping Permutation: " + Utility.hex(possible));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// convert into a String[] to clean up storage
|
||||
String[] finalResult = new String[result.size()];
|
||||
result.toArray(finalResult);
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Set getEquivalents2(String segment) {
|
||||
|
||||
|
||||
Set result = new HashSet();
|
||||
|
||||
if (PROGRESS) System.out.println("Adding: " + NAME.transliterate(segment));
|
||||
|
||||
|
||||
if (PROGRESS) System.out.println("Adding: " + Utility.hex(segment));
|
||||
|
||||
result.add(segment);
|
||||
StringBuffer workingBuffer = new StringBuffer();
|
||||
|
||||
|
||||
// cycle through all the characters
|
||||
int cp=0,end=0;
|
||||
int[] range = new int[2];
|
||||
int[] range = new int[2];
|
||||
for (int i = 0; i < segment.length(); i += UTF16.getCharCount(cp)) {
|
||||
|
||||
// see if any character is at the start of some decomposition
|
||||
cp = UTF16.charAt(segment, i);;
|
||||
USerializedSet starts = new USerializedSet();
|
||||
|
||||
|
||||
// see if any character is at the start of some decomposition
|
||||
cp = UTF16.charAt(segment, i);;
|
||||
USerializedSet starts = new USerializedSet();
|
||||
|
||||
if (!NormalizerImpl.getCanonStartSet(cp, starts)) {
|
||||
continue;
|
||||
}
|
||||
int j=0;
|
||||
// if so, see which decompositions match
|
||||
for(j = 0, cp = end+1; cp <= end ||starts.getSerializedRange(j++, range); ++cp) {
|
||||
continue;
|
||||
}
|
||||
int j=0;
|
||||
// if so, see which decompositions match
|
||||
for(j = 0, cp = end+1; cp <= end ||starts.getSerializedRange(j++, range); ++cp) {
|
||||
if(cp>end){
|
||||
cp=range[0];
|
||||
end=range[1];
|
||||
}
|
||||
|
||||
Set remainder = extract(cp, segment, i,workingBuffer);
|
||||
if (remainder == null) continue;
|
||||
|
||||
// there were some matches, so add all the possibilities to the set.
|
||||
String prefix= segment.substring(0,i);
|
||||
prefix += UTF16.valueOf(cp);
|
||||
int el = -1;
|
||||
Iterator iter = remainder.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String item = (String) iter.next();
|
||||
String toAdd = new String(prefix);
|
||||
toAdd += item;
|
||||
result.add(toAdd);
|
||||
//if (PROGRESS) printf("Adding: %s\n", UToS(Tr(*toAdd)));
|
||||
}
|
||||
|
||||
Set remainder = extract(cp, segment, i,workingBuffer);
|
||||
if (remainder == null) continue;
|
||||
|
||||
// there were some matches, so add all the possibilities to the set.
|
||||
String prefix= segment.substring(0,i);
|
||||
prefix += UTF16.valueOf(cp);
|
||||
int el = -1;
|
||||
Iterator iter = remainder.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String item = (String) iter.next();
|
||||
String toAdd = new String(prefix);
|
||||
toAdd += item;
|
||||
result.add(toAdd);
|
||||
//if (PROGRESS) printf("Adding: %s\n", UToS(Tr(*toAdd)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
/*
|
||||
Set result = new HashSet();
|
||||
if (PROGRESS) System.out.println("Adding: " + NAME.transliterate(segment));
|
||||
result.add(segment);
|
||||
StringBuffer workingBuffer = new StringBuffer();
|
||||
|
||||
|
||||
// cycle through all the characters
|
||||
int cp;
|
||||
|
||||
|
||||
for (int i = 0; i < segment.length(); i += UTF16.getCharCount(cp)) {
|
||||
// see if any character is at the start of some decomposition
|
||||
cp = UTF16.charAt(segment, i);
|
||||
@ -349,7 +351,7 @@ public final class CanonicalIterator {
|
||||
// so we don't have to check CharacterIterator.IS_STRING
|
||||
Set remainder = extract(cp2, segment, i, workingBuffer);
|
||||
if (remainder == null) continue;
|
||||
|
||||
|
||||
// there were some matches, so add all the possibilities to the set.
|
||||
String prefix = segment.substring(0, i) + UTF16.valueOf(cp2);
|
||||
Iterator it = remainder.iterator();
|
||||
@ -363,19 +365,19 @@ public final class CanonicalIterator {
|
||||
return result;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See if the decomposition of cp2 is at segment starting at segmentPos
|
||||
* See if the decomposition of cp2 is at segment starting at segmentPos
|
||||
* (with canonical rearrangment!)
|
||||
* If so, take the remainder, and return the equivalents
|
||||
* If so, take the remainder, and return the equivalents
|
||||
*/
|
||||
private Set extract(int comp, String segment, int segmentPos, StringBuffer buffer) {
|
||||
if (PROGRESS) System.out.println(" extract: " + NAME.transliterate(UTF16.valueOf(comp))
|
||||
+ ", " + NAME.transliterate(segment.substring(segmentPos)));
|
||||
|
||||
if (PROGRESS) System.out.println(" extract: " + Utility.hex(UTF16.valueOf(comp))
|
||||
+ ", " + Utility.hex(segment.substring(segmentPos)));
|
||||
|
||||
//String decomp = Normalizer.normalize(UTF16.valueOf(comp), Normalizer.DECOMP, 0);
|
||||
String decomp = Normalizer.normalize(comp, Normalizer.NFD);
|
||||
|
||||
|
||||
// See if it matches the start of segment (at segmentPos)
|
||||
boolean ok = false;
|
||||
int cp;
|
||||
@ -384,11 +386,11 @@ public final class CanonicalIterator {
|
||||
decompPos += UTF16.getCharCount(decompCp); // adjust position to skip first char
|
||||
//int decompClass = getClass(decompCp);
|
||||
buffer.setLength(0); // initialize working buffer, shared among callees
|
||||
|
||||
|
||||
for (int i = segmentPos; i < segment.length(); i += UTF16.getCharCount(cp)) {
|
||||
cp = UTF16.charAt(segment, i);
|
||||
if (cp == decompCp) { // if equal, eat another cp from decomp
|
||||
if (PROGRESS) System.out.println(" matches: " + NAME.transliterate(UTF16.valueOf(cp)));
|
||||
if (PROGRESS) System.out.println(" matches: " + Utility.hex(UTF16.valueOf(cp)));
|
||||
if (decompPos == decomp.length()) { // done, have all decomp characters!
|
||||
buffer.append(segment.substring(i + UTF16.getCharCount(cp))); // add remaining segment chars
|
||||
ok = true;
|
||||
@ -398,7 +400,7 @@ public final class CanonicalIterator {
|
||||
decompPos += UTF16.getCharCount(decompCp);
|
||||
//decompClass = getClass(decompCp);
|
||||
} else {
|
||||
if (PROGRESS) System.out.println(" buffer: " + NAME.transliterate(UTF16.valueOf(cp)));
|
||||
if (PROGRESS) System.out.println(" buffer: " + Utility.hex(UTF16.valueOf(cp)));
|
||||
// brute force approach
|
||||
UTF16.append(buffer, cp);
|
||||
/* TODO: optimize
|
||||
@ -408,7 +410,7 @@ public final class CanonicalIterator {
|
||||
// there are only a few cases that work: zero, less, same, greater
|
||||
// if both classes are the same, we fail
|
||||
// if the decomp class < the segment class, we fail
|
||||
|
||||
|
||||
segClass = getClass(cp);
|
||||
if (decompClass <= segClass) return null;
|
||||
*/
|
||||
@ -418,20 +420,20 @@ public final class CanonicalIterator {
|
||||
if (PROGRESS) System.out.println("Matches");
|
||||
if (buffer.length() == 0) return SET_WITH_NULL_STRING; // succeed, but no remainder
|
||||
String remainder = buffer.toString();
|
||||
|
||||
|
||||
// brute force approach
|
||||
// to check to make sure result is canonically equivalent
|
||||
/*
|
||||
String trial = Normalizer.normalize(UTF16.valueOf(comp) + remainder, Normalizer.DECOMP, 0);
|
||||
if (!segment.regionMatches(segmentPos, trial, 0, segment.length() - segmentPos)) return null;
|
||||
*/
|
||||
|
||||
|
||||
if (0!=Normalizer.compare(UTF16.valueOf(comp) + remainder, segment.substring(segmentPos), 0)) return null;
|
||||
|
||||
|
||||
// get the remaining combinations
|
||||
return getEquivalents2(remainder);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// TODO: fix once we have a codepoint interface to get the canonical combining class
|
||||
// TODO: Need public access to canonical combining class in UCharacter!
|
||||
@ -439,19 +441,19 @@ public final class CanonicalIterator {
|
||||
return Normalizer.getClass((char)cp);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// ================= BUILDER =========================
|
||||
// TODO: Flatten this data so it doesn't have to be reconstructed each time!
|
||||
|
||||
|
||||
private static final UnicodeSet EMPTY = new UnicodeSet(); // constant, don't change
|
||||
private static final Set SET_WITH_NULL_STRING = new HashSet(); // constant, don't change
|
||||
static {
|
||||
SET_WITH_NULL_STRING.add("");
|
||||
}
|
||||
|
||||
|
||||
// private static UnicodeSet SAFE_START = new UnicodeSet();
|
||||
// private static CharMap AT_START = new CharMap();
|
||||
|
||||
|
||||
// TODO: WARNING, NORMALIZER doesn't have supplementaries yet !!;
|
||||
// Change FFFF to 10FFFF in C, and in Java when normalizer is upgraded.
|
||||
// private static int LAST_UNICODE = 0x10FFFF;
|
||||
@ -471,19 +473,19 @@ public final class CanonicalIterator {
|
||||
// will fix to be really safe below
|
||||
}
|
||||
if (PROGRESS) System.out.println();
|
||||
|
||||
|
||||
if (PROGRESS) System.out.println("Getting Containment");
|
||||
for (int cp = 0; cp <= LAST_UNICODE; ++cp) {
|
||||
if (PROGRESS & (cp & 0x7FF) == 0) System.out.print('.');
|
||||
|
||||
|
||||
if (Normalizer.isNormalized(cp, Normalizer.NFD)) continue;
|
||||
|
||||
//String istr = UTF16.valueOf(cp);
|
||||
String decomp = Normalizer.normalize(cp, Normalizer.NFD);
|
||||
//if (decomp.equals(istr)) continue;
|
||||
|
||||
// add each character in the decomposition to canBeIn
|
||||
|
||||
|
||||
// add each character in the decomposition to canBeIn
|
||||
|
||||
int component;
|
||||
for (int i = 0; i < decomp.length(); i += UTF16.getCharCount(component)) {
|
||||
component = UTF16.charAt(decomp, i);
|
||||
@ -497,12 +499,12 @@ public final class CanonicalIterator {
|
||||
if (PROGRESS) System.out.println();
|
||||
}
|
||||
// the following is just for a map from characters to a set of characters
|
||||
|
||||
|
||||
private static class CharMap {
|
||||
Map storage = new HashMap();
|
||||
MutableInt probe = new MutableInt();
|
||||
boolean converted = false;
|
||||
|
||||
|
||||
public void add(int cp, int whatItIsIn) {
|
||||
UnicodeSet result = (UnicodeSet) storage.get(probe.set(cp));
|
||||
if (result == null) {
|
||||
@ -511,12 +513,12 @@ public final class CanonicalIterator {
|
||||
}
|
||||
result.add(whatItIsIn);
|
||||
}
|
||||
|
||||
|
||||
public UnicodeSet get(int cp) {
|
||||
return (UnicodeSet) storage.get(probe.set(cp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class MutableInt {
|
||||
public int contents;
|
||||
public int hashCode() { return contents; }
|
||||
@ -532,4 +534,3 @@ public final class CanonicalIterator {
|
||||
*/
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,9 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Collator.java,v $
|
||||
* $Date: 2002/12/11 23:36:58 $
|
||||
* $Revision: 1.19 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Collator.java,v $
|
||||
* $Date: 2003/01/28 18:55:41 $
|
||||
* $Revision: 1.20 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -26,64 +26,64 @@ import com.ibm.icu.impl.ICUService.Factory;
|
||||
* <p>Collator performs locale-sensitive string comparison. A concrete
|
||||
* subclass, RuleBasedCollator, allows customization of the collation
|
||||
* ordering by the use of rule sets.</p>
|
||||
*
|
||||
*
|
||||
* <p>Following the <a href=http://www.unicode.org>Unicode
|
||||
* Consortium</a>'s specifications for the
|
||||
* Consortium</a>'s specifications for the
|
||||
* <a href="http://www.unicode.org/unicode/reports/tr10/"> Unicode Collation
|
||||
* Algorithm (UCA)</a>, there are 5 different levels of strength used
|
||||
* in comparisons:
|
||||
*
|
||||
* <ul>
|
||||
* <li>PRIMARY strength: Typically, this is used to denote differences between
|
||||
* base characters (for example, "a" < "b").
|
||||
* It is the strongest difference. For example, dictionaries are divided
|
||||
* into different sections by base character.
|
||||
* <li>SECONDARY strength: Accents in the characters are considered secondary
|
||||
* differences (for example, "as" < "às" < "at"). Other
|
||||
* differences
|
||||
* between letters can also be considered secondary differences, depending
|
||||
* on the language. A secondary difference is ignored when there is a
|
||||
* <li>PRIMARY strength: Typically, this is used to denote differences between
|
||||
* base characters (for example, "a" < "b").
|
||||
* It is the strongest difference. For example, dictionaries are divided
|
||||
* into different sections by base character.
|
||||
* <li>SECONDARY strength: Accents in the characters are considered secondary
|
||||
* differences (for example, "as" < "às" < "at"). Other
|
||||
* differences
|
||||
* between letters can also be considered secondary differences, depending
|
||||
* on the language. A secondary difference is ignored when there is a
|
||||
* primary difference anywhere in the strings.
|
||||
* <li>TERTIARY strength: Upper and lower case differences in characters are
|
||||
* distinguished at tertiary strength (for example, "ao" < "Ao" <
|
||||
* "aò"). In addition, a variant of a letter differs from the base
|
||||
* form on the tertiary strength (such as "A" and "Ⓐ"). Another
|
||||
* example is the
|
||||
* difference between large and small Kana. A tertiary difference is ignored
|
||||
* when there is a primary or secondary difference anywhere in the strings.
|
||||
* <li>QUATERNARY strength: When punctuation is ignored
|
||||
* <li>TERTIARY strength: Upper and lower case differences in characters are
|
||||
* distinguished at tertiary strength (for example, "ao" < "Ao" <
|
||||
* "aò"). In addition, a variant of a letter differs from the base
|
||||
* form on the tertiary strength (such as "A" and "Ⓐ"). Another
|
||||
* example is the
|
||||
* difference between large and small Kana. A tertiary difference is ignored
|
||||
* when there is a primary or secondary difference anywhere in the strings.
|
||||
* <li>QUATERNARY strength: When punctuation is ignored
|
||||
* <a href=http://www-124.ibm.com/icu/userguide/Collate_Concepts.html#Ignoring_Punctuation>
|
||||
* (see Ignoring Punctuations in the user guide)</a> at PRIMARY to TERTIARY
|
||||
* strength, an additional strength level can
|
||||
* be used to distinguish words with and without punctuation (for example,
|
||||
* "ab" < "a-b" < "aB").
|
||||
* This difference is ignored when there is a PRIMARY, SECONDARY or TERTIARY
|
||||
* difference. The QUATERNARY strength should only be used if ignoring
|
||||
* punctuation is required.
|
||||
* (see Ignoring Punctuations in the user guide)</a> at PRIMARY to TERTIARY
|
||||
* strength, an additional strength level can
|
||||
* be used to distinguish words with and without punctuation (for example,
|
||||
* "ab" < "a-b" < "aB").
|
||||
* This difference is ignored when there is a PRIMARY, SECONDARY or TERTIARY
|
||||
* difference. The QUATERNARY strength should only be used if ignoring
|
||||
* punctuation is required.
|
||||
* <li>IDENTICAL strength:
|
||||
* When all other strengths are equal, the IDENTICAL strength is used as a
|
||||
* tiebreaker. The Unicode code point values of the NFD form of each string
|
||||
* are compared, just in case there is no difference.
|
||||
* For example, Hebrew cantellation marks are only distinguished at this
|
||||
* strength. This strength should be used sparingly, as only code point
|
||||
* value differences between two strings is an extremely rare occurrence.
|
||||
* Using this strength substantially decreases the performance for both
|
||||
* comparison and collation key generation APIs. This strength also
|
||||
* When all other strengths are equal, the IDENTICAL strength is used as a
|
||||
* tiebreaker. The Unicode code point values of the NFD form of each string
|
||||
* are compared, just in case there is no difference.
|
||||
* For example, Hebrew cantellation marks are only distinguished at this
|
||||
* strength. This strength should be used sparingly, as only code point
|
||||
* value differences between two strings is an extremely rare occurrence.
|
||||
* Using this strength substantially decreases the performance for both
|
||||
* comparison and collation key generation APIs. This strength also
|
||||
* increases the size of the collation key.
|
||||
* </ul>
|
||||
*
|
||||
* Unlike the JDK, ICU4J's Collator deals only with 2 decomposition modes,
|
||||
* Unlike the JDK, ICU4J's Collator deals only with 2 decomposition modes,
|
||||
* the canonical decomposition mode and one that does not use any decomposition.
|
||||
* The compatibility decomposition mode, java.text.Collator.FULL_DECOMPOSITION
|
||||
* is not supported here. If the canonical
|
||||
* decomposition mode is set, the Collator handles un-normalized text properly,
|
||||
* producing the same results as if the text were normalized in NFD. If
|
||||
* canonical decomposition is turned off, it is the user's responsibility to
|
||||
* decomposition mode is set, the Collator handles un-normalized text properly,
|
||||
* producing the same results as if the text were normalized in NFD. If
|
||||
* canonical decomposition is turned off, it is the user's responsibility to
|
||||
* ensure that all text is already in the appropriate form before performing
|
||||
* a comparison or before getting a CollationKey.</p>
|
||||
*
|
||||
* <p>For more information about the collation service see the
|
||||
* <a href="http://oss.software.ibm.com/icu/userguide/Collate_Intro.html">users
|
||||
* <p>For more information about the collation service see the
|
||||
* <a href="http://oss.software.ibm.com/icu/userguide/Collate_Intro.html">users
|
||||
* guide</a>.</p>
|
||||
*
|
||||
* <p>Examples of use
|
||||
@ -94,7 +94,7 @@ import com.ibm.icu.impl.ICUService.Factory;
|
||||
* if (usCollator.compare("abc", "ABC") == 0) {
|
||||
* System.out.println("Strings are equivalent");
|
||||
* }
|
||||
*
|
||||
*
|
||||
* The following example shows how to compare two strings using the
|
||||
* Collator for the default locale.
|
||||
*
|
||||
@ -119,14 +119,14 @@ import com.ibm.icu.impl.ICUService.Factory;
|
||||
* @see RuleBasedCollator
|
||||
* @see CollationKey
|
||||
* @author Syn Wee Quek
|
||||
* @draft ICU 2.2
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public abstract class Collator implements Comparator, Cloneable
|
||||
{
|
||||
{
|
||||
// public data members ---------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Strongest collator strength value. Typically used to denote differences
|
||||
* Strongest collator strength value. Typically used to denote differences
|
||||
* between base characters. See class documentation for more explanation.
|
||||
* @see #setStrength
|
||||
* @see #getStrength
|
||||
@ -135,10 +135,10 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
public final static int PRIMARY = 0;
|
||||
|
||||
/**
|
||||
* Second level collator strength value.
|
||||
* Second level collator strength value.
|
||||
* Accents in the characters are considered secondary differences.
|
||||
* Other differences between letters can also be considered secondary
|
||||
* differences, depending on the language.
|
||||
* Other differences between letters can also be considered secondary
|
||||
* differences, depending on the language.
|
||||
* See class documentation for more explanation.
|
||||
* @see #setStrength
|
||||
* @see #getStrength
|
||||
@ -147,23 +147,23 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
public final static int SECONDARY = 1;
|
||||
|
||||
/**
|
||||
* Third level collator strength value.
|
||||
* Third level collator strength value.
|
||||
* Upper and lower case differences in characters are distinguished at this
|
||||
* strength level. In addition, a variant of a letter differs from the base
|
||||
* strength level. In addition, a variant of a letter differs from the base
|
||||
* form on the tertiary level.
|
||||
* See class documentation for more explanation.
|
||||
* @see #setStrength
|
||||
* @see #getStrength
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public final static int TERTIARY = 2;
|
||||
public final static int TERTIARY = 2;
|
||||
|
||||
/**
|
||||
* Fourth level collator strength value.
|
||||
* When punctuation is ignored
|
||||
* Fourth level collator strength value.
|
||||
* When punctuation is ignored
|
||||
* <a href="http://www-124.ibm.com/icu/userguide/Collate_Concepts.html#Ignoring_Punctuation">
|
||||
* (see Ignoring Punctuations in the user guide)</a> at PRIMARY to TERTIARY
|
||||
* strength, an additional strength level can
|
||||
* (see Ignoring Punctuations in the user guide)</a> at PRIMARY to TERTIARY
|
||||
* strength, an additional strength level can
|
||||
* be used to distinguish words with and without punctuation.
|
||||
* See class documentation for more explanation.
|
||||
* @see #setStrength
|
||||
@ -174,10 +174,10 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Smallest Collator strength value. When all other strengths are equal,
|
||||
* the IDENTICAL strength is used as a tiebreaker. The Unicode code point
|
||||
* values of the NFD form of each string are compared, just in case there
|
||||
* is no difference.
|
||||
* Smallest Collator strength value. When all other strengths are equal,
|
||||
* the IDENTICAL strength is used as a tiebreaker. The Unicode code point
|
||||
* values of the NFD form of each string are compared, just in case there
|
||||
* is no difference.
|
||||
* See class documentation for more explanation.
|
||||
* </p>
|
||||
* <p>
|
||||
@ -197,7 +197,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* @see #CANONICAL_DECOMPOSITION
|
||||
* @see #getDecomposition
|
||||
* @see #setDecomposition
|
||||
* @draft ICU 2.2
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public final static int NO_DECOMPOSITION = 16;
|
||||
|
||||
@ -213,20 +213,20 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* @see #NO_DECOMPOSITION
|
||||
* @see #getDecomposition
|
||||
* @see #setDecomposition
|
||||
* @draft ICU 2.2
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public final static int CANONICAL_DECOMPOSITION = 17;
|
||||
|
||||
|
||||
// public methods --------------------------------------------------------
|
||||
|
||||
|
||||
// public setters --------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* <p>Sets this Collator's strength property. The strength property
|
||||
* determines the minimum level of difference considered significant
|
||||
* <p>Sets this Collator's strength property. The strength property
|
||||
* determines the minimum level of difference considered significant
|
||||
* during comparison.</p>
|
||||
*
|
||||
* <p>The default strength for the Collator is TERTIARY, unless specified
|
||||
*
|
||||
* <p>The default strength for the Collator is TERTIARY, unless specified
|
||||
* otherwise by the locale used to create the Collator.</p>
|
||||
*
|
||||
* <p>See the Collator class description for an example of use.</p>
|
||||
@ -237,11 +237,11 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* @see #TERTIARY
|
||||
* @see #QUATERNARY
|
||||
* @see #IDENTICAL
|
||||
* @exception IllegalArgumentException if the new strength value is not one
|
||||
* @exception IllegalArgumentException if the new strength value is not one
|
||||
* of PRIMARY, SECONDARY, TERTIARY, QUATERNARY or IDENTICAL.
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public void setStrength(int newStrength)
|
||||
public void setStrength(int newStrength)
|
||||
{
|
||||
if ((newStrength != PRIMARY) &&
|
||||
(newStrength != SECONDARY) &&
|
||||
@ -252,7 +252,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
}
|
||||
m_strength_ = newStrength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Set the decomposition mode of this Collator. Setting this
|
||||
* decomposition property with CANONICAL_DECOMPOSITION allows the
|
||||
@ -263,27 +263,27 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* a comparison or before getting a CollationKey. Adjusting
|
||||
* decomposition mode allows the user to select between faster and
|
||||
* more complete collation behavior.</p>
|
||||
*
|
||||
*
|
||||
* <p>Since a great many of the world's languages do not require
|
||||
* text normalization, most locales set NO_DECOMPOSITION as the
|
||||
* default decomposition mode.</p>
|
||||
*
|
||||
*
|
||||
* The default decompositon mode for the Collator is
|
||||
* NO_DECOMPOSITON, unless specified otherwise by the locale used
|
||||
* to create the Collator.</p>
|
||||
*
|
||||
*
|
||||
* <p>See getDecomposition for a description of decomposition
|
||||
* mode.</p>
|
||||
*
|
||||
*
|
||||
* @param decomposition the new decomposition mode
|
||||
* @see #getDecomposition
|
||||
* @see #NO_DECOMPOSITION
|
||||
* @see #CANONICAL_DECOMPOSITION
|
||||
* @exception IllegalArgumentException If the given value is not a valid
|
||||
* @exception IllegalArgumentException If the given value is not a valid
|
||||
* decomposition mode.
|
||||
* @draft ICU 2.2
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public void setDecomposition(int decomposition)
|
||||
public void setDecomposition(int decomposition)
|
||||
{
|
||||
if ((decomposition != NO_DECOMPOSITION) &&
|
||||
(decomposition != CANONICAL_DECOMPOSITION)) {
|
||||
@ -291,21 +291,21 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
}
|
||||
m_decomposition_ = decomposition;
|
||||
}
|
||||
|
||||
|
||||
// public getters --------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Gets the Collator for the current default locale.
|
||||
* The default locale is determined by java.util.Locale.getDefault().
|
||||
* @return the Collator for the default locale (for example, en_US) if it
|
||||
* is created successfully. Otherwise if there is no Collator
|
||||
* associated with the current locale, the default UCA collator
|
||||
* associated with the current locale, the default UCA collator
|
||||
* will be returned.
|
||||
* @see java.util.Locale#getDefault()
|
||||
* @see #getInstance(Locale)
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public static final Collator getInstance()
|
||||
public static final Collator getInstance()
|
||||
{
|
||||
return getInstance(Locale.getDefault());
|
||||
}
|
||||
@ -317,7 +317,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* @param locale the desired locale.
|
||||
* @return Collator for the desired locale if it is created successfully.
|
||||
* Otherwise if there is no Collator
|
||||
* associated with the current locale, a default UCA collator will
|
||||
* associated with the current locale, a default UCA collator will
|
||||
* be returned.
|
||||
* @see java.util.Locale
|
||||
* @see java.util.ResourceBundle
|
||||
@ -374,12 +374,12 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///CLOVER:ON
|
||||
/**
|
||||
* Get the set of Locales for which Collators are installed.
|
||||
* Get the set of Locales for which Collators are installed.
|
||||
* @return the list of available locales which collators are installed.
|
||||
* The set of Locales returned will be the ones registered in
|
||||
* The set of Locales returned will be the ones registered in
|
||||
* ICULocaleService, if ICULocaleService is used. Otherwise it will
|
||||
* be the set of Locales that are installed with ICU4J.
|
||||
* @draft ICU 2.4
|
||||
@ -396,14 +396,15 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
////CLOVER:OFF
|
||||
/* @prototype */
|
||||
/* public */ static final Map getDisplayNames(Locale locale) {
|
||||
return getService().getDisplayNames(locale);
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getService().getDisplayNames(locale, col, null);
|
||||
}
|
||||
////CLOVER:ON
|
||||
|
||||
|
||||
// end registry stuff
|
||||
|
||||
/**
|
||||
* <p>Returns this Collator's strength property. The strength property
|
||||
* <p>Returns this Collator's strength property. The strength property
|
||||
* determines the minimum level of difference considered significant.
|
||||
* </p>
|
||||
* <p>
|
||||
@ -422,11 +423,11 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
{
|
||||
return m_strength_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Get the decomposition mode of this Collator. Decomposition mode
|
||||
* determines how Unicode composed characters are handled.
|
||||
* determines how Unicode composed characters are handled.
|
||||
* </p>
|
||||
* <p>
|
||||
* See the Collator class description for more details.
|
||||
@ -441,20 +442,20 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
{
|
||||
return m_decomposition_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Compares the source text String to the target text String according to
|
||||
* Compares the source text String to the target text String according to
|
||||
* this Collator's rules, strength and decomposition mode.
|
||||
* Returns an integer less than,
|
||||
* equal to or greater than zero depending on whether the source String is
|
||||
* Returns an integer less than,
|
||||
* equal to or greater than zero depending on whether the source String is
|
||||
* less than, equal to or greater than the target String. See the Collator
|
||||
* class description for an example of use.
|
||||
* </p>
|
||||
* @param source the source String.
|
||||
* @param target the target String.
|
||||
* @return Returns an integer value. Value is less than zero if source is
|
||||
* less than target, value is zero if source and target are equal,
|
||||
* @return Returns an integer value. Value is less than zero if source is
|
||||
* less than target, value is zero if source and target are equal,
|
||||
* value is greater than zero if source is greater than target.
|
||||
* @see CollationKey
|
||||
* @see #getCollationKey
|
||||
@ -470,7 +471,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
}
|
||||
return compare((String)source, (String)target);
|
||||
}
|
||||
|
||||
|
||||
// public other methods -------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -484,23 +485,23 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* @exception NullPointerException thrown if either arguments is null.
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public boolean equals(String source, String target)
|
||||
public boolean equals(String source, String target)
|
||||
{
|
||||
return (compare(source, target) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an UnicodeSet that contains all the characters and sequences
|
||||
* tailored in this collator.
|
||||
* @return a pointer to a UnicodeSet object containing all the
|
||||
* code points and sequences that may sort differently than
|
||||
* in the UCA.
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public UnicodeSet getTailoredSet()
|
||||
{
|
||||
return new UnicodeSet(0, 0x10FFFF);
|
||||
}
|
||||
/**
|
||||
* Get an UnicodeSet that contains all the characters and sequences
|
||||
* tailored in this collator.
|
||||
* @return a pointer to a UnicodeSet object containing all the
|
||||
* code points and sequences that may sort differently than
|
||||
* in the UCA.
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public UnicodeSet getTailoredSet()
|
||||
{
|
||||
return new UnicodeSet(0, 0x10FFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the equality of two Collators.
|
||||
@ -510,7 +511,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public abstract boolean equals(Object that);
|
||||
|
||||
|
||||
// public abstract methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
@ -522,17 +523,17 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Compares the source text String to the target text String according to
|
||||
* Compares the source text String to the target text String according to
|
||||
* this Collator's rules, strength and decomposition mode.
|
||||
* Returns an integer less than,
|
||||
* equal to or greater than zero depending on whether the source String is
|
||||
* Returns an integer less than,
|
||||
* equal to or greater than zero depending on whether the source String is
|
||||
* less than, equal to or greater than the target String. See the Collator
|
||||
* class description for an example of use.
|
||||
* </p>
|
||||
* @param source the source String.
|
||||
* @param target the target String.
|
||||
* @return Returns an integer value. Value is less than zero if source is
|
||||
* less than target, value is zero if source and target are equal,
|
||||
* @return Returns an integer value. Value is less than zero if source is
|
||||
* less than target, value is zero if source and target are equal,
|
||||
* value is greater than zero if source is greater than target.
|
||||
* @see CollationKey
|
||||
* @see #getCollationKey
|
||||
@ -546,20 +547,20 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* Transforms the String into a CollationKey suitable for efficient
|
||||
* repeated comparison. The resulting key depends on the collator's
|
||||
* rules, strength and decomposition mode.
|
||||
* </p>
|
||||
* </p>
|
||||
* <p>See the CollationKey class documentation for more information.</p>
|
||||
* @param source the string to be transformed into a CollationKey.
|
||||
* @return the CollationKey for the given String based on this Collator's
|
||||
* collation rules. If the source String is null, a null
|
||||
* @return the CollationKey for the given String based on this Collator's
|
||||
* collation rules. If the source String is null, a null
|
||||
* CollationKey is returned.
|
||||
* @see CollationKey
|
||||
* @see #compare(String, String)
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public abstract CollationKey getCollationKey(String source);
|
||||
|
||||
|
||||
// protected constructor -------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Empty default constructor to make javadocs happy
|
||||
* @draft ICU 2.4
|
||||
@ -567,9 +568,9 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
protected Collator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// private data members --------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Collation strength
|
||||
*/
|
||||
@ -577,7 +578,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
|
||||
/**
|
||||
* Decomposition mode
|
||||
*/
|
||||
*/
|
||||
private int m_decomposition_ = CANONICAL_DECOMPOSITION;
|
||||
}
|
||||
|
||||
|
@ -4,14 +4,15 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CompoundTransliterator.java,v $
|
||||
* $Date: 2002/12/03 18:57:36 $
|
||||
* $Revision: 1.31 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CompoundTransliterator.java,v $
|
||||
* $Date: 2003/01/28 18:55:41 $
|
||||
* $Revision: 1.32 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.text;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.impl.UtilityExtensions;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
@ -42,7 +43,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
* Otherwise, this should have a value of -1. We need this
|
||||
* information to implement toRules().
|
||||
*/
|
||||
private int compoundRBTIndex;
|
||||
private int compoundRBTIndex;
|
||||
|
||||
private static final String COPYRIGHT =
|
||||
"\u00A9 IBM Corporation 1999-2001. All rights reserved.";
|
||||
@ -80,7 +81,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
public CompoundTransliterator(Transliterator[] transliterators) {
|
||||
this(transliterators, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new compound transliterator.
|
||||
* @param ID compound ID
|
||||
@ -94,7 +95,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
super(ID, filter);
|
||||
init(ID, direction, -1, null, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new compound transliterator with no filter.
|
||||
* @param ID compound ID
|
||||
@ -104,7 +105,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
public CompoundTransliterator(String ID, int direction) {
|
||||
this(ID, direction, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new forward compound transliterator with no filter.
|
||||
* @param ID compound ID
|
||||
@ -126,7 +127,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
super(ID, null);
|
||||
init(idBlock, FORWARD, idSplitPoint, splitTrans, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package private constructor for Transliterator from a vector of
|
||||
* transliterators. The caller is responsible for fixing up the
|
||||
@ -389,25 +390,25 @@ public class CompoundTransliterator extends Transliterator {
|
||||
* 1. h-u, changes hex to Unicode
|
||||
*
|
||||
* 4 7 a d 0 4 7 a
|
||||
* abc/u0061/u => abca/u
|
||||
* abc/u0061/u => abca/u
|
||||
* C S L C S L gl=f->a
|
||||
*
|
||||
* 2. upup, changes "x" to "XX"
|
||||
*
|
||||
* 4 7 a 4 7 a
|
||||
* abca/u => abcAA/u
|
||||
* C SL C S
|
||||
* abca/u => abcAA/u
|
||||
* C SL C S
|
||||
* L gl=a->b
|
||||
* 3. u-h, changes Unicode to hex
|
||||
*
|
||||
* 4 7 a 4 7 a d 0 3
|
||||
* abcAA/u => abc/u0041/u0041/u
|
||||
* abcAA/u => abc/u0041/u0041/u
|
||||
* C S L C S
|
||||
* L gl=b->15
|
||||
* 4. return
|
||||
*
|
||||
* 4 7 a d 0 3
|
||||
* abc/u0041/u0041/u
|
||||
* abc/u0041/u0041/u
|
||||
* C S L
|
||||
*/
|
||||
|
||||
@ -432,7 +433,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
if (DEBUG) {
|
||||
log = new StringBuffer("CompoundTransliterator{" + getID() +
|
||||
(incremental ? "}i: IN=" : "}: IN="));
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
System.out.println(Utility.escape(log.toString()));
|
||||
}
|
||||
|
||||
@ -448,7 +449,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
System.out.println("CompoundTransliterator[" + i +
|
||||
".." + (trans.length-1) +
|
||||
(incremental ? "]i: " : "]: ") +
|
||||
Utility.formatInput(text, index) +
|
||||
UtilityExtensions.formatInput(text, index) +
|
||||
" (NOTHING TO DO)");
|
||||
}
|
||||
break;
|
||||
@ -459,7 +460,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
log.append("CompoundTransliterator[" + i + "=" +
|
||||
trans[i].getID() +
|
||||
(incremental ? "]i: " : "]: "));
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
}
|
||||
|
||||
trans[i].filteredTransliterate(text, index, incremental);
|
||||
@ -477,7 +478,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
|
||||
if (DEBUG) {
|
||||
log.append(" => ");
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
System.out.println(Utility.escape(log.toString()));
|
||||
}
|
||||
|
||||
@ -505,7 +506,7 @@ public class CompoundTransliterator extends Transliterator {
|
||||
log.setLength(0);
|
||||
log.append("CompoundTransliterator{" + getID() +
|
||||
(incremental ? "}i: OUT=" : "}: OUT="));
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
System.out.println(Utility.escape(log.toString()));
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/TransliterationRule.java,v $
|
||||
* $Date: 2002/06/28 19:15:53 $
|
||||
* $Revision: 1.47 $
|
||||
* $Date: 2003/01/28 18:55:42 $
|
||||
* $Revision: 1.48 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -46,7 +46,7 @@ import com.ibm.icu.impl.Utility;
|
||||
* <p>Copyright © IBM Corporation 1999. All rights reserved.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: TransliterationRule.java,v $ $Revision: 1.47 $ $Date: 2002/06/28 19:15:53 $
|
||||
* @version $RCSfile: TransliterationRule.java,v $ $Revision: 1.48 $ $Date: 2003/01/28 18:55:42 $
|
||||
*/
|
||||
class TransliterationRule {
|
||||
|
||||
@ -127,13 +127,6 @@ class TransliterationRule {
|
||||
*/
|
||||
private final RuleBasedTransliterator.Data data;
|
||||
|
||||
/**
|
||||
* The character at index i, where i < contextStart || i >= contextLimit,
|
||||
* is ETHER. This allows explicit matching by rules and UnicodeSets
|
||||
* of text outside the context. In traditional terms, this allows anchoring
|
||||
* at the start and/or end.
|
||||
*/
|
||||
static final char ETHER = '\uFFFF';
|
||||
|
||||
private static final String COPYRIGHT =
|
||||
"\u00A9 IBM Corporation 1999-2001. All rights reserved.";
|
||||
@ -430,7 +423,7 @@ class TransliterationRule {
|
||||
}
|
||||
|
||||
oText = intRef[0];
|
||||
|
||||
|
||||
minOText = posAfter(text, oText);
|
||||
|
||||
// ------------------------ Start Anchor ------------------------
|
||||
@ -590,6 +583,9 @@ class TransliterationRule {
|
||||
|
||||
/**
|
||||
* $Log: TransliterationRule.java,v $
|
||||
* Revision 1.48 2003/01/28 18:55:42 rviswanadha
|
||||
* jitterbug 2309: Modularize ICU4J big bang commit
|
||||
*
|
||||
* Revision 1.47 2002/06/28 19:15:53 alan
|
||||
* jitterbug 1434: improve method names; minor cleanup
|
||||
*
|
||||
|
@ -5,15 +5,15 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/TransliterationRuleSet.java,v $
|
||||
* $Date: 2002/06/28 19:15:53 $
|
||||
* $Revision: 1.25 $
|
||||
* $Date: 2003/01/28 18:55:42 $
|
||||
* $Revision: 1.26 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import java.util.*;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.impl.UtilityExtensions;
|
||||
|
||||
/**
|
||||
* A set of rules for a <code>RuleBasedTransliterator</code>. This set encodes
|
||||
@ -28,7 +28,7 @@ import com.ibm.icu.impl.Utility;
|
||||
* <p>Copyright © IBM Corporation 1999. All rights reserved.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: TransliterationRuleSet.java,v $ $Revision: 1.25 $ $Date: 2002/06/28 19:15:53 $
|
||||
* @version $RCSfile: TransliterationRuleSet.java,v $ $Revision: 1.26 $ $Date: 2003/01/28 18:55:42 $
|
||||
*/
|
||||
class TransliterationRuleSet {
|
||||
/**
|
||||
@ -204,14 +204,14 @@ class TransliterationRuleSet {
|
||||
if (Transliterator.DEBUG) {
|
||||
System.out.println((incremental ? "Rule.i: match ":"Rule: match ") +
|
||||
rules[i].toRule(true) + " => " +
|
||||
Utility.formatInput(text, pos));
|
||||
UtilityExtensions.formatInput(text, pos));
|
||||
}
|
||||
return true;
|
||||
case UnicodeMatcher.U_PARTIAL_MATCH:
|
||||
if (Transliterator.DEBUG) {
|
||||
System.out.println((incremental ? "Rule.i: partial match ":"Rule: partial match ") +
|
||||
rules[i].toRule(true) + " => " +
|
||||
Utility.formatInput(text, pos));
|
||||
UtilityExtensions.formatInput(text, pos));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -220,7 +220,7 @@ class TransliterationRuleSet {
|
||||
pos.start += UTF16.getCharCount(text.char32At(pos.start));
|
||||
if (Transliterator.DEBUG) {
|
||||
System.out.println((incremental ? "Rule.i: no match => ":"Rule: no match => ") +
|
||||
Utility.formatInput(text, pos));
|
||||
UtilityExtensions.formatInput(text, pos));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -254,9 +254,9 @@ class TransliterationRuleSet {
|
||||
TransliterationRule r =
|
||||
(TransliterationRule) ruleVector.elementAt(i);
|
||||
if (getTarget) {
|
||||
r.addTargetSetTo(set);
|
||||
r.addTargetSetTo(set);
|
||||
} else {
|
||||
r.addSourceSetTo(set);
|
||||
r.addSourceSetTo(set);
|
||||
}
|
||||
}
|
||||
return set;
|
||||
@ -264,9 +264,12 @@ class TransliterationRuleSet {
|
||||
}
|
||||
|
||||
/* $Log: TransliterationRuleSet.java,v $
|
||||
* Revision 1.25 2002/06/28 19:15:53 alan
|
||||
* jitterbug 1434: improve method names; minor cleanup
|
||||
* Revision 1.26 2003/01/28 18:55:42 rviswanadha
|
||||
* jitterbug 2309: Modularize ICU4J big bang commit
|
||||
*
|
||||
/* Revision 1.25 2002/06/28 19:15:53 alan
|
||||
/* jitterbug 1434: improve method names; minor cleanup
|
||||
/*
|
||||
/* Revision 1.24 2002/06/26 18:12:40 alan
|
||||
/* jitterbug 1434: initial public implementation of getSourceSet and getTargetSet
|
||||
/*
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Transliterator.java,v $
|
||||
* $Date: 2002/12/05 01:22:35 $
|
||||
* $Revision: 1.86 $
|
||||
* $Date: 2003/01/28 18:55:42 $
|
||||
* $Revision: 1.87 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -15,13 +15,13 @@ package com.ibm.icu.text;
|
||||
import com.ibm.icu.impl.ICULocaleData;
|
||||
import com.ibm.icu.impl.data.ResourceReader;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.impl.UtilityExtensions;
|
||||
import com.ibm.icu.util.CaseInsensitiveString;
|
||||
import com.ibm.icu.impl.UCharacterProperty;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.RuleBasedCollator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
@ -675,7 +675,7 @@ public abstract class Transliterator {
|
||||
* incremental and non-incremental transliteration. Let
|
||||
* <code>originalStart</code> refer to the value of
|
||||
* <code>pos.start</code> upon entry.
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>If <code>incremental</code> is false, then this method
|
||||
* should transliterate all characters between
|
||||
@ -695,7 +695,7 @@ public abstract class Transliterator {
|
||||
* transliterator and characters [<code>pos.start</code>,
|
||||
* <code>pos.limit</code>) are unchanged.</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p>Implementations of this method should also obey the
|
||||
* following invariants:</p>
|
||||
*
|
||||
@ -718,13 +718,13 @@ public abstract class Transliterator {
|
||||
* <li>Text before <code>pos.contextStart</code> and text after
|
||||
* <code> pos.contextLimit</code> should be ignored.</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p>Subclasses may safely assume that all characters in
|
||||
* [<code>pos.start</code>, <code>pos.limit</code>) are filtered.
|
||||
* In other words, the filter has already been applied by the time
|
||||
* this method is called. See
|
||||
* <code>filteredTransliterate()</code>.
|
||||
*
|
||||
*
|
||||
* <p>This method is <b>not</b> for public consumption. Calling
|
||||
* this method directly will transliterate
|
||||
* [<code>pos.start</code>, <code>pos.limit</code>) without
|
||||
@ -732,19 +732,19 @@ public abstract class Transliterator {
|
||||
* transliterate()</code> instead of this method. Subclass code
|
||||
* should call <code>filteredTransliterate()</code> instead of
|
||||
* this method.<p>
|
||||
*
|
||||
*
|
||||
* @param text the buffer holding transliterated and
|
||||
* untransliterated text
|
||||
*
|
||||
*
|
||||
* @param pos the indices indicating the start, limit, context
|
||||
* start, and context limit of the text.
|
||||
*
|
||||
*
|
||||
* @param incremental if true, assume more text may be inserted at
|
||||
* <code>pos.limit</code> and act accordingly. Otherwise,
|
||||
* transliterate all text between <code>pos.start</code> and
|
||||
* <code>pos.limit</code> and move <code>pos.start</code> up to
|
||||
* <code>pos.limit</code>.
|
||||
*
|
||||
*
|
||||
* @see #transliterate
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
@ -757,7 +757,7 @@ public abstract class Transliterator {
|
||||
* public API methods eventually call this method with a rollback argument
|
||||
* of TRUE. Other entities may call this method but rollback should be
|
||||
* FALSE.
|
||||
*
|
||||
*
|
||||
* <p>If this transliterator has a filter, break up the input text into runs
|
||||
* of unfiltered characters. Pass each run to
|
||||
* <subclass>.handleTransliterate().
|
||||
@ -835,14 +835,14 @@ public abstract class Transliterator {
|
||||
if (filter != null) {
|
||||
// Narrow the range to be transliterated to the first run
|
||||
// of unfiltered characters at or after index.start.
|
||||
|
||||
|
||||
// Advance past filtered chars
|
||||
int c;
|
||||
while (index.start < globalLimit &&
|
||||
!filter.contains(c=text.char32At(index.start))) {
|
||||
index.start += UTF16.getCharCount(c);
|
||||
}
|
||||
|
||||
|
||||
// Find the end of this run of unfiltered chars
|
||||
index.limit = index.start;
|
||||
while (index.limit < globalLimit &&
|
||||
@ -900,7 +900,7 @@ public abstract class Transliterator {
|
||||
if (DEBUG) {
|
||||
log.setLength(0);
|
||||
System.out.println("filteredTransliterate{"+getID()+"}i: IN=" +
|
||||
Utility.formatInput(text, index));
|
||||
UtilityExtensions.formatInput(text, index));
|
||||
}
|
||||
|
||||
int runStart = index.start;
|
||||
@ -948,7 +948,7 @@ public abstract class Transliterator {
|
||||
if (DEBUG) {
|
||||
log.setLength(0);
|
||||
log.append("filteredTransliterate{"+getID()+"}i: ");
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
}
|
||||
|
||||
// Delegate to subclass for actual transliteration. Upon
|
||||
@ -959,11 +959,11 @@ public abstract class Transliterator {
|
||||
|
||||
if (DEBUG) {
|
||||
log.append(" => ");
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
}
|
||||
|
||||
delta = index.limit - passLimit; // change in length
|
||||
|
||||
|
||||
// We failed to completely transliterate this pass.
|
||||
// Roll back the text. Indices remain unchanged; reset
|
||||
// them where necessary.
|
||||
@ -971,13 +971,13 @@ public abstract class Transliterator {
|
||||
// Find the rollbackStart, adjusted for length changes
|
||||
// and the deletion of partially transliterated text.
|
||||
int rs = rollbackStart + delta - (index.limit - passStart);
|
||||
|
||||
|
||||
// Delete the partially transliterated text
|
||||
text.replace(passStart, index.limit, "");
|
||||
|
||||
|
||||
// Copy the rollback text back
|
||||
text.copy(rs, rs + uncommittedLength, passStart);
|
||||
|
||||
|
||||
// Restore indices to their original values
|
||||
index.start = passStart;
|
||||
index.limit = passLimit;
|
||||
@ -1030,7 +1030,7 @@ public abstract class Transliterator {
|
||||
if (DEBUG) {
|
||||
log.setLength(0);
|
||||
log.append("filteredTransliterate{"+getID()+"}: ");
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
}
|
||||
|
||||
int limit = index.limit;
|
||||
@ -1039,7 +1039,7 @@ public abstract class Transliterator {
|
||||
|
||||
if (DEBUG) {
|
||||
log.append(" => ");
|
||||
Utility.formatInput(log, text, index);
|
||||
UtilityExtensions.formatInput(log, text, index);
|
||||
}
|
||||
|
||||
// In a properly written transliterator, start == limit after
|
||||
@ -1066,7 +1066,7 @@ public abstract class Transliterator {
|
||||
if (filter == null || isIncrementalRun) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// If we did completely transliterate this
|
||||
// run, then repeat with the next unfiltered run.
|
||||
}
|
||||
@ -1077,7 +1077,7 @@ public abstract class Transliterator {
|
||||
|
||||
if (DEBUG) {
|
||||
System.out.println("filteredTransliterate{"+getID()+"}: OUT=" +
|
||||
Utility.formatInput(text, index));
|
||||
UtilityExtensions.formatInput(text, index));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1178,10 +1178,10 @@ public abstract class Transliterator {
|
||||
*/
|
||||
public static String getDisplayName(String id, Locale inLocale) {
|
||||
|
||||
// Resource bundle containing display name keys and the
|
||||
// RB_RULE_BASED_IDS array.
|
||||
//
|
||||
//If we ever integrate this with the Sun JDK, the resource bundle
|
||||
// Resource bundle containing display name keys and the
|
||||
// RB_RULE_BASED_IDS array.
|
||||
//
|
||||
//If we ever integrate this with the Sun JDK, the resource bundle
|
||||
// root will change to sun.text.resources.LocaleElements
|
||||
|
||||
ResourceBundle bundle = ICULocaleData.getLocaleElements(inLocale);
|
||||
@ -1551,7 +1551,7 @@ public abstract class Transliterator {
|
||||
/**
|
||||
* Register a Transliterator object with the given ID.
|
||||
* @param ID the ID of this transliterator
|
||||
* @param trans the Transliterator object
|
||||
* @param trans the Transliterator object
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
public static void registerInstance(Transliterator trans) {
|
||||
|
@ -115,27 +115,29 @@ class TransliteratorRegistry {
|
||||
top = theSpec;
|
||||
spec = null;
|
||||
scriptName = null;
|
||||
|
||||
Locale toploc = LocaleUtility.getLocaleFromName(top);
|
||||
res = ICULocaleData.getLocaleElements(toploc);
|
||||
// Make sure we got the bundle we wanted; otherwise, don't use it
|
||||
if (LocaleUtility.isFallbackOf(res.getLocale().toString(), top)) {
|
||||
isSpecLocale = true;
|
||||
} else {
|
||||
isSpecLocale = false;
|
||||
res = null;
|
||||
}
|
||||
|
||||
// Canonicalize script name -or- do locale->script mapping
|
||||
int[] s = UScript.getCode(top);
|
||||
if (s != null) {
|
||||
scriptName = UScript.getName(s[0]);
|
||||
// If the script name is the same as top then it's redundant
|
||||
if (scriptName.equalsIgnoreCase(top)) {
|
||||
scriptName = null;
|
||||
try{
|
||||
Locale toploc = LocaleUtility.getLocaleFromName(top);
|
||||
res = ICULocaleData.getLocaleElements(toploc);
|
||||
// Make sure we got the bundle we wanted; otherwise, don't use it
|
||||
if (res!=null && LocaleUtility.isFallbackOf(res.getLocale().toString(), top)) {
|
||||
isSpecLocale = true;
|
||||
} else {
|
||||
isSpecLocale = false;
|
||||
res = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Canonicalize script name -or- do locale->script mapping
|
||||
int[] s = UScript.getCode(top);
|
||||
if (s != null) {
|
||||
scriptName = UScript.getName(s[0]);
|
||||
// If the script name is the same as top then it's redundant
|
||||
if (scriptName.equalsIgnoreCase(top)) {
|
||||
scriptName = null;
|
||||
}
|
||||
}
|
||||
}catch(MissingResourceException e){
|
||||
scriptName = null;
|
||||
}
|
||||
// assert(spec != top);
|
||||
reset();
|
||||
}
|
||||
@ -167,11 +169,11 @@ class TransliteratorRegistry {
|
||||
}
|
||||
} else {
|
||||
// Fallback to the script, which may be null
|
||||
if (nextSpec != scriptName) {
|
||||
nextSpec = scriptName;
|
||||
} else {
|
||||
nextSpec = null;
|
||||
}
|
||||
if (nextSpec != scriptName) {
|
||||
nextSpec = scriptName;
|
||||
} else {
|
||||
nextSpec = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,13 +214,13 @@ class TransliteratorRegistry {
|
||||
public String getTop() {
|
||||
return top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Entry classes
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static class ResourceEntry {
|
||||
static class ResourceEntry {
|
||||
public String resourceName;
|
||||
public String encoding;
|
||||
public int direction;
|
||||
@ -369,7 +371,7 @@ class TransliteratorRegistry {
|
||||
removeSTV(stv[0], stv[1], stv[2]);
|
||||
availableIDs.removeElement(new CaseInsensitiveString(id));
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// class TransliteratorRegistry: Public ID and spec management
|
||||
//----------------------------------------------------------------------
|
||||
@ -695,9 +697,9 @@ class TransliteratorRegistry {
|
||||
return new Object[] { new LocaleEntry(subres[i+1], dir) };
|
||||
}
|
||||
|
||||
} catch (MissingResourceException e) {
|
||||
if (DEBUG) System.out.println("missing resource: " + e);
|
||||
}
|
||||
} catch (MissingResourceException e) {
|
||||
if (DEBUG) System.out.println("missing resource: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here we had a missing resource exception or we
|
||||
@ -848,7 +850,7 @@ class TransliteratorRegistry {
|
||||
// This should never happen; UTF8 is always supported
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
parser.parse(r, re.direction);
|
||||
} catch (ClassCastException e) {
|
||||
// If we pull a rule from a locale resource bundle it will
|
||||
|
@ -4,9 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UnicodeMatcher.java,v $
|
||||
* $Date: 2002/12/05 01:23:15 $
|
||||
* $Revision: 1.8 $
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UnicodeMatcher.java,v $
|
||||
* $Date: 2003/01/28 18:55:42 $
|
||||
* $Revision: 1.9 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -27,7 +27,7 @@ public interface UnicodeMatcher {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public static final int U_MISMATCH = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constant returned by <code>matches()</code> indicating a
|
||||
* partial match between the text and this matcher. This value is
|
||||
@ -39,7 +39,7 @@ public interface UnicodeMatcher {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public static final int U_PARTIAL_MATCH = 1;
|
||||
|
||||
|
||||
/**
|
||||
* Constant returned by <code>matches()</code> indicating a
|
||||
* complete match between the text and this matcher. For an
|
||||
@ -50,6 +50,14 @@ public interface UnicodeMatcher {
|
||||
*/
|
||||
public static final int U_MATCH = 2;
|
||||
|
||||
/**
|
||||
* The character at index i, where i < contextStart || i >= contextLimit,
|
||||
* is ETHER. This allows explicit matching by rules and UnicodeSets
|
||||
* of text outside the context. In traditional terms, this allows anchoring
|
||||
* at the start and/or end.
|
||||
*/
|
||||
static final char ETHER = '\uFFFF';
|
||||
|
||||
/**
|
||||
* Return a UMatchDegree value indicating the degree of match for
|
||||
* the given text at the given offset. Zero, one, or more
|
||||
@ -58,7 +66,7 @@ public interface UnicodeMatcher {
|
||||
* Matching in the forward direction is indicated by limit >
|
||||
* offset. Characters from offset forwards to limit-1 will be
|
||||
* considered for matching.
|
||||
*
|
||||
*
|
||||
* Matching in the reverse direction is indicated by limit <
|
||||
* offset. Characters from offset backwards to limit+1 will be
|
||||
* considered for matching.
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UnicodeSet.java,v $
|
||||
* $Date: 2003/01/21 21:12:35 $
|
||||
* $Revision: 1.84 $
|
||||
* $Date: 2003/01/28 18:55:43 $
|
||||
* $Revision: 1.85 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -80,7 +80,7 @@ import java.util.Iterator;
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td nowrap valign="top" align="left"><code>[a-e]</code></td>
|
||||
* <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
|
||||
* <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
|
||||
* point order</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
@ -89,7 +89,7 @@ import java.util.Iterator;
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
|
||||
* <td valign="top">The character 'a' and the multicharacter strings "ab" and
|
||||
* <td valign="top">The character 'a' and the multicharacter strings "ab" and
|
||||
* "ac"</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
@ -275,7 +275,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
private int[] list; // MUST be terminated with HIGH
|
||||
private int[] rangeList; // internal buffer
|
||||
private int[] buffer; // internal buffer
|
||||
|
||||
|
||||
// NOTE: normally the field should be of type SortedSet; but that is missing a public clone!!
|
||||
// is not private so that UnicodeSetIterator can get access
|
||||
TreeSet strings = new TreeSet();
|
||||
@ -744,26 +744,26 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
int[] offset,
|
||||
int limit,
|
||||
boolean incremental) {
|
||||
|
||||
|
||||
if (offset[0] == limit) {
|
||||
// Strings, if any, have length != 0, so we don't worry
|
||||
// about them here. If we ever allow zero-length strings
|
||||
// we much check for them here.
|
||||
if (contains(TransliterationRule.ETHER)) {
|
||||
if (contains(UnicodeMatcher.ETHER)) {
|
||||
return incremental ? U_PARTIAL_MATCH : U_MATCH;
|
||||
} else {
|
||||
return U_MISMATCH;
|
||||
}
|
||||
} else {
|
||||
if (strings.size() != 0) { // try strings first
|
||||
|
||||
|
||||
// might separate forward and backward loops later
|
||||
// for now they are combined
|
||||
|
||||
// TODO Improve efficiency of this, at least in the forward
|
||||
// direction, if not in both. In the forward direction we
|
||||
// can assume the strings are sorted.
|
||||
|
||||
|
||||
Iterator it = strings.iterator();
|
||||
boolean forward = offset[0] < limit;
|
||||
|
||||
@ -790,7 +790,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
// forward direction.
|
||||
if (forward && c > firstChar) break;
|
||||
if (c != firstChar) continue;
|
||||
|
||||
|
||||
int len = matchRest(text, offset[0], limit, trial);
|
||||
|
||||
if (incremental) {
|
||||
@ -825,7 +825,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
return super.matches(text, offset, limit, incremental);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the longest match for s in text at the given position.
|
||||
* If limit > start then match forward from start+1 to limit
|
||||
@ -866,7 +866,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
}
|
||||
return maxLen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of UnicodeMatcher API. Union the set of all
|
||||
@ -1000,7 +1000,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
|
||||
// HIGH is 0x110000
|
||||
// assert(list[len-1] == HIGH);
|
||||
|
||||
|
||||
// empty = [HIGH]
|
||||
// [start_0, limit_0, start_1, limit_1, HIGH]
|
||||
|
||||
@ -1064,7 +1064,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
list[i+1] = c+1;
|
||||
len += 2;
|
||||
}
|
||||
|
||||
|
||||
pat = null;
|
||||
return this;
|
||||
}
|
||||
@ -1074,23 +1074,23 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* present. If this set already contains the multicharacter,
|
||||
* the call leaves this set unchanged.
|
||||
* Thus "ch" => {"ch"}
|
||||
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
||||
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
||||
* @param s the source string
|
||||
* @return this object, for chaining
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final UnicodeSet add(String s) {
|
||||
|
||||
|
||||
int cp = getSingleCP(s);
|
||||
if (cp < 0) {
|
||||
strings.add(s);
|
||||
pat = null;
|
||||
} else {
|
||||
add(cp, cp);
|
||||
}
|
||||
strings.add(s);
|
||||
pat = null;
|
||||
} else {
|
||||
add(cp, cp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a code point IF the string consists of a single one.
|
||||
* otherwise returns -1.
|
||||
@ -1098,19 +1098,19 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
*/
|
||||
private static int getSingleCP(String s) {
|
||||
if (s.length() < 1) {
|
||||
throw new IllegalArgumentException("Can't use zero-length strings in UnicodeSet");
|
||||
throw new IllegalArgumentException("Can't use zero-length strings in UnicodeSet");
|
||||
}
|
||||
if (s.length() > 2) return -1;
|
||||
if (s.length() == 1) return s.charAt(0);
|
||||
|
||||
// at this point, len = 2
|
||||
if (s.length() > 2) return -1;
|
||||
if (s.length() == 1) return s.charAt(0);
|
||||
|
||||
// at this point, len = 2
|
||||
int cp = UTF16.charAt(s, 0);
|
||||
if (cp > 0xFFFF) { // is surrogate pair
|
||||
return cp;
|
||||
return cp;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
|
||||
* If this set already any particular character, it has no effect on that character.
|
||||
@ -1135,7 +1135,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final UnicodeSet retainAll(String s) {
|
||||
return retainAll(fromAll(s));
|
||||
return retainAll(fromAll(s));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1146,7 +1146,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final UnicodeSet complementAll(String s) {
|
||||
return complementAll(fromAll(s));
|
||||
return complementAll(fromAll(s));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1157,12 +1157,12 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final UnicodeSet removeAll(String s) {
|
||||
return removeAll(fromAll(s));
|
||||
return removeAll(fromAll(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a set from a multicharacter string. Thus "ch" => {"ch"}
|
||||
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
||||
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
||||
* @param s the source string
|
||||
* @return a newly created set containing the given string
|
||||
* @stable ICU 2.0
|
||||
@ -1171,7 +1171,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
return new UnicodeSet().add(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
|
||||
* @param s the source string
|
||||
@ -1216,7 +1216,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
public final UnicodeSet retain(int c) {
|
||||
return retain(c, c);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retain the specified string in this set if it is present.
|
||||
* The set will not contain the specified character once the call
|
||||
@ -1228,14 +1228,14 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
public final UnicodeSet retain(String s) {
|
||||
int cp = getSingleCP(s);
|
||||
if (cp < 0) {
|
||||
if (strings.size() == 1 && strings.contains(s)) return this;
|
||||
strings.clear();
|
||||
strings.add(s);
|
||||
pat = null;
|
||||
} else {
|
||||
retain(cp, cp);
|
||||
}
|
||||
return this;
|
||||
if (strings.size() == 1 && strings.contains(s)) return this;
|
||||
strings.clear();
|
||||
strings.add(s);
|
||||
pat = null;
|
||||
} else {
|
||||
retain(cp, cp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1284,12 +1284,12 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
public final UnicodeSet remove(String s) {
|
||||
int cp = getSingleCP(s);
|
||||
if (cp < 0) {
|
||||
strings.remove(s);
|
||||
pat = null;
|
||||
} else {
|
||||
remove(cp, cp);
|
||||
}
|
||||
return this;
|
||||
strings.remove(s);
|
||||
pat = null;
|
||||
} else {
|
||||
remove(cp, cp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1346,12 +1346,12 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
pat = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Complement the specified string in this set.
|
||||
* The set will not contain the specified string once the call
|
||||
* returns.
|
||||
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
||||
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
||||
* @param s the string to complement
|
||||
* @return this object, for chaining
|
||||
* @stable ICU 2.0
|
||||
@ -1359,14 +1359,14 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
public final UnicodeSet complement(String s) {
|
||||
int cp = getSingleCP(s);
|
||||
if (cp < 0) {
|
||||
if (strings.contains(s)) strings.remove(s);
|
||||
else strings.add(s);
|
||||
pat = null;
|
||||
} else {
|
||||
complement(cp, cp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
if (strings.contains(s)) strings.remove(s);
|
||||
else strings.add(s);
|
||||
pat = null;
|
||||
} else {
|
||||
complement(cp, cp);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this set contains the given character.
|
||||
@ -1417,7 +1417,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
// list[len - 1] == HIGH and that c is legal (0..HIGH-1).
|
||||
if (c < list[0]) return 0;
|
||||
// High runner test. c is often after the last range, so an
|
||||
// initial check for this condition pays off.
|
||||
// initial check for this condition pays off.
|
||||
if (len >= 2 && c >= list[len-2]) return len-1;
|
||||
int lo = 0;
|
||||
int hi = len - 1;
|
||||
@ -1482,7 +1482,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
// validate();
|
||||
// }
|
||||
// int temp;
|
||||
//
|
||||
//
|
||||
// // set up initial range to search. Each subrange is a power of two in length
|
||||
// int high = searchValue < list[topOfLow] ? topOfLow : topOfHigh;
|
||||
//
|
||||
@ -1490,48 +1490,48 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
// // Each case deliberately falls through to the next
|
||||
// // Logically, list[-1] < all_search_values && list[count] > all_search_values
|
||||
// // although the values -1 and count are never actually touched.
|
||||
//
|
||||
//
|
||||
// // The bounds at each point are low & high,
|
||||
// // where low == high - delta*2
|
||||
// // so high - delta is the midpoint
|
||||
//
|
||||
//
|
||||
// // The invariant AFTER each line is that list[low] < searchValue <= list[high]
|
||||
//
|
||||
//
|
||||
// switch (power) {
|
||||
// //case 31: if (searchValue < list[temp = high-0x40000000]) high = temp; // no unsigned int in Java
|
||||
// case 30: if (searchValue < list[temp = high-0x20000000]) high = temp;
|
||||
// case 29: if (searchValue < list[temp = high-0x10000000]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 28: if (searchValue < list[temp = high- 0x8000000]) high = temp;
|
||||
// case 27: if (searchValue < list[temp = high- 0x4000000]) high = temp;
|
||||
// case 26: if (searchValue < list[temp = high- 0x2000000]) high = temp;
|
||||
// case 25: if (searchValue < list[temp = high- 0x1000000]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 24: if (searchValue < list[temp = high- 0x800000]) high = temp;
|
||||
// case 23: if (searchValue < list[temp = high- 0x400000]) high = temp;
|
||||
// case 22: if (searchValue < list[temp = high- 0x200000]) high = temp;
|
||||
// case 21: if (searchValue < list[temp = high- 0x100000]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 20: if (searchValue < list[temp = high- 0x80000]) high = temp;
|
||||
// case 19: if (searchValue < list[temp = high- 0x40000]) high = temp;
|
||||
// case 18: if (searchValue < list[temp = high- 0x20000]) high = temp;
|
||||
// case 17: if (searchValue < list[temp = high- 0x10000]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 16: if (searchValue < list[temp = high- 0x8000]) high = temp;
|
||||
// case 15: if (searchValue < list[temp = high- 0x4000]) high = temp;
|
||||
// case 14: if (searchValue < list[temp = high- 0x2000]) high = temp;
|
||||
// case 13: if (searchValue < list[temp = high- 0x1000]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 12: if (searchValue < list[temp = high- 0x800]) high = temp;
|
||||
// case 11: if (searchValue < list[temp = high- 0x400]) high = temp;
|
||||
// case 10: if (searchValue < list[temp = high- 0x200]) high = temp;
|
||||
// case 9: if (searchValue < list[temp = high- 0x100]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 8: if (searchValue < list[temp = high- 0x80]) high = temp;
|
||||
// case 7: if (searchValue < list[temp = high- 0x40]) high = temp;
|
||||
// case 6: if (searchValue < list[temp = high- 0x20]) high = temp;
|
||||
// case 5: if (searchValue < list[temp = high- 0x10]) high = temp;
|
||||
//
|
||||
//
|
||||
// case 4: if (searchValue < list[temp = high- 0x8]) high = temp;
|
||||
// case 3: if (searchValue < list[temp = high- 0x4]) high = temp;
|
||||
// case 2: if (searchValue < list[temp = high- 0x2]) high = temp;
|
||||
@ -1580,15 +1580,15 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final boolean contains(String s) {
|
||||
|
||||
|
||||
int cp = getSingleCP(s);
|
||||
if (cp < 0) {
|
||||
return strings.contains(s);
|
||||
} else {
|
||||
return contains(cp);
|
||||
}
|
||||
return strings.contains(s);
|
||||
} else {
|
||||
return contains(cp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains all the characters and strings
|
||||
* of the given set.
|
||||
@ -1609,7 +1609,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
if (!strings.containsAll(c.strings)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains all the characters
|
||||
* of the given string.
|
||||
@ -1625,7 +1625,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains none of the characters
|
||||
* of the given range.
|
||||
@ -1668,7 +1668,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
if (!SortedSetRelation.hasRelation(strings, SortedSetRelation.DISJOINT, c.strings)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains none of the characters
|
||||
* of the given string.
|
||||
@ -1684,7 +1684,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains one or more of the characters
|
||||
* in the given range.
|
||||
@ -1694,9 +1694,9 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final boolean containsSome(int start, int end) {
|
||||
return !containsNone(start, end);
|
||||
return !containsNone(start, end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains one or more of the characters
|
||||
* and strings of the given set.
|
||||
@ -1705,9 +1705,9 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final boolean containsSome(UnicodeSet s) {
|
||||
return !containsNone(s);
|
||||
return !containsNone(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this set contains one or more of the characters
|
||||
* of the given string.
|
||||
@ -1716,10 +1716,10 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final boolean containsSome(String s) {
|
||||
return !containsNone(s);
|
||||
return !containsNone(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds all of the elements in the specified set to this set if
|
||||
* they're not already present. This operation effectively
|
||||
@ -1950,7 +1950,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
int nestedPatStart = -1; // see below for usage
|
||||
boolean nestedPatDone = false; // see below for usage
|
||||
StringBuffer multiCharBuffer = new StringBuffer();
|
||||
|
||||
|
||||
|
||||
boolean invert = false;
|
||||
clear();
|
||||
@ -2095,7 +2095,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
rebuildPattern = true;
|
||||
|
||||
i = pp.getIndex(); // advance past property pattern
|
||||
|
||||
|
||||
if (mode == 3) {
|
||||
// Entire pattern is a category; leave parse
|
||||
// loop. This is one of 2 ways we leave this
|
||||
@ -2179,7 +2179,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
multiCharBuffer.setLength(0);
|
||||
while (i < pattern.length()) {
|
||||
int ch = UTF16.charAt(pattern, i);
|
||||
i += UTF16.getCharCount(ch);
|
||||
i += UTF16.getCharCount(ch);
|
||||
if (ch == '}') {
|
||||
length = -length; // signal that we saw '}'
|
||||
break;
|
||||
@ -2273,7 +2273,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
if (anchor == 2) {
|
||||
rebuildPattern = true;
|
||||
newPat.append(SymbolTable.SYMBOL_REF);
|
||||
add(TransliterationRule.ETHER);
|
||||
add(UnicodeMatcher.ETHER);
|
||||
}
|
||||
mode = 4;
|
||||
break;
|
||||
@ -2316,9 +2316,9 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
if (lastChar == SymbolTable.SYMBOL_REF && !isLastLiteral) {
|
||||
rebuildPattern = true;
|
||||
newPat.append((char) lastChar);
|
||||
add(TransliterationRule.ETHER);
|
||||
add(UnicodeMatcher.ETHER);
|
||||
}
|
||||
|
||||
|
||||
else if (lastChar != NONE) {
|
||||
add(lastChar, lastChar);
|
||||
_appendToPat(newPat, lastChar, false);
|
||||
@ -2612,7 +2612,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
private static final int max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Generic filter-based scanning code
|
||||
//----------------------------------------------------------------
|
||||
@ -2737,7 +2737,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
//----------------------------------------------------------------
|
||||
// Property set API
|
||||
//----------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Modifies this set to contain those code points which have the
|
||||
* given value for the given binary or enumerated property, as
|
||||
@ -2877,7 +2877,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
// valueAlias is empty. Interpret as General Category, Script,
|
||||
// Binary property, or ANY or ASCII. Upon success, p and v will
|
||||
// be set.
|
||||
try {
|
||||
try {
|
||||
p = UProperty.GENERAL_CATEGORY_MASK;
|
||||
v = UCharacter.getPropertyValueEnum(p, propertyAlias);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -2926,7 +2926,7 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
//----------------------------------------------------------------
|
||||
// Property set patterns
|
||||
//----------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Return true if the given position, in the given pattern, appears
|
||||
* to be the start of a property set pattern.
|
||||
@ -3000,12 +3000,12 @@ public class UnicodeSet extends UnicodeFilter {
|
||||
propName = pattern.substring(pos, equals);
|
||||
valueName = pattern.substring(equals+1, close);
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
// Handle case where no '=' is seen, and \N{}
|
||||
propName = pattern.substring(pos, close);
|
||||
valueName = "";
|
||||
|
||||
|
||||
// Handle \N{name}
|
||||
if (isName) {
|
||||
// This is a little inefficient since it means we have to
|
||||
|
@ -160,10 +160,10 @@ import java.util.Set;
|
||||
* to format dates.
|
||||
*
|
||||
* <p><strong>Field manipulation methods</strong></p>
|
||||
*
|
||||
*
|
||||
* <p><code>Calendar</code> fields can be changed using three methods:
|
||||
* <code>set()</code>, <code>add()</code>, and <code>roll()</code>.</p>
|
||||
*
|
||||
*
|
||||
* <p><strong><code>set(f, value)</code></strong> changes field
|
||||
* <code>f</code> to <code>value</code>. In addition, it sets an
|
||||
* internal member variable to indicate that field <code>f</code> has
|
||||
@ -178,7 +178,7 @@ import java.util.Set;
|
||||
* <code>get(f)</code> will not necessarily return <code>value</code>
|
||||
* after the fields have been recomputed. The specifics are determined by
|
||||
* the concrete calendar class.</p>
|
||||
*
|
||||
*
|
||||
* <p><em>Example</em>: Consider a <code>GregorianCalendar</code>
|
||||
* originally set to August 31, 1999. Calling <code>set(Calendar.MONTH,
|
||||
* Calendar.SEPTEMBER)</code> sets the calendar to September 31,
|
||||
@ -187,11 +187,11 @@ import java.util.Set;
|
||||
* call to <code>set(Calendar.DAY_OF_MONTH, 30)</code> before the call to
|
||||
* <code>getTime()</code> sets the calendar to September 30, 1999, since
|
||||
* no recomputation occurs after <code>set()</code> itself.</p>
|
||||
*
|
||||
*
|
||||
* <p><strong><code>add(f, delta)</code></strong> adds <code>delta</code>
|
||||
* to field <code>f</code>. This is equivalent to calling <code>set(f,
|
||||
* get(f) + delta)</code> with two adjustments:</p>
|
||||
*
|
||||
*
|
||||
* <blockquote>
|
||||
* <p><strong>Add rule 1</strong>. The value of field <code>f</code>
|
||||
* after the call minus the value of field <code>f</code> before the
|
||||
@ -199,7 +199,7 @@ import java.util.Set;
|
||||
* field <code>f</code>. Overflow occurs when a field value exceeds its
|
||||
* range and, as a result, the next larger field is incremented or
|
||||
* decremented and the field value is adjusted back into its range.</p>
|
||||
*
|
||||
*
|
||||
* <p><strong>Add rule 2</strong>. If a smaller field is expected to be
|
||||
* invariant, but it is impossible for it to be equal to its
|
||||
* prior value because of changes in its minimum or maximum after field
|
||||
@ -210,11 +210,11 @@ import java.util.Set;
|
||||
* that are not expected to be invariant. The calendar system
|
||||
* determines what fields are expected to be invariant.</p>
|
||||
* </blockquote>
|
||||
*
|
||||
*
|
||||
* <p>In addition, unlike <code>set()</code>, <code>add()</code> forces
|
||||
* an immediate recomputation of the calendar's milliseconds and all
|
||||
* fields.</p>
|
||||
*
|
||||
*
|
||||
* <p><em>Example</em>: Consider a <code>GregorianCalendar</code>
|
||||
* originally set to August 31, 1999. Calling <code>add(Calendar.MONTH,
|
||||
* 13)</code> sets the calendar to September 30, 2000. <strong>Add rule
|
||||
@ -226,19 +226,19 @@ import java.util.Set;
|
||||
* it is a smaller field, <code>DAY_OF_WEEK</code> is not adjusted by
|
||||
* rule 2, since it is expected to change when the month changes in a
|
||||
* <code>GregorianCalendar</code>.</p>
|
||||
*
|
||||
*
|
||||
* <p><strong><code>roll(f, delta)</code></strong> adds
|
||||
* <code>delta</code> to field <code>f</code> without changing larger
|
||||
* fields. This is equivalent to calling <code>add(f, delta)</code> with
|
||||
* the following adjustment:</p>
|
||||
*
|
||||
*
|
||||
* <blockquote>
|
||||
* <p><strong>Roll rule</strong>. Larger fields are unchanged after the
|
||||
* call. A larger field represents a larger unit of
|
||||
* time. <code>DAY_OF_MONTH</code> is a larger field than
|
||||
* <code>HOUR</code>.</p>
|
||||
* </blockquote>
|
||||
*
|
||||
*
|
||||
* <p><em>Example</em>: Consider a <code>GregorianCalendar</code>
|
||||
* originally set to August 31, 1999. Calling <code>roll(Calendar.MONTH,
|
||||
* 8)</code> sets the calendar to April 30, <strong>1999</strong>. Add
|
||||
@ -247,7 +247,7 @@ import java.util.Set;
|
||||
* be 31 in the month April. Add rule 2 sets it to the closest possible
|
||||
* value, 30. Finally, the <strong>roll rule</strong> maintains the
|
||||
* <code>YEAR</code> field value of 1999.</p>
|
||||
*
|
||||
*
|
||||
* <p><em>Example</em>: Consider a <code>GregorianCalendar</code>
|
||||
* originally set to Sunday June 6, 1999. Calling
|
||||
* <code>roll(Calendar.WEEK_OF_MONTH, -1)</code> sets the calendar to
|
||||
@ -261,7 +261,7 @@ import java.util.Set;
|
||||
* when changing the <code>WEEK_OF_MONTH</code>, is set to Tuesday, the
|
||||
* closest possible value to Sunday (where Sunday is the first day of the
|
||||
* week).</p>
|
||||
*
|
||||
*
|
||||
* <p><strong>Usage model</strong>. To motivate the behavior of
|
||||
* <code>add()</code> and <code>roll()</code>, consider a user interface
|
||||
* component with increment and decrement buttons for the month, day, and
|
||||
@ -285,7 +285,7 @@ import java.util.Set;
|
||||
* may give invalid results.
|
||||
*
|
||||
* <p><big><big><b>Calendar Architecture in ICU4J</b></big></big></p>
|
||||
*
|
||||
*
|
||||
* <p>Recently the implementation of <code>Calendar</code> has changed
|
||||
* significantly in order to better support subclassing. The original
|
||||
* <code>Calendar</code> class was designed to support subclassing, but
|
||||
@ -298,26 +298,26 @@ import java.util.Set;
|
||||
* ways in which <code>com.ibm.icu.util.Calendar</code> differs from
|
||||
* <code>java.util.Calendar</code>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p><big><b>Changes</b></big></p>
|
||||
*
|
||||
*
|
||||
* <p>Overview of changes between the classic <code>Calendar</code>
|
||||
* architecture and the new architecture.
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li>The <code>fields[]</code> array is <code>private</code> now
|
||||
* instead of <code>protected</code>. Subclasses must access it
|
||||
* using the methods {@link #internalSet} and
|
||||
* {@link #internalGet}. <b>Motivation:</b> Subclasses should
|
||||
* not directly access data members.</li>
|
||||
*
|
||||
*
|
||||
* <li>The <code>time</code> long word is <code>private</code> now
|
||||
* instead of <code>protected</code>. Subclasses may access it using
|
||||
* the method {@link #internalGetTimeInMillis}, which does not
|
||||
* provoke an update. <b>Motivation:</b> Subclasses should not
|
||||
* directly access data members.</li>
|
||||
*
|
||||
*
|
||||
* <li>The scope of responsibility of subclasses has been drastically
|
||||
* reduced. As much functionality as possible is implemented in the
|
||||
* <code>Calendar</code> base class. As a result, it is much easier
|
||||
@ -327,9 +327,9 @@ import java.util.Set;
|
||||
* week-related fields and time fields, the arithmetic
|
||||
* ({@link #add(int, int) add} and {@link #roll(int, int) roll}) behavior of many
|
||||
* fields, and the field validation system.</li>
|
||||
*
|
||||
*
|
||||
* <li>The subclassing API has been completely redesigned.</li>
|
||||
*
|
||||
*
|
||||
* <li>The <code>Calendar</code> base class contains some Gregorian
|
||||
* calendar algorithmic support that subclasses can use (specifically
|
||||
* in {@link #handleComputeFields}). Subclasses can use the
|
||||
@ -338,13 +338,13 @@ import java.util.Set;
|
||||
* <code>Calendar</code> subclasses in order to implement consistent
|
||||
* time zone behavior, and Gregorian-derived systems can use the
|
||||
* already computed data.</li>
|
||||
*
|
||||
*
|
||||
* <li>The <code>FIELD_COUNT</code> constant has been removed. Use
|
||||
* {@link #getFieldCount}. In addition, framework API has been
|
||||
* added to allow subclasses to define additional fields.
|
||||
* <b>Motivation: </b>The number of fields is not constant across
|
||||
* calendar systems.</li>
|
||||
*
|
||||
*
|
||||
* <li>The range of handled dates has been narrowed from +/-
|
||||
* ~300,000,000 years to +/- ~5,000,000 years. In practical terms
|
||||
* this should not affect clients. However, it does mean that client
|
||||
@ -362,29 +362,29 @@ import java.util.Set;
|
||||
* special case code that was used to accomodate arithmetic overflow
|
||||
* at millis near <code>Long.MIN_VALUE</code> and
|
||||
* <code>Long.MAX_VALUE</code>.</li>
|
||||
*
|
||||
*
|
||||
* <li>New fields are implemented: {@link #JULIAN_DAY} defines
|
||||
* single-field specification of the
|
||||
* date. {@link #MILLISECONDS_IN_DAY} defines a single-field
|
||||
* specification of the wall time. {@link #DOW_LOCAL} and
|
||||
* {@link #YEAR_WOY} implement localized day-of-week and
|
||||
* week-of-year behavior.</li>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses can access millisecond constants
|
||||
* {@link #ONE_SECOND}, {@link #ONE_MINUTE},
|
||||
* {@link #ONE_HOUR}, {@link #ONE_DAY}, and
|
||||
* {@link #ONE_WEEK} defined in <code>Calendar</code>.</li>
|
||||
*
|
||||
*
|
||||
* <li>New API has been added to suport calendar-specific subclasses
|
||||
* of <code>DateFormat</code>.</li>
|
||||
*
|
||||
*
|
||||
* <li>Several subclasses have been implemented, representing
|
||||
* various international calendar systems.</li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p><big><b>Subclass API</b></big></p>
|
||||
*
|
||||
*
|
||||
* <p>The original <code>Calendar</code> API was based on the experience
|
||||
* of implementing a only a single subclass,
|
||||
* <code>GregorianCalendar</code>. As a result, all of the subclassing
|
||||
@ -396,29 +396,29 @@ import java.util.Set;
|
||||
* these. Subclasses are able to allocate the <code>fields</code> array
|
||||
* through a protected framework method; this allows subclasses to
|
||||
* specify additional fields. </p>
|
||||
*
|
||||
*
|
||||
* <p>More functionality has been moved into the base class. The base
|
||||
* class now contains much of the computational machinery to support the
|
||||
* Gregorian calendar. This is based on two things: (1) Many calendars
|
||||
* are based on the Gregorian calendar (such as the Buddhist and Japanese
|
||||
* imperial calendars). (2) <em>All</em> calendars require basic
|
||||
* Gregorian support in order to handle timezone computations. </p>
|
||||
*
|
||||
*
|
||||
* <p>Common computations have been moved into
|
||||
* <code>Calendar</code>. Subclasses no longer compute the week related
|
||||
* fields and the time related fields. These are commonly handled for all
|
||||
* calendars by the base class. </p>
|
||||
*
|
||||
*
|
||||
* <p><b>Subclass computation of time <tt>=></tt> fields</b>
|
||||
*
|
||||
*
|
||||
* <p>The {@link #ERA}, {@link #YEAR},
|
||||
* {@link #EXTENDED_YEAR}, {@link #MONTH},
|
||||
* {@link #DAY_OF_MONTH}, and {@link #DAY_OF_YEAR} fields are
|
||||
* computed by the subclass, based on the Julian day. All other fields
|
||||
* are computed by <code>Calendar</code>.
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses should implement {@link #handleComputeFields}
|
||||
* to compute the {@link #ERA}, {@link #YEAR},
|
||||
* {@link #EXTENDED_YEAR}, {@link #MONTH},
|
||||
@ -433,11 +433,11 @@ import java.util.Set;
|
||||
* calendar. Within this method, subclasses may call
|
||||
* <code>getGregorianXxx()</code> to obtain the Gregorian calendar
|
||||
* month, day of month, and extended year for the given date.</li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p><b>Subclass computation of fields <tt>=></tt> time</b>
|
||||
*
|
||||
*
|
||||
* <p>The interpretation of most field values is handled entirely by
|
||||
* <code>Calendar</code>. <code>Calendar</code> determines which fields
|
||||
* are set, which are not, which are set more recently, and so on. In
|
||||
@ -446,39 +446,39 @@ import java.util.Set;
|
||||
* thing the subclass must do is determine the extended year, based on
|
||||
* the year fields, and then, given an extended year and a month, it must
|
||||
* return a Julian day number.
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses should implement {@link #handleGetExtendedYear}
|
||||
* to return the extended year for this calendar system, based on the
|
||||
* {@link #YEAR}, {@link #EXTENDED_YEAR}, and any fields that
|
||||
* the calendar system uses that are larger than a year, such as
|
||||
* {@link #ERA}.</li>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses should implement {@link #handleComputeMonthStart}
|
||||
* to return the Julian day number
|
||||
* associated with a month and extended year. This is the Julian day
|
||||
* number of the day before the first day of the month. The month
|
||||
* number is zero-based. This computation should not depend on any
|
||||
* field values.</li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p><b>Other methods</b>
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses should implement {@link #handleGetMonthLength}
|
||||
* to return the number of days in a
|
||||
* given month of a given extended year. The month number, as always,
|
||||
* is zero-based.</li>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses should implement {@link #handleGetYearLength}
|
||||
* to return the number of days in the given
|
||||
* extended year. This method is used by
|
||||
* <tt>computeWeekFields</tt> to compute the
|
||||
* {@link #WEEK_OF_YEAR} and {@link #YEAR_WOY} fields.</li>
|
||||
*
|
||||
*
|
||||
* <li>Subclasses should implement {@link #handleGetLimit}
|
||||
* to return the {@link #MINIMUM},
|
||||
* {@link #GREATEST_MINIMUM}, {@link #LEAST_MAXIMUM}, or
|
||||
@ -491,7 +491,7 @@ import java.util.Set;
|
||||
* {@link #EXTENDED_YEAR}. Other fields are invariant (with
|
||||
* respect to calendar system) and are handled by the base
|
||||
* class.</li>
|
||||
*
|
||||
*
|
||||
* <li>Optionally, subclasses may override {@link #validateField}
|
||||
* to check any subclass-specific fields. If the
|
||||
* field's value is out of range, the method should throw an
|
||||
@ -499,7 +499,7 @@ import java.util.Set;
|
||||
* <code>super.validateField(field)</code> to handle fields in a
|
||||
* generic way, that is, to compare them to the range
|
||||
* <code>getMinimum(field)</code>..<code>getMaximum(field)</code>.</li>
|
||||
*
|
||||
*
|
||||
* <li>Optionally, subclasses may override
|
||||
* {@link #handleCreateFields} to create an <code>int[]</code>
|
||||
* array large enough to hold the calendar's fields. This is only
|
||||
@ -507,14 +507,14 @@ import java.util.Set;
|
||||
* defined by <code>Calendar</code>. The length of the result must be
|
||||
* at least {@link #BASE_FIELD_COUNT} and no more than
|
||||
* {@link #MAX_FIELD_COUNT}.</li>
|
||||
*
|
||||
*
|
||||
* <li>Optionally, subclasses may override
|
||||
* {@link #handleGetDateFormat} to create a
|
||||
* <code>DateFormat</code> appropriate to this calendar. This is only
|
||||
* required if a calendar subclass redefines the use of a field (for
|
||||
* example, changes the {@link #ERA} field from a symbolic field
|
||||
* to a numeric one) or defines an additional field.</li>
|
||||
*
|
||||
*
|
||||
* <li>Optionally, subclasses may override {@link #roll roll} and
|
||||
* {@link #add add} to handle fields that are discontinuous. For
|
||||
* example, in the Hebrew calendar the month "Adar I" only
|
||||
@ -526,16 +526,16 @@ import java.util.Set;
|
||||
* (Adar) in a non-leap year. The protected utility method {@link
|
||||
* #pinField pinField} is often useful when implementing these two
|
||||
* methods. </li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p><big><b>Normalized behavior</b></big>
|
||||
*
|
||||
*
|
||||
* <p>The behavior of certain fields has been made consistent across all
|
||||
* calendar systems and implemented in <code>Calendar</code>.
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li>Time is normalized. Even though some calendar systems transition
|
||||
* between days at sunset or at other times, all ICU4J calendars
|
||||
* transition between days at <em>local zone midnight</em>. This
|
||||
@ -545,7 +545,7 @@ import java.util.Set;
|
||||
* {@link #HOUR}, {@link #HOUR_OF_DAY}, {@link #MINUTE},
|
||||
* {@link #SECOND}, {@link #MILLISECOND},
|
||||
* {@link #ZONE_OFFSET}, and {@link #DST_OFFSET}.</li>
|
||||
*
|
||||
*
|
||||
* <li>DST behavior is normalized. Daylight savings time behavior is
|
||||
* computed the same for all calendar systems, and depends on the
|
||||
* value of several <code>GregorianCalendar</code> fields: the
|
||||
@ -553,7 +553,7 @@ import java.util.Set;
|
||||
* {@link #DAY_OF_MONTH}. As a result, <code>Calendar</code>
|
||||
* always computes these fields, even for non-Gregorian calendar
|
||||
* systems. These fields are available to subclasses.</li>
|
||||
*
|
||||
*
|
||||
* <li>Weeks are normalized. Although locales define the week
|
||||
* differently, in terms of the day on which it starts, and the
|
||||
* designation of week number one of a month or year, they all use a
|
||||
@ -568,11 +568,11 @@ import java.util.Set;
|
||||
* {@link #EXTENDED_YEAR}, {@link #DAY_OF_YEAR},
|
||||
* {@link #MONTH}, and {@link #DAY_OF_MONTH}, which are
|
||||
* computed by the subclass.</li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p><big><b>Supported range</b></big>
|
||||
*
|
||||
*
|
||||
* <p>The allowable range of <code>Calendar</code> has been
|
||||
* narrowed. <code>GregorianCalendar</code> used to attempt to support
|
||||
* the range of dates with millisecond values from
|
||||
@ -588,11 +588,11 @@ import java.util.Set;
|
||||
* {@link #MAX_DATE} (or {@link #MAX_MILLIS} or
|
||||
* {@link #MAX_JULIAN}) in <code>Calendar</code> to specify an
|
||||
* extremely early or extremely late date.</p>
|
||||
*
|
||||
*
|
||||
* <p><big><b>General notes</b></big>
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li>Calendars implementations are <em>proleptic</em>. For example,
|
||||
* even though the Gregorian calendar was not instituted until the
|
||||
* 16th century, the <code>GregorianCalendar</code> class supports
|
||||
@ -606,7 +606,7 @@ import java.util.Set;
|
||||
* {@link #YEAR}, {@link #ERA}, etc. fields. Then, if the
|
||||
* calendar is set to not be lenient, out-of-range field values will
|
||||
* trigger an exception.</li>
|
||||
*
|
||||
*
|
||||
* <li>Calendar system subclasses compute a <em>extended
|
||||
* year</em>. This differs from the {@link #YEAR} field in that
|
||||
* it ranges over all integer values, including zero and negative
|
||||
@ -620,7 +620,7 @@ import java.util.Set;
|
||||
* + 20 * BAKTUN)</code>. The <code>Calendar</code> base class uses
|
||||
* the {@link #EXTENDED_YEAR} field to compute the week-related
|
||||
* fields.</li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* @see Date
|
||||
@ -935,7 +935,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public static final int MILLISECONDS_IN_DAY = 21;
|
||||
|
||||
|
||||
/**
|
||||
* The number of fields defined by this class. Subclasses may define
|
||||
* addition fields starting with this number.
|
||||
@ -1423,7 +1423,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
// areFieldsSet, and isTimeSet become transient, and isSet[] is
|
||||
// removed. In JDK 1.1.6 we write a format compatible with version 2.
|
||||
// static final int currentSerialVersion = 1;
|
||||
|
||||
|
||||
/**
|
||||
* The version of the serialized data on the stream. Possible values:
|
||||
* <dl>
|
||||
@ -1666,7 +1666,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
/**
|
||||
* Registers a default CalendarFactory for the provided locale.
|
||||
* If the factory has not already been registered with
|
||||
* registerFactory, it will be.
|
||||
* registerFactory, it will be.
|
||||
* @prototype
|
||||
*/
|
||||
/* public */ static Object register(CalendarFactory factory, Locale locale, boolean visible) {
|
||||
@ -1680,12 +1680,12 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the CalendarFactory associated with this key
|
||||
* Unregister the CalendarFactory associated with this key
|
||||
* (obtained from register).
|
||||
* @prototype
|
||||
*/
|
||||
/* public */ static boolean unregister(Object registryKey) {
|
||||
return service == null
|
||||
return service == null
|
||||
? false
|
||||
: service.unregisterFactory((Factory)registryKey);
|
||||
}
|
||||
@ -1728,7 +1728,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* Note: Calling <code>setTime()</code> with
|
||||
* <code>Date(Long.MAX_VALUE)</code> or <code>Date(Long.MIN_VALUE)</code>
|
||||
* may yield incorrect field values from <code>get()</code>.
|
||||
* @param date the given Date.
|
||||
* @param date the given Date.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public final void setTime(Date date) {
|
||||
@ -1786,7 +1786,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
{
|
||||
return fields[field];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the value for a given time field, or return the given default
|
||||
* value if the field is not set. This is an internal method for
|
||||
@ -1960,7 +1960,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* the equals() method to return true, the other Calendar must
|
||||
* be set to the same time.
|
||||
*
|
||||
* @param other the Calendar to be compared with this Calendar
|
||||
* @param other the Calendar to be compared with this Calendar
|
||||
* @draft ICU 2.4
|
||||
*/
|
||||
public boolean isEquivalentTo(Calendar other) {
|
||||
@ -1973,7 +1973,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
|
||||
/**
|
||||
* Returns a hash code for this calendar.
|
||||
* @return a hash code value for this object.
|
||||
* @return a hash code value for this object.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
public int hashCode() {
|
||||
@ -2045,7 +2045,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* DAY_OF_WEEK; it returns the maximum for any day of week in the
|
||||
* current month. Likewise for the WEEK_OF_MONTH and WEEK_OF_YEAR
|
||||
* fields.
|
||||
*
|
||||
*
|
||||
* @param field the field whose maximum is desired
|
||||
* @return the maximum of the given field for the current date of this calendar
|
||||
* @see #getMaximum
|
||||
@ -2054,7 +2054,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
*/
|
||||
public int getActualMaximum(int field) {
|
||||
int result;
|
||||
|
||||
|
||||
switch (field) {
|
||||
case DAY_OF_MONTH:
|
||||
{
|
||||
@ -2095,7 +2095,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the minimum value that this field could have, given the current date.
|
||||
* For most fields, this is the same as {@link #getMinimum getMinimum}
|
||||
@ -2108,7 +2108,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* there will be four or more days in the first week, so it will be week number 1,
|
||||
* and <code>getActualMinimum(WEEK_OF_MONTH)</code> will return 1. However,
|
||||
* if the first of the month is a Thursday, Friday, or Saturday, there are
|
||||
* <em>not</em> four days in that week, so it is week number 0, and
|
||||
* <em>not</em> four days in that week, so it is week number 0, and
|
||||
* <code>getActualMinimum(WEEK_OF_MONTH)</code> will return 0.
|
||||
* <p>
|
||||
* @param field the field whose actual minimum value is desired.
|
||||
@ -2120,7 +2120,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
*/
|
||||
public int getActualMinimum(int field) {
|
||||
int result;
|
||||
|
||||
|
||||
switch (field) {
|
||||
case DAY_OF_WEEK:
|
||||
case AM_PM:
|
||||
@ -2137,7 +2137,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
// These fields all have fixed minima/maxima
|
||||
result = getMinimum(field);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
// For all other fields, do it the hard way....
|
||||
result = getActualHelper(field, getGreatestMinimum(field), getMinimum(field));
|
||||
@ -2176,7 +2176,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
case EXTENDED_YEAR:
|
||||
set(DAY_OF_YEAR, getGreatestMinimum(DAY_OF_YEAR));
|
||||
break;
|
||||
|
||||
|
||||
case MONTH:
|
||||
set(DAY_OF_MONTH, getGreatestMinimum(DAY_OF_MONTH));
|
||||
break;
|
||||
@ -2187,7 +2187,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
set(DAY_OF_MONTH, 1);
|
||||
set(DAY_OF_WEEK, get(DAY_OF_WEEK)); // Make this user set
|
||||
break;
|
||||
|
||||
|
||||
case WEEK_OF_MONTH:
|
||||
case WEEK_OF_YEAR:
|
||||
// If we're counting weeks, set the day of the week to either the
|
||||
@ -2216,7 +2216,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
if (startValue == endValue) {
|
||||
// if we know that the maximum value is always the same, just return it
|
||||
return startValue;
|
||||
}
|
||||
}
|
||||
|
||||
final int delta = (endValue > startValue) ? 1 : -1;
|
||||
|
||||
@ -2225,7 +2225,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
Calendar work = (Calendar) clone();
|
||||
work.setLenient(true);
|
||||
work.prepareGetActual(field, delta < 0);
|
||||
|
||||
|
||||
// now try each value from the start to the end one by one until
|
||||
// we get a value that normalizes to another value. The last value that
|
||||
// normalizes to itself is the actual maximum for the current date
|
||||
@ -2242,7 +2242,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rolls (up/down) a single unit of time on the given field. If the
|
||||
* field is rolled past its maximum allowable value, it will "wrap" back
|
||||
@ -2299,7 +2299,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* example, to roll the current date up by three days, you can call
|
||||
* <code>roll(Calendar.DATE, 3)</code>. If the
|
||||
* field is rolled past its maximum allowable value, it will "wrap" back
|
||||
* to its minimum and continue rolling.
|
||||
* to its minimum and continue rolling.
|
||||
* For example, calling <code>roll(Calendar.DATE, 10)</code>
|
||||
* on a Gregorian calendar set to 4/25/96 will result in the date 4/5/96.
|
||||
* <p>
|
||||
@ -2336,7 +2336,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* down must overide <code>roll</code> to handle those fields specially.
|
||||
* For example, in the Hebrew calendar the month "Adar I"
|
||||
* only occurs in leap years; in other years the calendar jumps from
|
||||
* Shevat (month #4) to Adar (month #6). The
|
||||
* Shevat (month #4) to Adar (month #6). The
|
||||
* {@link HebrewCalendar#roll HebrewCalendar.roll} method takes this into account,
|
||||
* so that rolling the month of Shevat by one gives the proper result (Adar) in a
|
||||
* non-leap year.
|
||||
@ -2415,12 +2415,12 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
{
|
||||
int max = getActualMaximum(MONTH);
|
||||
int mon = (internalGet(MONTH) + amount) % (max+1);
|
||||
|
||||
|
||||
if (mon < 0) {
|
||||
mon += (max + 1);
|
||||
}
|
||||
set(MONTH, mon);
|
||||
|
||||
|
||||
// Keep the day of month in range. We don't want to spill over
|
||||
// into the next month; e.g., we don't want jan31 + 1 mo -> feb31 ->
|
||||
// mar3.
|
||||
@ -2636,11 +2636,11 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
") not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a signed amount to a specified field, using this calendar's rules.
|
||||
* For example, to add three days to the current date, you can call
|
||||
* <code>add(Calendar.DATE, 3)</code>.
|
||||
* <code>add(Calendar.DATE, 3)</code>.
|
||||
* <p>
|
||||
* When adding to certain fields, the values of other fields may conflict and
|
||||
* need to be changed. For example, when adding one to the {@link #MONTH MONTH} field
|
||||
@ -2673,7 +2673,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* down must overide <code>add</code> to handle those fields specially.
|
||||
* For example, in the Hebrew calendar the month "Adar I"
|
||||
* only occurs in leap years; in other years the calendar jumps from
|
||||
* Shevat (month #4) to Adar (month #6). The
|
||||
* Shevat (month #4) to Adar (month #6). The
|
||||
* {@link HebrewCalendar#add HebrewCalendar.add} method takes this into account,
|
||||
* so that adding one month
|
||||
* to a date in Shevat gives the proper result (Adar) in a non-leap year.
|
||||
@ -2699,7 +2699,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
// result of the add operation is to move from DST to Standard, or
|
||||
// vice versa, we need to adjust by an hour forward or back,
|
||||
// respectively. For such fields we set keepHourInvariant to true.
|
||||
|
||||
|
||||
// We only adjust the DST for fields larger than an hour. For
|
||||
// fields smaller than an hour, we cannot adjust for DST without
|
||||
// causing problems. for instance, if you add one hour to April 5,
|
||||
@ -2728,7 +2728,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
set(field, get(field) + amount);
|
||||
pinField(DAY_OF_MONTH);
|
||||
return;
|
||||
|
||||
|
||||
case WEEK_OF_YEAR:
|
||||
case WEEK_OF_MONTH:
|
||||
case DAY_OF_WEEK_IN_MONTH:
|
||||
@ -2791,7 +2791,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of this calendar in the language of the given locale.
|
||||
* @stable ICU 2.0
|
||||
@ -2799,7 +2799,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
public String getDisplayName(Locale loc) {
|
||||
return this.getClass().getName();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Interface for creating custon DateFormats for different types of Calendars
|
||||
//-------------------------------------------------------------------------
|
||||
@ -2830,7 +2830,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
DateFormatSymbols symbols = new DateFormatSymbols(this, locale);
|
||||
return new SimpleDateFormat(pattern, symbols);
|
||||
}
|
||||
|
||||
|
||||
static private DateFormat formatHelper(Calendar cal, Locale loc,
|
||||
int dateStyle, int timeStyle)
|
||||
{
|
||||
@ -2878,7 +2878,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
// Protected utility methods for use by subclasses. These are very handy
|
||||
// for implementing add, roll, and computeFields.
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Adjust the specified field so that it is within
|
||||
* the allowable range for the date to which this calendar is set.
|
||||
@ -2909,7 +2909,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
protected void pinField(int field) {
|
||||
int max = getActualMaximum(field);
|
||||
int min = getActualMinimum(field);
|
||||
|
||||
|
||||
if (fields[field] > max) {
|
||||
set(field, max);
|
||||
} else if (fields[field] < min) {
|
||||
@ -2921,10 +2921,10 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* Return the week number of a day, within a period. This may be the week number in
|
||||
* a year or the week number in a month. Usually this will be a value >= 1, but if
|
||||
* some initial days of the period are excluded from week 1, because
|
||||
* {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
|
||||
* {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
|
||||
* the week number will be zero for those
|
||||
* initial days. This method requires the day number and day of week for some
|
||||
* known date in the period in order to determine the day of week
|
||||
* known date in the period in order to determine the day of week
|
||||
* on the desired day.
|
||||
* <p>
|
||||
* <b>Subclassing:</b>
|
||||
@ -2986,7 +2986,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* some initial days of the period are excluded from week 1, because
|
||||
* {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1,
|
||||
* then the week number will be zero for those
|
||||
* initial days. This method requires the day of week for the given date in order to
|
||||
* initial days. This method requires the day of week for the given date in order to
|
||||
* determine the result.
|
||||
* <p>
|
||||
* <b>Subclassing:</b>
|
||||
@ -3018,7 +3018,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
//-------------------------------------------------------------------------
|
||||
// Constants
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* [NEW]
|
||||
* Return the difference between the given time and the time this
|
||||
@ -3466,7 +3466,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
if (dayOfWeek > weekendCease && dayOfWeek < weekendOnset) {
|
||||
return WEEKDAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dayOfWeek == weekendOnset) {
|
||||
return (weekendOnsetMillis == 0) ? WEEKEND : WEEKEND_ONSET;
|
||||
}
|
||||
@ -3600,11 +3600,11 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this calendar. This method
|
||||
* is intended to be used only for debugging purposes, and the
|
||||
* format of the returned string may vary between implementations.
|
||||
* Return a string representation of this calendar. This method
|
||||
* is intended to be used only for debugging purposes, and the
|
||||
* format of the returned string may vary between implementations.
|
||||
* The returned string may be empty but may not be <code>null</code>.
|
||||
*
|
||||
*
|
||||
* @return a string representation of this calendar.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
@ -3645,10 +3645,10 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
{
|
||||
/* try to get the Locale data from the cache */
|
||||
int[] data = (int[]) cachedLocaleData.get(desiredLocale);
|
||||
|
||||
if (data == null) { /* cache miss */
|
||||
ResourceBundle resource = ICULocaleData.getLocaleElements(desiredLocale);
|
||||
String[] dateTimePatterns =
|
||||
resource.getStringArray("DateTimeElements");
|
||||
String[] dateTimePatterns = resource.getStringArray("DateTimeElements");
|
||||
data = new int[2];
|
||||
data[0] = Integer.parseInt(dateTimePatterns[0]);
|
||||
data[1] = Integer.parseInt(dateTimePatterns[1]);
|
||||
@ -3707,7 +3707,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
*/
|
||||
private void readObject(ObjectInputStream stream)
|
||||
throws IOException, ClassNotFoundException {
|
||||
|
||||
|
||||
stream.defaultReadObject();
|
||||
|
||||
initInternal();
|
||||
@ -3843,7 +3843,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
}
|
||||
fields[DOW_LOCAL] = dowLocal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute the Gregorian calendar year, month, and day of month from the
|
||||
* Julian day. These values are not stored in fields, but in member
|
||||
@ -4094,7 +4094,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
protected final int getStamp(int field) {
|
||||
return stamp[field];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the field that is newer, either defaultField, or
|
||||
* alternateField. If neither is newer or neither is set, return defaultField.
|
||||
@ -4181,7 +4181,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
validateFields();
|
||||
}
|
||||
|
||||
// Compute the Julian day
|
||||
// Compute the Julian day
|
||||
int julianDay = computeJulianDay();
|
||||
|
||||
long millis = julianDayToMillis(julianDay);
|
||||
@ -4450,7 +4450,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
if (first < 0) {
|
||||
first += 7;
|
||||
}
|
||||
|
||||
|
||||
// Get zero-based localized DOW, valid range 0..6. This is the DOW
|
||||
// we are looking for.
|
||||
int dowLocal = 0;
|
||||
@ -4484,7 +4484,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
int dim = internalGet(DAY_OF_WEEK_IN_MONTH, 1);
|
||||
if (dim >= 0) {
|
||||
date += 7*(dim - 1);
|
||||
|
||||
|
||||
} else {
|
||||
// Move date to the last of this day-of-week in this month,
|
||||
// then back up as needed. If dim==-1, we don't back up at
|
||||
@ -4565,7 +4565,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
* <li>DAY_OF_MONTH
|
||||
* <li>DAY_OF_YEAR
|
||||
* <li>EXTENDED_YEAR</ul>
|
||||
*
|
||||
*
|
||||
* Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which
|
||||
* will be set when this method is called. Subclasses can also call
|
||||
* the getGregorianXxx() methods to obtain Gregorian calendar
|
||||
@ -4779,7 +4779,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
remainder[0] = numerator % denominator;
|
||||
return numerator / denominator;
|
||||
}
|
||||
int quotient = ((numerator + 1) / denominator) - 1;
|
||||
int quotient = ((numerator + 1) / denominator) - 1;
|
||||
remainder[0] = numerator - (quotient * denominator);
|
||||
return quotient;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user