ICU-1678 Add locale converter tool

X-SVN-Rev: 7538
This commit is contained in:
Ram Viswanadha 2002-01-31 01:22:25 +00:00
parent 40ac5aa3b0
commit 0748195513
62 changed files with 13432 additions and 0 deletions

View file

@ -0,0 +1,93 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ArrayEnumeration.java,v $
* $Date: 2002/01/31 01:21:23 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.util.*;
public final class ArrayEnumeration implements Enumeration {
public ArrayEnumeration(Object[] array, int start, int limit) {
this.array = array;
position = start;
this.limit = limit;
}
public ArrayEnumeration(byte[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Byte(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(char[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Character(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(short[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Short(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(int[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Integer(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(float[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Float(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(double[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Double(array[i]);
}
position = start;
this.limit = limit;
}
public boolean hasMoreElements() {
return position < limit;
}
public Object nextElement() {
if (position < limit)
return array[position++];
else
throw new java.util.NoSuchElementException();
}
// privates
private Object[] array;
private int position = 0;
private int limit = 0;
}

View file

@ -0,0 +1,95 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/CollationItem.java,v $
* $Date: 2002/01/31 01:21:23 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* A CollationItem represents a single entry in a collation sequence.
*/
public class CollationItem {
private static final char[] OP_CHARS = {'=', '<', ';', ',', '&' };
private static final char[] SPECIAL_CHARS = { '&', '@' , '=', '<', ';', ',' };
public static final int NONE = 0;
public static final int PRIMARY = 1;
public static final int SECONDARY = 2;
public static final int TERTIARY = 3;
private static final int FIRST = 4;
public int op;
public String item;
public String expansion;
public String comment;
public static final CollationItem FORWARD = new CollationItem(NONE, "") {
public String toString() { return ""; }
};
public static final CollationItem BACKWARD = new CollationItem(NONE, "") {
public String toString() { return "@"; }
};
public CollationItem(String item) {
this.op = FIRST;
this.item = cleanString(item);
this.expansion = "";
}
public CollationItem(int op, String item) {
this(op, item, null);
}
public CollationItem(int op, String item, String expansion) {
this.op = Math.abs(op);
if (this.op > TERTIARY) this.op = TERTIARY;
this.item = cleanString(item);
this.expansion = cleanString(expansion);
}
public void setComment(String comment) {
this.comment = comment;
}
public String toString() {
String itemString = item;
if (expansion.length() == 0) {
return ""+OP_CHARS[op]+item;
} else {
return "&"+expansion+OP_CHARS[op]+item;
}
}
private String cleanString(String source) {
if (source == null) return "";
String result = source;
for (int i = 0; i < result.length(); i++) {
final char c = result.charAt(i);
if ((c == '@') || (c == '\t') || (c == '\n')
|| (c == '\f') || (c =='\r') || (c == '\013')
|| ((c <= '\u002F') && (c >= '\u0020'))
|| ((c <= '\u003F') && (c >= '\u003A'))
|| ((c <= '\u0060') && (c >= '\u005B'))
|| ((c <= '\u007E') && (c >= '\u007B'))) {
if (i < result.length()-1) {
result = result.substring(0, i)
+ "'" + c +"'"
+ result.substring(i+1);
} else {
result = result.substring(0, i)
+ "'" + c +"'";
}
i += 2; //skip the two characters we inserted
}
}
return result;
}
}

View file

@ -0,0 +1,20 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/Comparable.java,v $
* $Date: 2002/01/31 01:21:24 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
public interface Comparable {
/**
returns 0 if objects are equal, -1 if a is less than b, 1 otherwise.
*/
public int compareTo(Object b);
}

View file

@ -0,0 +1,20 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/Comparator.java,v $
* $Date: 2002/01/31 01:21:27 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
public interface Comparator {
/**
returns 0 if objects are equal, -1 if a is less than b, 1 otherwise.
*/
public int compare(Object a, Object b);
}

View file

@ -0,0 +1,73 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ComplexTransition.java,v $
* $Date: 2002/01/31 01:21:27 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* A ComplexTransition is conceptually a single transition that
* consumes multiple input characters.
*/
public abstract class ComplexTransition implements Lex.Transition {
//the value that is returned by subclasses indicating that
//the transition was successfull. This value is then
//discarded and the value passed to the constructor
//is then returned to the caller.
protected static final int SUCCESS = Lex.END_OF_FILE - 1;
private int success; //value to return if successfull
private Lex parser; //the parser used for this transition
public ComplexTransition(int success) {
this.success = success;
this.parser = new Lex(null);
//this.parser.debug(true);
}
public int doAction(int c, PushbackReader input, StringBuffer buffer) throws IOException {
input.unread(c);
parser.setStates(getStates());
parser.setInput(input);
try {
int s = parser.nextToken();
handleSuccess(parser, buffer);
return success;
} catch (IOException e) {
handleFailure(parser, buffer);
throw e;
}
}
//called after a successful parse
protected void handleSuccess(Lex parser, StringBuffer output) throws IOException {
parser.appendDataTo(output);
}
//called after a failed parse
protected void handleFailure(Lex parser, StringBuffer output) {
}
//subclasses should return the states to use to parse this
//transition
protected abstract Lex.Transition[][] getStates();
public ComplexTransition debug(boolean debug) {
parser.debug(debug);
return this;
}
public ComplexTransition debug(boolean debug, String tag) {
parser.debug(debug, tag);
return this;
}
}

View file

@ -0,0 +1,88 @@
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
The ConvertJavaLocale application converts java locales to
Java and ICU Locale files. It's usage is as follows
ConvertJavaLocale [-11] [-12] [-icu] locale...
Usage
-11
If this option is specified, data is output in
Java 1.1.x locale format.
-12
If this option is specified, data is output in
Java 1.2.x locale format. If an output format
is not specified, -12 is the default.
-icu
If this option is specified, data is output in
ICU locale format.
locale
The locale to convert
*/
import java.lang.reflect.*;
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ConvertAllJavaLocales.java,v $
* $Date: 2002/01/31 01:21:28 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
public class ConvertAllJavaLocales {
public static void main(String args[]) {
try {
new ConvertAllJavaLocales(args);
} catch (Throwable t) {
System.err.println("Unknown error: "+t);
}
}
public ConvertAllJavaLocales(String argsIn[]) {
try {
String packageName = argsIn[0];
System.out.println("This is the packagename : "+packageName);
String classname = packageName+".Locale";
//classname.concat();
System.out.println("This is the classname : "+classname);
/* Class cl = Class.forName(classname);
Class[] paramList=null;
Method gvl = cl.getMethod("getAvailableLocales", paramList);
Object[] params = new Object[]{""};
gvl.invoke(null,params);*/
final Locale[] locales = java.util.Locale.getAvailableLocales();//(Locale[])gvl.invoke(null,params);;
for (int i = 0; i < locales.length; i++) {
final String localeName = locales[i].toString();
final String[] args = {"-package",packageName,"-icu", localeName};
System.out.println("Converting "+localeName);
final FileOutputStream outFile = new FileOutputStream("ICULocale_"+localeName);
final PrintStream out = new PrintStream(outFile, true);
new ConvertJavaLocale(args, out);
out.close();
}
} catch (IOException e) {
System.err.println("Unexpected IO error");
}catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,196 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ConvertJavaLocale.java,v $
* $Date: 2002/01/31 01:21:29 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
The ConvertJavaLocale application converts java locales to
Java and ICU Locale files. It's usage is as follows
ConvertJavaLocale [-11] [-12] [-icu] locale...
Usage
-11
If this option is specified, data is output in
Java 1.1.x locale format.
-12
If this option is specified, data is output in
Java 1.2.x locale format. If an output format
is not specified, -12 is the default.
-icu
If this option is specified, data is output in
ICU locale format.
locale
The locale to convert
*/
public class ConvertJavaLocale {
private static final byte OPT_11 = (byte)0x01;
private static final byte OPT_12 = (byte)0x02;
private static final byte OPT_ICU = (byte)0x04;
private static final byte OPT_PACKAGE = (byte)0x08;
private static final byte OPT_UNKNOWN = (byte)0x80;
private static final String USER_OPTIONS[] = {
"-11",
"-12",
"-icu",
"-package"
};
private static final String[] tags = {
"LocaleString",
"LocaleID",
"ShortLanguage",
"ShortCountry",
"Languages",
"Countries",
"MonthNames",
"MonthAbbreviations",
"DayNames",
"DayAbbreviations",
"AmPmMarkers",
"Eras",
"NumberPatterns",
"NumberElements",
"CurrencyElements",
"DateTimePatterns",
"DateTimeElements",
"CollationElements",
"zoneStrings",
"localPatternChars",
};
public static void main(String args[]) {
try {
new ConvertJavaLocale(args, System.out);
} catch (Throwable t) {
System.err.println("Unknown error: "+t);
}
}
public ConvertJavaLocale(String args[], PrintStream out) {
process(args, out);
}
public void process(String args[], PrintStream out) {
short options = identifyOptions(args);
if ((args.length < 1) || ((options & OPT_UNKNOWN) != 0)) {
printUsage();
} else {
String localeName = null;
String packagename = null;
for (int i = 0; i < args.length; i++) {
final String thisArg = args[i];
if(args[i].equalsIgnoreCase("-package")){
i++;
packagename = args[i];
}else if(args[i].equalsIgnoreCase("-icu")){
}else if (!args[i].startsWith("-")) {
localeName = args[i];
}
}
final Hashtable data = new Hashtable();
final String localeElements = packagename+".LocaleElements" +
(String)((localeName != null) ? "_"+localeName : "");
final String DateFormatZoneData = packagename+".DateFormatZoneData" +
(String)((localeName != null) ? "_"+localeName : "");
addLocaleData(localeElements, data);
addLocaleData(DateFormatZoneData, data);
final Locale locale = localeFromString(localeName);
if ((options & OPT_11) != 0) {
new Java1LocaleWriter(out, System.err).write(locale, data);
}
if ((options & OPT_12) != 0) {
new JavaLocaleWriter(out, System.err).write(locale, data);
}
if ((options & OPT_ICU) != 0) {
new ICULocaleWriter(out, System.err).write(locale, data);
}
}
}
private void addLocaleData(final String bundleClassName, final Hashtable data) {
try {
final Class bundleClass = Class.forName(bundleClassName);
final ResourceBundle bundle = (ResourceBundle)bundleClass.newInstance();
for (int i = 0; i < tags.length; i++) {
try {
final Object resource = bundle.getObject(tags[i]);
data.put(tags[i], resource);
} catch (MissingResourceException e) {
}
}
} catch (ClassNotFoundException e) {
System.err.println("Could not find bundle class for bundle: "+bundleClassName);
} catch (InstantiationException e) {
System.err.println("Could not create bundle instance for bundle: "+bundleClassName);
} catch (IllegalAccessException e) {
System.err.println("Could not create bundle instance for bundle: "+bundleClassName);
}
}
private void printUsage() {
System.err.println("Usage: ConvertJavaLocale [-11] [-12] [-icu] localeName");
}
private short identifyOptions(String[] options) {
short result = 0;
for (int j = 0; j < options.length; j++) {
String option = options[j];
if (option.startsWith("-")) {
boolean optionRecognized = false;
for (short i = 0; i < USER_OPTIONS.length; i++) {
if (USER_OPTIONS[i].equals(option)) {
result |= (short)(1 << i);
optionRecognized = true;
break;
}
}
if (!optionRecognized) {
result |= OPT_UNKNOWN;
}
}
}
return result;
}
private Locale localeFromString(final String localeName) {
if (localeName == null) return new Locale("", "", "");
String language = localeName;
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx+1);
country = country.substring(0, ndx);
}
return new Locale(language, country, variant);
}
}

View file

@ -0,0 +1,98 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ConvertLocaleTest.java,v $
* $Date: 2002/01/31 01:21:30 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/*
ConvertPOSIXLocale [-11] [-12] [-icu] [-icu2] localeDataFile [charMapFile ...]
*/
public class ConvertLocaleTest {
public static void main(String args[]) {
/*
ConvertPOSIXLocale.main( new String[] {
"-12",
"C:\\projects\\com\\taligent\\localeconverter\\collationTest.txt"
} );
ConvertPOSIXLocale.main( new String[] {
"-icu",
"C:\\projects\\com\\taligent\\localeconverter\\collationTest2.txt",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
} );
ConvertPOSIXLocale.main( new String[] {
"-icu", "-LC_MESSAGES",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\Vivnx43.ibm",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ibm1129-2-UniCode.chm",
} );
/* ConvertPOSIXLocale.main( new String[] {
"-12",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\en_US",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
/* ConvertPOSIXLocale.main( new String[] {
"-12",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fi_FI",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
ConvertPOSIXLocale.main( new String[] {
"-12", "en_BE",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\ENBEWIN.IBM",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\Ibm1252.chm",
});
ConvertPOSIXLocale.main( new String[] {
"-12", "vi_VN",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\Vivnx43.ibm",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ibm1129-2-UniCode.chm",
});
ConvertPOSIXLocale.main( new String[] {
"-icu", "fr_FR",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fr_FR",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
ConvertPOSIXLocale.main( new String[] {
"-icu", "fo_FO",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fo_FO",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
*/
ConvertPOSIXLocale.main( new String[] {
"-icu", "fr_LU",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fr_LU",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
/*
ConvertPOSIXLocale.main( new String[] {
"-icu", "de_LU",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\de_LU",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
*/
}
}

View file

@ -0,0 +1,349 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ConvertPOSIXLocale.java,v $
* $Date: 2002/01/31 01:21:31 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
The ConvertPOSIXLocale application converts POSIX locale files to
Java and ICU Locale files. It's usage is as follows
ConvertPOSIXLocale
[-LC_CTYPE]
[-LC_TIME]
[-LC_NUMERIC]
[-LC_MONETARY]
[-LC_MESSAGES]
[-11]
[-12]
[-icu]
[-icu2]
localeName
localeDataFile
[charMapFile ...]
The application is invoked with options specifying the format(s) of
the locale file(s) to generate as well as the POSIX locale file and
character mapping files.
Usage
-LC_CTYPE
If the -LC_CTYPE option is specified, the
following items are added to the locale if they
are present in the source: upper, lower, alpha, digit,
space, cntrl, punct, graph, print, xdigit, blank,
toupper, tolower.
<CODE>-LC_TIME
If the -LC_TIME option is specified, the following
items will be included if they are present in the POSIX source:
abday, day, abmon, mon, d_t_fmt, d_ftm, t_fmt, am_pm,
t_fmt_ampm, era, era_year, era_d_fmt, alt_digits.
-LC_NUMERIC
If the -LC_NUMERIC option is specified, the following
items will be included if they are present in the source:
decimal_point, thousands_sep, grouping
-LC_MONETARY
If the -LC_MONETARY option is specified, the following
items will be included if they are present in the source:
int_curr_symbol, currency_symbol, mon_decimal_point,
mon_thousands_sep, mon_grouping, positive_sign,
negative_sign, int_frac_digits, frac_digits, p_cs_precedes,
p_sep_by_space, n_cs_precedes, n_sep_by_space, p_sign_posn.
-LC_MESSAGES
If the -LC_MESSAGES option is specified, the
following items are added to the locale if they
are present in the source: yesexpr, noexpr
-11
If this option is specified, data is output in
Java 1.1.x locale format.
-12
If this option is specified, data is output in
Java 1.2.x locale format. If an output format
is not specified, -12 is the default.
-icu
If this option is specified, data is output in
ICU locale format.
localeName
The name of the locale in the localeDataFile. Ex. en_US.
localeDataFile
The localeDataFile path is required and specifies the path
to the locale data file. If a "copy" directive is encountered
while processing the localeDataFile, ConvertPOSIXLocale will look
in the same directory as the localeDataFile for additional
POSIX locale data files. Files must be in the POSIX format
specified in ISO/IEC 9945- with exceptions noted below. Exactly
one localeDataFile must be specified.
charMapFile
Zero or more character mapping files may be specified. charMapFiles are used
to map symbols in the localeDataFile to Unicode values. They are processed
as follows. ConvertPOSIXLocale searchs for a line containing only the
word "CHARMAP" and reads symbol mappings until it reaches a line
containing only the words "END CHARMAP". Symbol mappings have
the form "<SYMBOL> <Uhhhh>" where "<SYMBOL>" is any symbol valid
in a localeDataFile and "hhhh" is four hexidecimal digits representing
the Unicode value for that symbol. Surrogate pairs are not supported
in charMapFiles. An example charMapFile might contain the following:
CHARMAP
<START_OF_TEXT> <U0002>
<E> <U0045>
<q> <U0071>
END CHARMAP
specifying that the symbol <START_OF_TEXT> should be replaced by
the Unicode value of 0x0002 wherever it occurs.
When multiple charMapFiles are specified, mappings in files listed
later take precedence over earlier ones.
Conversion to ICU and Java:
CollationElements
Converted from the LC_COLLATE section. The "..." directive is ignored.
The "replace-after" directive is ignored.
CurrencyElements
element 0 is set to currency_symbol
element 1 is set to int_curr_symbol
element 2 is set to mon_decimal_point
All other elements default.
NumberElements
element 0 is set to decimal_point
element 1 is set to thousands_sep
MonthNames is set to mon
MonthAbbreviations is set to abmon
DayNames is set to day
DayAbbreviations is set to abday
AmPmMarkers is set to am_pm
DateTimePatterns
elements 0 through 3 are set to t_fmt_ampm with the patterns converted
elements 4 through 7 are set to d_fmt with the patterns converted
Adition POSIX data may be included in the Locale as follows:
LC_TYPE
This section is ignored unless the -LC_CTYPE option is
specified. If the -LC_CTYPE option is specified, the
following items are added to the locale if they
are present in the source: upper, lower, alpha, digit,
space, cntrl, punct, graph, print, xdigit, blank,
toupper, tolower.
LC_MESSAGES
LC_MONETARY
LC_NUMERIC
LC_TIME
If the -LC_TIME option is specified, the following
items will be included if they are present in the source:
abday, day, abmon, mon, d_t_fmt, d_ftm, t_fmt, am_pm,
t_fmt_ampm, era, era_year, era_d_fmt, alt_digits.
LC_COLLATE
Converted to CollationElements in the resource file.
*/
public class ConvertPOSIXLocale {
private static final short OPT_LC_CTYPE = 0x001;
private static final short OPT_LC_TIME = 0x002;
private static final short OPT_LC_NUMERIC = 0x004;
private static final short OPT_LC_MONETARY = 0x008;
private static final short OPT_LC_MESSAGES = 0x010;
private static final short OPT_11 = 0x020;
private static final short OPT_12 = 0x040;
private static final short OPT_ICU = 0x080;
private static final short OPT_ICU2 = 0x100;
private static final short OPT_RAW = 0x200;
private static final short OPT_UNKNOWN = 0x4000;
private static final String USER_OPTIONS[] = {
"-LC_CTYPE",
"-LC_TIME",
"-LC_NUMERIC",
"-LC_MONETARY",
"-LC_MESSAGES",
"-11",
"-12",
"-icu",
"-icu2",
"-RAW",
"-enc",
};
private static final short OPT_CONVERT = (short)(OPT_LC_CTYPE | OPT_LC_TIME
| OPT_LC_NUMERIC | OPT_LC_MONETARY | OPT_LC_MESSAGES);
private Hashtable data;
public static void main(String args[]) {
try {
new ConvertPOSIXLocale(args);
} catch (Throwable t) {
t.printStackTrace();
System.err.println("Unknown error: "+t);
}
}
public ConvertPOSIXLocale(String args[]) {
process(args);
//{{INIT_CONTROLS
//}}
}
public void process(String args[]) {
short options = identifyOptions(args);
String enc="";
if ((args.length < 2) || ((options & OPT_UNKNOWN) != 0)) {
printUsage();
} else {
Vector mapFiles = new Vector();
Locale locale = null;
String fileName = null;
for (int i = 0; i < args.length; i++) {
final String thisArg = args[i];
if (thisArg.startsWith("-")) {
if(thisArg.startsWith("-enc")){
enc = args[++i];
}
} else if (locale == null) {
locale = localeFromString(thisArg);
} else if (fileName == null) {
fileName = thisArg;
} else {
mapFiles.addElement(thisArg);
}
}
if ((fileName == null) || (locale == null) || (options == 0)) {
printUsage();
} else {
PosixCharMap map = new PosixCharMap();
Enumeration enum = mapFiles.elements();
while (enum.hasMoreElements()) {
String mapFile = (String)enum.nextElement();
System.err.println("Locale: "+locale);
System.err.println("Loading character map file: "+mapFile);
try {
map.load(new File(mapFile),enc);
} catch (IOException e) {
System.err.println("Error loading map file: "+mapFile+" "+e);
System.err.println("File skipped");
}
}
SymbolTransition.setCharMap(map);
File dataFile = new File(fileName);
System.err.println("Locale directory: "+dataFile.getParent());
POSIXLocaleReader reader = new POSIXLocaleReader(dataFile.getParent(), locale);
System.err.println("Parsing file: "+dataFile.getName());
try {
data = reader.parse(dataFile.getName(), (byte)(options & OPT_CONVERT));
System.err.println("Converting....");
if ((options & OPT_11) != 0) {
new Java1LocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_12) != 0) {
new JavaLocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_ICU) != 0) {
new ICULocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_ICU2) != 0) {
new ICU2LocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_RAW) != 0) {
new ICULocaleWriter(System.out, System.err).write(locale, data);
}
} catch (IOException e) {
System.err.println(e);
}
}
}
}
private void printUsage() {
System.err.println("Usage: ConvertPOSIXLocale [-LC_CTYPE] [-LC_TIME]"+
" [-LC_NUMERIC] [-LC_MONETARY] [-LC_MESSAGES] [-11] [-12] [-icu]"+
" localeName localeDataFile [charMapFile ...]");
}
private short identifyOptions(String[] options) {
short result = 0;
for (int j = 0; j < options.length; j++) {
String option = options[j];
if (option.startsWith("-")) {
boolean optionRecognized = false;
for (short i = 0; i < USER_OPTIONS.length; i++) {
if (USER_OPTIONS[i].equals(option)) {
result |= (short)(1 << i);
optionRecognized = true;
break;
}
}
if (!optionRecognized) {
result |= OPT_UNKNOWN;
}
}
}
return result;
}
private Locale localeFromString(final String localeName) {
String language = localeName;
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx+1);
country = country.substring(0, ndx);
}
ndx = country.indexOf('@');
if(ndx>0){
variant = country.substring(ndx+1);
country = country.substring(0,ndx);
}
return new Locale(language, country, variant);
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,113 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/EOLTransition.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* This transition parses an end-of-line sequence. The comment character
* can be set to an arbitrary character, but it is shared globally.
* A comment may only occur after an end-of-line.
* EOL := <EOF> | <EOL_CHARS> [ <EOL_SEGMENT> ]*
* EOL_SEGMENT := <EOL_CHARS> | <SPACE_CHARS> | <COMMENT>
* SPACE_CHARS := " \t";
* EOL_CHARS = "\r\n\u2028\u2029";
* COMMENT_STRING := <COMMENT_CHAR> <COMMENT_BODY>
* COMMENT_CHAR = "#";
* COMMENT_BODY = [ ~<EOF> & ~<EOL_CHARS> ]*
*/
public class EOLTransition extends ComplexTransition {
public static final String EOL_CHARS = "\r\n\u2028\u2029";
public static final char DEFAULT_COMMENT_CHAR = '#';
public static char COMMENT_CHAR = DEFAULT_COMMENT_CHAR;
public static final EOLTransition GLOBAL = new EOLTransition(SUCCESS);
/** Restore the comment character to the default value */
public static synchronized char setDefaultCommentChar() {
return setCommentChar(DEFAULT_COMMENT_CHAR);
}
/** Set a new comment character */
public static synchronized char setCommentChar(char c) {
char result = COMMENT_CHAR;
COMMENT_CHAR = c;
states = null; //flush states
return result;
}
public EOLTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return EOL_CHARS.indexOf((char)c) >= 0;
}
protected Lex.Transition[][] getStates() {
synchronized (getClass()) {
if (states == null) {
//cache the states so they can be shared. This states
//need to be flushed and rebuilt when the comment
//character changes.
states = new Lex.Transition[][] {
{ //state 0:
new Lex.StringTransition(EOL_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.EOFTransition(SUCCESS),
new Lex.ParseExceptionTransition("bad characters in EOL")
},
{ //state 1:
new Lex.CharTransition(COMMENT_CHAR, Lex.IGNORE_CONSUME, -2),
new Lex.StringTransition(EOL_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.StringTransition(SpaceTransition.SPACE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.EOFTransition(SUCCESS),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, SUCCESS)
},
{ //state 2:
new Lex.StringTransition(EOL_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.EOFTransition(SUCCESS),
new Lex.DefaultTransition(Lex.IGNORE_CONSUME, -2)
}
};
}
}
return states;
}
private static Lex.Transition[][] states;
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new EOLTransition(SUCCESS).debug(true),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
String text = "\n\r\n# Hello World\n\r\n\n\n\r\r\n#hello kdsj\n";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
parser.debug(true);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
//System.out.println(parser.getData());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,152 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/EscapeTransition.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* An escape transition parses a POSIX escape sequence. An escape
* sequence can be a hex, octal, or decimal constant, or an escaped
* character. The resultant value is ALWAYS on byte long. Longer
* escaped values (ie.\xFF63) overflow and are truncated. An escape
* character followed by an EOL sequence is silently eaten.
*/
public class EscapeTransition extends ComplexTransition {
public static final EscapeTransition GLOBAL = new EscapeTransition(SUCCESS);
public static final char DEFAULT_ESCAPE_CHAR = '\\';
public static char ESCAPE_CHAR = DEFAULT_ESCAPE_CHAR;
private static final int DECIMAL = 1; //decimal escape sequence was parsed
private static final int OCTAL = 2; //octal escape sequence was parsed
private static final int HEX = 3; //hex escape sequence was parsed
private static final int ESCAPE = 4; //character escape sequence was parsed
private static final int EOL = 5; //an escape character followed by EOF eaten
private static final String OCTAL_CHARS = "01234567";
private static final String DECIMAL_CHARS = "0123456789";
private static final String HEX_CHARS = "0123456789abcdefABCDEF";
/** Set the escape character to the default */
public static synchronized char setDefaultEscapeChar() {
return setEscapeChar(DEFAULT_ESCAPE_CHAR);
}
/** Set the escape character */
public static synchronized char setEscapeChar(char c) {
char result = ESCAPE_CHAR;
ESCAPE_CHAR = c;
theStates = null;
return result;
}
public EscapeTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return ESCAPE_CHAR == (char)c;
}
/** Convert the accepted text into the appropriate unicode character */
protected void handleSuccess(Lex parser, StringBuffer output) throws IOException {
switch (parser.getState()) {
case DECIMAL:
output.append((char)parser.dataAsNumber(10));
break;
case OCTAL:
output.append((char)parser.dataAsNumber(8));
break;
case HEX:
output.append((char)parser.dataAsNumber(16));
break;
case ESCAPE:
parser.appendDataTo(output);
break;
case EOL:
//silently eat the EOL characters
break;
default:
//should never get here
throw new Lex.ParseException("Internal error parsing escape sequence");
// parser.appendDataTo(output);
}
}
/** return the states for this transaction */
protected Lex.Transition[][] getStates() {
synchronized (getClass()) {
if (theStates == null) {
//cache the states so they can be shared. They must
//be rebuilt when the escape character is changed.
theStates = new Lex.Transition[][] {
{ //state 0:
new Lex.CharTransition(ESCAPE_CHAR, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal escape character")
},
{ //state 1:
new Lex.EOFTransition(OCTAL),
new Lex.CharTransition('d', Lex.IGNORE_CONSUME, -3),
new Lex.CharTransition('x', Lex.IGNORE_CONSUME, -2),
new Lex.StringTransition(OCTAL_CHARS, Lex.ACCUMULATE_CONSUME, -4),
new Lex.CharTransition(ESCAPE_CHAR, Lex.ACCUMULATE_CONSUME, ESCAPE),
new EOLTransition(EOL),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, ESCAPE)
},
{ //state 2: hex
new Lex.EOFTransition(HEX),
new Lex.StringTransition(HEX_CHARS, Lex.ACCUMULATE_CONSUME, -2),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, HEX)
},
{ //state 3: decimal
new Lex.EOFTransition(DECIMAL),
new Lex.StringTransition(DECIMAL_CHARS, Lex.ACCUMULATE_CONSUME, -3),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, DECIMAL)
},
{ //state 4: octal
new Lex.EOFTransition(OCTAL),
new Lex.StringTransition(OCTAL_CHARS, Lex.ACCUMULATE_CONSUME, -4),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, OCTAL)
},
};
}
}
return theStates;
}
private static Lex.Transition[][] theStates = null;
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new EscapeTransition(SUCCESS),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
String text = "\\d100\\xAf\\\\\\777\\\n\\123\\x2028\\x2029";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
System.out.println(parser.getState());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,122 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ICU2LocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class ICU2LocaleWriter extends LocaleWriter {
public ICU2LocaleWriter(PrintStream out) {
super(out);
//{{INIT_CONTROLS
//}}
}
public ICU2LocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
protected void open(Locale locale) {
print(locale.toString());
println(" {");
indent();
}
protected void write(String tag, String value) {
print(tag);
print(" { ");
printString(value);
println(" }");
}
protected void write(String tag, String[] value) {
if (tag != null) {
print(tag);
println(" { ");
} else {
println("{");
}
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
}
protected void write(String tag, Object o) {
if ("CollationElements".equals(tag)) {
writeTagged(tag,(Object[][])o);
} else if (!(o instanceof CollationItem[])) {
super.write(tag, o);
} else {
CollationItem[] items = (CollationItem[])o;
print("CollationElements");
println(" { ");
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
printString(items[i].toString());
if (items[i].comment != null) {
tabTo(30);
print("//");
println(items[i].comment);
}
}
}
}
}
protected void writeTagged(String tag, Object[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write((String)value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void write2D(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(null, value[i]);
}
outdent();
println("}");
}
protected void writeTagged(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void close() {
outdent();
println("}");
}
protected String getStringJoiningCharacter() {
return "";
}
protected boolean isEscapeChar(final char c) {
return true;
}
protected String getEscapeChar() {
return "%u";
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,115 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/ICULocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class ICULocaleWriter extends LocaleWriter {
public ICULocaleWriter(PrintStream out) {
super(out);
}
public ICULocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
protected void open(Locale locale) {
print(locale.toString());
println(" {");
indent();
}
protected void write(String tag, Object o) {
if ("CollationElements".equals(tag)) {
if(o instanceof Object[][]){
writeTagged(tag,(Object[][])o);
}else{
write(tag,(String)o);
}
} else if (!(o instanceof CollationItem[])) {
super.write(tag, o);
} else {
CollationItem[] items = (CollationItem[])o;
print("CollationElements");
println(" { ");
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
printString(items[i].toString());
if (items[i].comment != null) {
tabTo(30);
print("//");
println(items[i].comment);
}
}
}
}
}
protected void write(String tag, String value) {
print(tag);
print(" { ");
printString(value);
println(" }");
}
protected void write(String tag, String[] value) {
if (tag != null) {
print(tag);
println(" { ");
} else {
println("{");
}
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
}
protected void write2D(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(null, value[i]);
}
outdent();
println("}");
}
protected void writeTagged(String tag, Object[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write((String)value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void writeTagged(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void close() {
outdent();
println("}");
super.closeFileHandle();
}
protected String getStringJoiningCharacter() {
return "";
}
}

View file

@ -0,0 +1,147 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/Java1LocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class Java1LocaleWriter extends LocaleWriter {
public Java1LocaleWriter(PrintStream out) {
super(out);
//{{INIT_CONTROLS
//}}
}
public Java1LocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
public void write(Locale locale, Hashtable localeData) {
try {
Hashtable temp = new NeutralToJ1Converter(locale).convert(localeData);
super.write(locale, temp);
} catch (LocaleConverter.ConversionError e) {
err.println(e);
}
}
protected void open(Locale locale) {
print(HEADER1);
print(locale.toString());
print(HEADER2);
print(locale.toString());
println(HEADER3);
indent(3);
}
protected void write(String tag, String value) {
print("{ ");
printString(tag);
print(", ");
printString(value);
println(" },");
}
protected void write(String tag, String[] value) {
print("{ ");
if (tag != null) {
printString(tag);
println(",");
} else {
println("");
}
indent();
println("new String[] {");
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
outdent();
println("},");
}
protected void write2D(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
println("{");
indent();
for (int j = 0; j < value[i].length; j++) {
printString(value[i][j]);
println(",");
}
outdent();
println("},");
}
outdent();
println("}");
outdent();
println("},");
}
protected void writeTagged(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
outdent();
println("},");
}
protected void close() {
outdent(3);
print(FOOTER);
}
protected void appendEscapedChar(char c, StringBuffer buffer) {
if (c < '\u0020' || c == '"' || c == '\\') {
buffer.append('\\');
buffer.append(HEX_DIGIT[(c & 0700) >> 6]); // HEX_DIGIT works for octal
buffer.append(HEX_DIGIT[(c & 0070) >> 3]);
buffer.append(HEX_DIGIT[(c & 0007)]);
} else {
super.appendEscapedChar(c, buffer);
}
}
protected String getStringJoiningCharacter() {
return "+";
}
private static final String HEADER1 =
"package java.text.resources;\n"+
"public class LocaleElements_";
private static final String HEADER2 =
" extends LocaleData {\n"+
" public LocaleElements_";
private static final String HEADER3 =
"() {\n"+
" super.init(table);\n"+
" }\n"+
" static String table []=";
private static final String FOOTER =
" }\n"+
"}";
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,170 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/JavaLocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class JavaLocaleWriter extends LocaleWriter {
public JavaLocaleWriter(PrintStream out) {
super(out);
}
public JavaLocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
public void open(Locale locale) {
println(HEADER);
indent(3);
}
protected void write(String tag, Object o) {
if ("CollationElements".equals(tag)) {
writeTagged(tag,(Object[][])o);
} else if (!(o instanceof CollationItem[])) {
super.write(tag, o);
} else {
CollationItem[] items = (CollationItem[])o;
print("{ ");
printString("CollationElements");
println(", ");
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
printString(items[i].toString());
if (items[i].comment != null) {
print("+");
tabTo(30);
print("//");
println(items[i].comment);
} else {
println("+");
}
}
}
println("\"\"");
println(" },");
}
}
public void write(String tag, String value) {
print("{ ");
printString(tag);
print(", ");
printString(value);
println(" },");
}
public void write(String tag, String[] value) {
print("{ ");
if (tag != null) {
printString(tag);
println(",");
} else {
println("");
}
indent();
println("new String[] {");
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
outdent();
println("},");
}
public void write2D(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
println("{");
indent();
for (int j = 0; j < value[i].length; j++) {
printString(value[i][j]);
println(",");
}
outdent();
println("},");
}
outdent();
println("}");
outdent();
println("},");
}
public void writeTagged(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
outdent();
println("},");
}
public void writeTagged(String tag, Object[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
write((String)value[i][0], value[i][1]);
}
outdent();
println("}");
outdent();
println("},");
}
public void close() {
outdent(3);
print(FOOTER);
println("");
}
protected void appendEscapedChar(char c, StringBuffer buffer) {
if (c < '\u0020' || c == '"' || c == '\\') {
buffer.append('\\');
buffer.append(HEX_DIGIT[(c & 0700) >> 6]); // HEX_DIGIT works for octal
buffer.append(HEX_DIGIT[(c & 0070) >> 3]);
buffer.append(HEX_DIGIT[(c & 0007)]);
} else {
super.appendEscapedChar(c, buffer);
}
}
protected String getStringJoiningCharacter() {
return "+";
}
private static final String HEADER =
"package java.text.resources;\n"+
"import java.util.ListResourceBundle;\n"+
"public class TestLocaleElements extends ListResourceBundle {\n"+
" public Object[][] getContents() {\n"+
" return new Object[][] {";
private static final String FOOTER =
" };\n"+
" }\n"+
"}";
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,416 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/Lex.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* A Lex is a state machine. Transitions can be activated
* arbitrarily and can consume arbitrary amounts of text.
* A transition simply says it can consume the next character
* and returns the state that the machine should transition into.
* States that are > 0 are final states and cause the nextToken
* routine to return a value.
*/
public final class Lex {
private Transition[][] states; //final
private PushbackReader input; //final
private int state;
private String data;
private final StringBuffer dataBuffer = new StringBuffer();
private boolean debugMessagesOn;
private String debugTag;
public static final int END_OF_FILE = Integer.MAX_VALUE;
/** Construct a new machine. NOTE: setInput must be
* called before nextToken is called */
public Lex(final Transition[][] states) {
this.states = states;
//{{INIT_CONTROLS
//}}
}
/** Construct a new machine. */
public Lex(final Transition[][] statesIn, final PushbackReader inputIn) {
states = statesIn;
input = inputIn;
}
/** Return the current state */
public int getState() {
return state;
}
/** Return the data resulting from the last call to nextToken */
public String getData() {
if (data == null) {
data = dataBuffer.toString();
}
return data;
}
/** Return the input reader used by this machine */
public PushbackReader getInput() {
return input;
}
/** set the input reader used by this machine */
public void setInput(PushbackReader input) {
this.input = input;
}
/** Return the states used by this machine */
public Transition[][] getStates() {
return states;
}
public void setStates(Transition[][] states) {
this.states = states;
}
/** Return true if the specified string equals the
* string returned by getData(). This routine
* may be faster than calling getData because
* it does not create a string on the heap.
*/
public boolean dataEquals(final String other) {
if (data != null) {
//if dataBuffer has already been converted to
//a string, just compare the strings.
return data.equals(other);
} else {
if (other.length() != dataBuffer.length()) return false;
final int len = dataBuffer.length();
for (int i = 0; i < len; i++) {
if (other.charAt(i) != dataBuffer.charAt(i)) {
return false;
}
}
return true;
}
}
/**
* Append the data returned from getData() to the
* specified StringBuffer. This routine avoids
* the creation of a String on the heap.
*/
public void appendDataTo(StringBuffer buffer) {
buffer.append(dataBuffer);
}
/**
* Return true if the data returned by getData()
* starts with the specified string. This routine avoids
* the creation of a String on the heap.
*/
public boolean dataStartsWith(String s) {
if (dataBuffer.length() < s.length()) {
return false;
} else {
final int sLength = s.length();
for (int i = 0; i < sLength; i++) {
if (dataBuffer.charAt(i) != s.charAt(i)) {
return false;
}
}
return true;
}
}
/**
* Convert the contents of the data buffer to an integer
* of the specified radix
*/
public int dataAsNumber(int radix) {
int value = 0;
final int len = dataBuffer.length();
for (int i = 0; i < len; i++) {
value = value*radix + Character.digit(dataBuffer.charAt(i), radix);
}
return value;
}
/**
* Get the next token from the input stream. The
* dataBuffer is cleared and the state is set to zero before
* parsing begins. Parsing continues until a state
* greater of equal to 0 s reached or an exception is thrown.
* After each non-terminal transition, the state machine
* walks through all the transitions, in order, for the current
* state until it finds one that will accept the current
* input character and then calls doAction on that transition.
*/
public int nextToken() throws IOException {
state = 0;
dataBuffer.setLength(0);
do {
int c = input.read();
final Transition[] transition = states[-state];
for (int i = 0; i < transition.length; i++) {
if (transition[i].accepts(c)) {
//System.out.println("state["+ -state+"].transition["+i+"] on "+c+" '"+(char)c+"' to state[");
state = transition[i].doAction(c, input, dataBuffer);
//println("" + -state + "]");
break;
}
}
} while (state <= 0);
data = null; //dump the cached data string
return state;
}
/**
* Get the next token and throw an acception if
* the state machine is not in the specified state.
*/
public void accept(final int neededState) throws IOException {
if (neededState != nextToken()) {
throw new ParseException("Unexpected token - "+getData());
}
}
/**
* Get the next token and throw an exception if the
* state machine is not in the specified state and the
* value returned by getData() does not match the
* specified value.
*/
public void accept(final int neededState, final String neededValue) throws IOException {
accept(neededState);
if (!dataEquals(neededValue)) {
throw new ParseException("Unexpected token - "+getData());
}
}
public void debug(boolean debugMessagesOn) {
this.debugMessagesOn = debugMessagesOn;
debugTag = null;
}
public void debug(boolean debugMessagesOn, String tag) {
this.debugMessagesOn = debugMessagesOn;
this.debugTag = tag;
}
/* private void print(String s) {
if (debugMessagesOn) {
System.out.print(s);
}
}
private void println(String s) {
if (debugMessagesOn) {
System.out.println(s+" <"+debugTag);
}
}
/**
* The interface for state machine transitions.
*/
public interface Transition {
/**
* Return true if the transition can accept the current input
* character.
*/
public boolean accepts(int c);
/**
* Perform the transition.
* @param c the current input character
* @param input the current input stream, minus the current input character
* @param buffer the current output buffer
* @return the state the machine should be in next
*/
public int doAction(int c, PushbackReader input, StringBuffer buffer) throws IOException;
}
/* constants for BaseTransitions */
/** Don't copy the current character to the output */
public static final byte IGNORE = 0x01;
/** Append the current character to the output */
public static final byte ACCUMULATE = 0x00;
private static final byte BUFFER_MASK = 0x01;
/** Remove the current character from the input stream */
public static final byte CONSUME = 0x00;
/** Return the current character to the input stream */
public static final byte PUTBACK = 0x10;
private static final byte INPUT_MASK = 0x10;
public static final byte
ACCUMULATE_CONSUME = (byte)(ACCUMULATE | CONSUME),
IGNORE_CONSUME = (byte)(IGNORE | CONSUME),
ACCUMULATE_PUTBACK = (byte)(ACCUMULATE | PUTBACK),
IGNORE_PUTBACK = (byte)(IGNORE | PUTBACK);
/**
* Base class for simple transition classes
*/
public static abstract class BaseTransition implements Transition {
private final boolean addToBuffer;
private final boolean unreadInput;
private final int next;
/**
* Construct a new transition. On execution, the
* specified action is performed and the
* specified state is returned.
* @param action the actions to perform to the
* input and output buffers.
* @param next the next state the machine should
* move into
*/
public BaseTransition(byte action, int next) {
this.addToBuffer = (action & BUFFER_MASK) == ACCUMULATE;
this.unreadInput = (action & INPUT_MASK) == PUTBACK;
this.next = next;
}
public abstract boolean accepts(int c);
public int doAction(final int c,
final PushbackReader input,
final StringBuffer buffer) throws IOException {
if (addToBuffer) {
buffer.append((char)c);
}
if (unreadInput) {
input.unread(c);
}
return next;
}
}
/**
* Accept end-of-file.
*/
public static final class EOFTransition extends BaseTransition {
public EOFTransition() {
this(IGNORE_CONSUME, END_OF_FILE);
}
public EOFTransition(int next) {
this(IGNORE_CONSUME, next);
}
public EOFTransition(byte action, int next) {
super(action, next);
}
public boolean accepts(int c) {
return c == -1;
}
}
/**
* Accept anything.
*/
public static final class DefaultTransition extends BaseTransition {
public DefaultTransition(byte action, int nextState) {
super(action, nextState);
}
public boolean accepts(int c) {
return true;
}
}
/**
* Accept any characters in the specified string.
*/
public static final class StringTransition extends BaseTransition {
private String chars;
public StringTransition(String chars, byte action, int nextState) {
super(action, nextState);
this.chars = chars;
}
public boolean accepts(int c) {
return chars.indexOf((char)c) != -1;
}
}
/**
* Accept only the specified character.
*/
public static final class CharTransition extends BaseTransition {
private char c;
public CharTransition(char c, byte action, int nextState) {
super(action, nextState);
this.c = c;
}
public boolean accepts(int c) {
return this.c == (char)c;
}
}
/**
* Accept anything, but throw the specified exception after
* performing the specified action
*/
public static final class ExceptionTransition extends BaseTransition {
private IOException e;
public ExceptionTransition(IOException e) {
super(IGNORE_PUTBACK, END_OF_FILE); //state is ignored
}
public ExceptionTransition(byte action, IOException e) {
super(action, END_OF_FILE); //state is ignored
}
public boolean accepts(int c) {
return true;
}
public final int doAction(final int c,
final PushbackReader input,
final StringBuffer buffer) throws IOException {
super.doAction(c, input, buffer);
throw e;
}
}
/**
* The base class for parse exceptions. Exceptions
* resulting from parsing errors should be subclasses of this
* class.
*/
public static final class ParseException extends IOException {
public final String reason;
public ParseException() {
this.reason = "unkown";
}
public ParseException(String reason) {
this.reason = reason;
}
public String toString() {
return reason;
}
}
/**
* Accept anything, execute as IGNORE_PUTBACK, and throw
* a ParseException with the specified message
*/
public static final class ParseExceptionTransition implements Transition {
private String reason;
public ParseExceptionTransition(String reason) {
this.reason = reason;
}
public boolean accepts(int c) {
return true;
}
public final int doAction(final int c,
final PushbackReader input,
final StringBuffer buffer) throws IOException {
input.unread((char)c);
throw new ParseException(reason);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,146 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/LineCharNumberReader.java,v $
* $Date: 2002/01/31 01:21:33 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
/**
* A LineCharNumberReader is a BufferedReader that
* keeps track of the line number and character offset
* on that line of the current input stream.
*/
public class LineCharNumberReader extends BufferedReader {
private int lineNumber = 0;
private int charNumber = 0;
private int markedLineNumber;
private int markedCharNumber;
private boolean skipLF;
public LineCharNumberReader(Reader in) {
super(in);
//{{INIT_CONTROLS
//}}
}
public LineCharNumberReader(Reader in, int sz) {
super(in, sz);
}
public int getLineNumber() {
return lineNumber;
}
public int getCharNumber() {
return charNumber;
}
public int read() throws IOException {
synchronized (lock) {
int c = super.read();
charNumber++;
if (skipLF) {
if (c == '\n') c = super.read();
skipLF = false;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
case '\u2028': /* Fall through */
case '\u2029': /* Fall through */
lineNumber++;
charNumber = 0;
return '\n';
}
return c;
}
}
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
int n = super.read(cbuf, off, len);
for (int i = off; i < off + len; i++) {
int c = cbuf[i];
charNumber++;
if (skipLF) {
skipLF = false;
if (c == '\n')
continue;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
case '\u2028': /* Fall through */
case '\u2029': /* Fall through */
lineNumber++;
charNumber = 0;
break;
}
}
return n;
}
}
public String readLine() throws IOException {
synchronized (lock) {
String l = super.readLine();
if (l != null)
lineNumber++;
charNumber = 0;
skipLF = false;
return l;
}
}
private static final int maxSkipBufferSize = 8192;
private char skipBuffer[] = null;
public long skip(long n) throws IOException {
int nn = (int) Math.min(n, maxSkipBufferSize);
synchronized (lock) {
if ((skipBuffer == null) || (skipBuffer.length < nn))
skipBuffer = new char[nn];
long r = n;
while (r > 0) {
int nc = read(skipBuffer, 0, nn);
if (nc == -1)
break;
r -= nc;
}
return n - r;
}
}
public void mark(int readAheadLimit) throws IOException {
synchronized (lock) {
super.mark(readAheadLimit);
markedLineNumber = lineNumber;
markedCharNumber = charNumber;
}
}
public void reset() throws IOException {
synchronized (lock) {
super.reset();
lineNumber = markedLineNumber;
charNumber = markedCharNumber;
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,42 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/LocaleConverter.java,v $
* $Date: 2002/01/31 01:21:35 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class LocaleConverter {
public Hashtable convert(Hashtable table) throws ConversionError {
Hashtable result = new Hashtable();
convert(result, table);
return result;
}
protected void convert(Hashtable result, Hashtable source) throws ConversionError {
Enumeration enum = source.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
Object data = source.get(key);
result.put(key, data);
}
}
public static class ConversionError extends Exception {
public ConversionError() {
}
public ConversionError(String reason) {
super(reason);
}
}
}

View file

@ -0,0 +1,418 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/LocaleWriter.java,v $
* $Date: 2002/01/31 01:22:18 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import com.ibm.text.*;
import java.io.*;
import java.util.*;
/**
* A LocaleWriter takes locale data in standard form and
* writes it to standard output in a form suitable for
* loading programatically.
*/
public abstract class LocaleWriter {
private static final String INDENT_CHARS =
" "+
" "+
" ";
private static final char EOL_CHARS[] = {'\r', '\n', '\u2028', '\u2029'};
private static final int INDENT_SIZE = 4;
private static final int MAX_LINE_LENGTH = 80;
private int indentLevel;
private String indentString;
private boolean needsIndent;
protected StringBuffer lineBuffer = new StringBuffer();
private int lineLength;
protected PrintStream out;
protected PrintStream err;
public static final HexToUnicodeTransliterator huTranslit = new HexToUnicodeTransliterator("<U###0>");
public static final UnicodeToHexTransliterator uhTranslit = new UnicodeToHexTransliterator("\\\\u0000");
final File outFile = new File( "cnvLoc.txt");
FileOutputStream outFileStream;
BufferedWriter outBufWrite;
PrintWriter myOut;
public LocaleWriter(PrintStream out) {
this.out = out;
this.err = out;
try{
outFile.canWrite();
outFileStream = new FileOutputStream(outFile);
outBufWrite = new BufferedWriter(new OutputStreamWriter(outFileStream,"UTF8"));
}
catch(java.io.IOException e){
System.out.println("Encoding unsupported");
return;
}
}
public LocaleWriter(PrintStream out, PrintStream err) {
this.out = out;
this.err = err;
try{
outFile.canWrite();
outFileStream = new FileOutputStream(outFile);
outBufWrite = new BufferedWriter(new OutputStreamWriter(outFileStream,"UTF8"));
}
catch(java.io.IOException e){
System.out.println("Encoding unsupported");
return;
}
}
public void write(Locale locale, Hashtable localeData) {
open(locale);
//sort the key so the tags are in order in the resource file
SortedVector order = new SortedVector(localeData.keys(), new SortedVector.StringComparator());
Enumeration e = order.elements();
while (e.hasMoreElements()) {
final String key = (String)e.nextElement();
final Object data = localeData.get(key);
if (isDuplicateOfInheritedValue(locale, key, data)) {
println("///* Discarding duplicate data for tag: "+key+" */");
} else {
write(key, data);
}
}
close();
}
public void closeFileHandle(){
try{
outBufWrite.close();
}
catch(java.io.IOException excp){
out.println("could not close the output file");
}
}
protected void write(String tag, Object o) {
if (o instanceof String) {
write(tag, (String)o);
} else if (o instanceof String[]) {
write(tag, (String[]) o);
} else if (o instanceof String[][]) {
write(tag, (String[][])o);
} else if (o instanceof Object[]) {
Object[] data = (Object[])o;
String[] temp = new String[data.length];
for (int i = 0; i < data.length; i++) {
temp[i] = data[i].toString();
}
write(tag, temp);
} else if (o instanceof Object[][]) {
Object[][] data = (Object[][])o;
String[][] temp = new String[data.length][];
for (int i = 0; i < data.length; i++) {
temp[i] = new String[data[i].length];
for (int j = 0; j < temp[i].length; j++) {
temp[i][j] = data[i][j].toString();
}
}
write(tag, temp);
} else {
write(tag, o.toString());
}
}
protected final void write(String tag, String[][] value) {
if (value.length > 0) {
if (value[0].length > 2) {
write2D(tag, value);
} else {
writeTagged(tag, value);
}
} else {
writeTagged(tag, value);
}
}
protected abstract void open(Locale locale);
protected abstract void write(String tag, String value);
protected abstract void write(String tag, String[] value);
protected abstract void write2D(String tag, String[][] value);
protected abstract void writeTagged(String tag, String[][] value);
protected abstract void close();
protected abstract String getStringJoiningCharacter();
protected void tabTo(int pos) {
if (pos > lineLength) {
for (int i = lineLength; i < pos; i++) {
print(" ");
}
}
}
protected void writeToFile(String str){
ReplaceableString tempStr = new ReplaceableString();
tempStr.replace(0,tempStr.length(),str);
//huTranslit.transliterate(tempStr);
//uhTranslit.transliterate(tempStr);
try{
outBufWrite.write(tempStr.toString());
}
catch(java.io.IOException e){
out.println("Could not write to file");
}
}
protected void print(String val) {
if (needsIndent) {
out.print(indentString);
writeToFile(indentString);
lineLength += indentString.length();
needsIndent = false;
}
ReplaceableString tempStr = new ReplaceableString();
tempStr.replace(0,tempStr.length(),val);
huTranslit.transliterate(tempStr);
String tval = tempStr.toString();
if(tval.length()< val.length()){
// uhTranslit.transliterate(tempStr);
tval=prependEsc(tempStr.toString());
}
if (tval != null) {
out.print(tval);
writeToFile(tval);
int len = 0;
for (int i = 0; i < EOL_CHARS.length; i++) {
len = Math.max(len, tval.lastIndexOf(EOL_CHARS[i]));
}
if (len == 0) {
lineLength += tval.length();
} else {
lineLength = tval.length() - len;
}
}
}
protected String prependEsc(String str){
StringBuffer myStr = new StringBuffer();
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
if(ch > 0x007f){
myStr.append("\\u");
myStr.append(toHexString(ch,16,4));
}
else{
myStr.append(ch);
}
}
return myStr.toString();
}
protected String toHexString(char ch, int radix, int pad){
final int MAX_DIGITS = 10;
int length = 0;
char buffer[] = new char[10];
int num = 0;
int digit;
int j;
char temp;
int i = (int)ch;
do{
digit = (int)(i % radix);
buffer[length++]=(char)(digit<=9?(0x0030+digit):(0x0030+digit+7));
i=(i/radix);
}while(i>0);
while (length < pad){
buffer[length++] = 0x0030;/*zero padding */
}
/* null terminate the buffer */
if(length<MAX_DIGITS){
buffer[length] = 0x0000;
}
num= (pad>=length) ? pad :length;
/* Reverses the string */
for (j = 0; j < (num / 2); j++){
temp = buffer[(length-1) - j];
buffer[(length-1) - j] = buffer[j];
buffer[j] = temp;
}
return new String(buffer,0,length);
}
protected void println(String val) {
print(val);
out.println();
writeToFile("\n");
lineLength = 0;
needsIndent = true;
}
protected void printString(String val) {
if (val != null) {
indent();
lineBuffer.setLength(0);
lineBuffer.append("\"");
final int size = val.length();
for (int i = 0; i < size; i++) {
append(val.charAt(i));
/*if (!append(val.charAt(i))) {
lineBuffer.append("\"");
lineBuffer.append(getStringJoiningCharacter());
println(lineBuffer.toString());
lineBuffer.setLength(0);
lineBuffer.append("\"");
}*/
}
lineBuffer.append("\"");
print(lineBuffer.toString());
outdent();
} else {
print("\"\"");
}
}
protected boolean append(final char c) {
boolean escape = isEscapeChar(c);
if (escape) {
appendEscapedChar(c, lineBuffer);
} else {
lineBuffer.append(c);
}
return (lineLength + lineBuffer.length() < MAX_LINE_LENGTH);
}
protected boolean isEscapeChar(final char c) {
switch (c) {
case '"':
case '\\':
case '\n':
case '\r':
case '\u2028':
case '\u2029':
return true;
default:
return (c < ' ') || (c > 0x07F);
}
}
protected void appendEscapedChar(char c, StringBuffer buffer) {
buffer.append(getEscapeChar());
int value = ((int)c) & 0xFFFF;
buffer.append(HEX_DIGIT[(value & 0xF000) >> 12]);
buffer.append(HEX_DIGIT[(value & 0x0F00) >> 8]);
buffer.append(HEX_DIGIT[(value & 0x00F0) >> 4]);
buffer.append(HEX_DIGIT[(value & 0x000F)]);
}
protected String getEscapeChar() {
return "\\u";
}
protected final void indent() {
indent(1);
}
protected void indent(int amount) {
indentLevel += amount;
indentString = INDENT_CHARS.substring(0, indentLevel*INDENT_SIZE);
}
protected final void outdent() {
outdent(1);
}
protected void outdent(int amount) {
indentLevel -= amount;
indentString = INDENT_CHARS.substring(0, indentLevel*INDENT_SIZE);
}
static final char[] HEX_DIGIT = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'};
/** Return true if the value for the specified tag is the same
* as the value inherited from the parent for that tag */
private boolean isDuplicateOfInheritedValue(final Locale loc, String tag, Object value) {
if (value == null) return true;
try {
final ResourceBundle parentBundle = getParentBundle(loc);
if (parentBundle == null) return false;
Object parentValue = parentBundle.getObject(tag);
if (!objectsAreEqual(value, parentValue)) {
return false;
} else {
return true;
}
} catch (java.util.MissingResourceException e) {
return false;
}
}
private boolean objectsAreEqual(final Object item, final Object parentItem) {
if (item instanceof Object[] && parentItem instanceof Object[]) {
return arraysAreEqual((Object[])item, (Object[])parentItem);
} else {
return item.equals(parentItem);
}
}
private boolean arraysAreEqual(final Object[] item, final Object[] parentItem) {
boolean matches = item.length == parentItem.length;
for (int i = 0; i < item.length && matches; i++) {
matches = objectsAreEqual(item[i], parentItem[i]);
}
return matches;
}
private ResourceBundle getParentBundle(final Locale loc) {
try {
final String x = loc.toString();
final int ndx = x.lastIndexOf('_');
if (ndx < 0) {
return null;
} else {
final String parentLocName = x.substring(0, ndx);
final Locale parentLoc = localeFromString(parentLocName);
return ResourceBundle.getBundle("com.ibm.jtc.localeconverter.myLocaleElements", parentLoc);
}
} catch (MissingResourceException e) {
return null;
}
}
private String replace(String source, String target, String replacement) {
if (target.equals(replacement)) {
return source;
} else {
StringBuffer result = new StringBuffer();
int lastNdx = 0;
int ndx = source.indexOf(target);
while (ndx >= 0) {
result.append(source.substring(lastNdx, ndx));
result.append(replacement);
ndx += target.length();
lastNdx = ndx;
ndx = source.indexOf(target, ndx);
}
result.append(source.substring(lastNdx));
return result.toString();
}
}
public Locale localeFromString(final String localeName) {
String language = localeName;
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx);
country = country.substring(0, ndx);
}
return new Locale(language, country, variant);
}
}

View file

@ -0,0 +1,209 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/NeutralToJ1Converter.java,v $
* $Date: 2002/01/31 01:22:21 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class NeutralToJ1Converter extends LocaleConverter {
private static class Conversion {
private String propName;
private int ndx;
protected Conversion() {
}
public Conversion(String propName) {
this.propName = propName;
this.ndx = -1;
}
public Conversion(String propName, int ndx) {
this.propName = propName;
this.ndx = ndx;
}
public String getPropName() {
return propName;
}
public String convert(Hashtable source) throws ConversionError {
Object sourceData = source.get(propName);
if (sourceData == null) {
return null;
}
if (ndx >= 0) {
if (sourceData instanceof String[]) {
sourceData = ((String[])sourceData)[ndx];
} else if (sourceData instanceof String[][]) {
sourceData = ((String[][])sourceData)[ndx];
}
}
if (sourceData instanceof String) {
return (String)sourceData;
} else if (sourceData instanceof String[]) {
String[] data = (String[])sourceData;
StringBuffer result = new StringBuffer();
for (int i = 0; i < data.length; i++) {
if (i > 0) result.append(';');
result.append(data[i]);
}
return result.toString();
} else {
throw new ConversionError("could not convert tag: "+propName);
}
}
}
private static class CollationConversion extends Conversion {
public String convert(Hashtable source) throws ConversionError {
Object[][] elements = (Object[][])source.get("CollationElements");
CollationItem[] items = (CollationItem[])elements[2][1];
if (items == null) {
return "";
} else {
StringBuffer result = new StringBuffer();
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
result.append(items[i].toString());
}
}
return result.toString();
}
}
}
private static final Conversion[] conversions = {
new Conversion("LocaleString"), /*locale id based on iso codes*/
new Conversion("LocaleID"), /*Windows id*/
new Conversion("ShortLanguage"), /*iso-3 abbrev lang name*/
new Conversion("ShortCountry"), /*iso-3 abbrev country name*/
new Conversion("Languages"), /*language names*/
new Conversion("Countries"), /*country names*/
new Conversion("MonthNames",0), /*january*/
new Conversion("MonthNames",1), /*february*/
new Conversion("MonthNames",2), /*march*/
new Conversion("MonthNames",3), /*april*/
new Conversion("MonthNames",4), /*may*/
new Conversion("MonthNames",5), /*june*/
new Conversion("MonthNames",6), /*july*/
new Conversion("MonthNames",7), /*august*/
new Conversion("MonthNames",8), /*september*/
new Conversion("MonthNames",9), /*october*/
new Conversion("MonthNames",10), /*november*/
new Conversion("MonthNames",11), /*december*/
new Conversion("MonthNames",12), /*month 13 if applicable*/
new Conversion("MonthAbbreviations",0), /*abb january*/
new Conversion("MonthAbbreviations",1), /*abb february*/
new Conversion("MonthAbbreviations",2), /*abb march*/
new Conversion("MonthAbbreviations",3), /*abb april*/
new Conversion("MonthAbbreviations",4), /*abb may*/
new Conversion("MonthAbbreviations",5), /*abb june*/
new Conversion("MonthAbbreviations",6), /*abb july*/
new Conversion("MonthAbbreviations",7), /*abb august*/
new Conversion("MonthAbbreviations",8), /*abb september*/
new Conversion("MonthAbbreviations",9), /*abb october*/
new Conversion("MonthAbbreviations",10), /*abb november*/
new Conversion("MonthAbbreviations",11), /*abb december*/
new Conversion("MonthAbbreviations",12), /*abb month 13 if applicable*/
new Conversion("DayNames",0), /*Monday*/
new Conversion("DayNames",1), /*Tuesday*/
new Conversion("DayNames",2), /*Wednesday*/
new Conversion("DayNames",3), /*Thursday*/
new Conversion("DayNames",4), /*Friday*/
new Conversion("DayNames",5), /*Saturday*/
new Conversion("DayNames",6), /*Sunday*/
new Conversion("DayAbbreviations",0), /*abb Monday*/
new Conversion("DayAbbreviations",1), /*abb Tuesday*/
new Conversion("DayAbbreviations",2), /*abb Wednesday*/
new Conversion("DayAbbreviations",3), /*abb Thursday*/
new Conversion("DayAbbreviations",4), /*abb Friday*/
new Conversion("DayAbbreviations",5), /*abb Saturday*/
new Conversion("DayAbbreviations",6), /*abb Sunday*/
new Conversion("AmPmMarkers",0), /*am marker*/
new Conversion("AmPmMarkers",1), /*pm marker*/
new Conversion("Eras"),/*era strings*/
new Conversion("NumberPatterns",0), /*decimal pattern*/
new Conversion("NumberPatterns",1), /*currency pattern*/
new Conversion("NumberPatterns",2), /*percent pattern*/
new Conversion("NumberElements",0), /*decimal separator*/
new Conversion("NumberElements",1), /*group (thousands) separator*/
new Conversion("NumberElements",2), /*list separator*/
new Conversion("NumberElements",3), /*percent sign*/
new Conversion("NumberElements",4), /*native 0 digit*/
new Conversion("NumberElements",5), /*pattern digit*/
new Conversion("NumberElements",6), /*minus sign*/
new Conversion("NumberElements",7), /*exponential*/
new Conversion("CurrencyElements",0), /*local currency symbol*/
new Conversion("CurrencyElements",1), /*intl currency symbol*/
new Conversion("CurrencyElements",2), /*monetary decimal separator*/
new Conversion("DateTimePatterns",0), /*full time pattern*/
new Conversion("DateTimePatterns",1), /*long time pattern*/
new Conversion("DateTimePatterns",2), /*medium time pattern*/
new Conversion("DateTimePatterns",3), /*short time pattern*/
new Conversion("DateTimePatterns",4), /*full date pattern*/
new Conversion("DateTimePatterns",5), /*long date pattern*/
new Conversion("DateTimePatterns",6), /*medium date pattern*/
new Conversion("DateTimePatterns",7), /*short date pattern*/
new Conversion("DateTimePatterns",8), /*date-time pattern*/
new Conversion("DateTimeElements",9), /*first day of week*/
new Conversion("DateTimeElements",10), /*min days in first week*/
new CollationConversion(), /*collation order*/
};
private Locale locale;
private Locale parentLocale;
private ResourceBundle defaultData;
public NeutralToJ1Converter(Locale locale) {
this.locale = locale;
String language = locale.toString();
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx);
country = country.substring(0, ndx);
}
if ("".equals(country)) {
language = "";
variant = "";
} else if ("".equals(variant)) {
country = "";
}
parentLocale = new Locale(language, country, variant);
defaultData =
ResourceBundle.getBundle("com.ibm.jtc.localeconverter.myLocaleElements", parentLocale);
//{{INIT_CONTROLS
//}}
}
/** convert the source table to the result */
protected void convert(Hashtable result, Hashtable source) throws ConversionError {
Vector localeElements = new Vector();
for (int i = 0; i < conversions.length; i++) {
final Conversion conv = conversions[i];
final String newValue = conv.convert(source);
if (newValue != null) {
localeElements.addElement(newValue);
} else {
localeElements.addElement(defaultData.getObject(conv.getPropName()));
}
}
result.put("LocaleElements", localeElements);
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,407 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/POSIXLocaleReader.java,v $
* $Date: 2002/01/31 01:22:24 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class POSIXLocaleReader {
private final String localeDataPath;
private final Locale locale;
public static final int TAG_TOKEN = 1;
public static final int SEPARATOR_TOKEN = 2;
public static final int EOL_TOKEN = 3;
public static final int EOF_TOKEN = 4;
//these states are used to parse the bulk of the
//input file. They translate escaped characters
//and symolic character references inline.
static final Lex.Transition[][] dataStates = {
{ //state 0: start
new SpaceTransition(0),
new Lex.CharTransition(';', Lex.IGNORE_CONSUME, SEPARATOR_TOKEN),
new Lex.CharTransition(',', Lex.IGNORE_CONSUME, SEPARATOR_TOKEN),
new EOLTransition(EOL_TOKEN),
new TokenTransition(TAG_TOKEN),
new Lex.EOFTransition(EOF_TOKEN),
new Lex.ParseExceptionTransition("unexpected characters")
}
};
static final Lex.Transition[][] LCStates = {
{ //state 0: start
new SpaceTransition(0),
new EOLTransition(EOL_TOKEN),
new Lex.EOFTransition(EOF_TOKEN),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //grab first word
new Lex.StringTransition(SpaceTransition.SPACE_CHARS, Lex.IGNORE_PUTBACK, TAG_TOKEN),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, TAG_TOKEN),
new Lex.EOFTransition(TAG_TOKEN),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
}
};
public POSIXLocaleReader(final String localeDataPath, final Locale locale) {
this.localeDataPath = localeDataPath;
this.locale = locale;
//{{INIT_CONTROLS
//}}
}
public Hashtable parse(String fileName, byte flags) throws IOException {
try {
Hashtable table = parseNative(fileName);
Hashtable result = new PosixToNeutralConverter(flags, locale,fileName).convert(table);
return result;
} catch (LocaleConverter.ConversionError e) {
System.err.println("Internal error converting locale data");
return null;
}
}
public Hashtable parseNative(String fileName) throws IOException {
char oldEscapeChar = EscapeTransition.setDefaultEscapeChar();
char oldCommentChar = EOLTransition.setDefaultCommentChar();
Hashtable table = new Hashtable();
try {
LineCharNumberReader lines = new LineCharNumberReader(
new BufferedReader(
new FileReader(
new File(localeDataPath, fileName)
)
)
);
PushbackReader reader = new PushbackReader(lines);
//Shove a newline at the start of the file. This has the affect of allowing
//the file to start with a comment, since the parser only allows comments as
//part of an EOL
reader.unread('\n');
String sectionTag = seekLC(reader);
while (sectionTag != null) {
try {
parseSection(table, reader, sectionTag);
} catch (Lex.ParseException e) {
System.err.println("ERROR parsing: "+e.reason);
System.err.println(" Line: "+lines.getLineNumber());
System.err.println(" char: "+lines.getCharNumber());
seekEND(reader);
System.err.println("Skipped to line: "+(lines.getLineNumber()+1));
}
sectionTag = seekLC(reader);
}
} finally {
EscapeTransition.setEscapeChar(oldEscapeChar);
EOLTransition.setCommentChar(oldCommentChar);
}
return table;
}
private void parseSection(Hashtable table, PushbackReader reader, String sectionTag) throws IOException {
if (sectionTag.equals("LC_CTYPE")) {
parseCTYPE(table, reader);
} else if (sectionTag.equals("LC_COLLATE")) {
parseCOLLATE(table, reader);
} else if (sectionTag.equals("LC_MONETARY")) {
parseLC(table, reader, sectionTag);
} else if (sectionTag.equals("LC_NUMERIC")) {
parseLC(table, reader, sectionTag);
} else if (sectionTag.equals("LC_TIME")) {
parseLC(table, reader, sectionTag);
} else if (sectionTag.equals("LC_MESSAGES")) {
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_MEASUREMENT")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_ADDRESS")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_PAPER")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_NAME")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_IDENTIFICATION")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_TELEPHONE")){
parseLC(table, reader, sectionTag);
}else {
System.out.println("Unrecognised section:"+sectionTag);
System.out.println("Default parsing applied.");
parseLC(table, reader, sectionTag);
}
}
private PushbackReader createParserInput(String localeName) throws IOException {
PushbackReader reader = new PushbackReader(
new BufferedReader(
new FileReader(
new File(localeDataPath, localeName)
)
)
);
//Shove a newline at the start of the file. This has the affect of allowing
//the file to start with a comment, since the parser only allows comments as
//part of an EOL
reader.unread('\n');
return reader;
}
private String seekLC(PushbackReader reader) throws IOException {
Lex p = new Lex(LCStates, reader);
final String LC = "LC_";
int s = p.nextToken();
while ((s != EOF_TOKEN)) {
if (s == TAG_TOKEN) {
if (p.dataStartsWith(LC)) {
String tag = p.getData();
do {
s = p.nextToken();
} while (s != EOL_TOKEN && s != EOF_TOKEN);
return tag;
} else if (p.dataEquals("escape_char")) {
s = p.nextToken();
if (s == TAG_TOKEN || p.getData().length() != 1) {
String escape_char = p.getData();
EscapeTransition.setEscapeChar(escape_char.charAt(0));
} else {
System.out.println("Error in escape_char directive. Directive ignored.");
}
} else if (p.dataEquals("comment_char")) {
s = p.nextToken();
if (s == TAG_TOKEN || p.getData().length() != 1) {
String comment_char = p.getData();
EOLTransition.setCommentChar(comment_char.charAt(0));
} else {
System.out.println("Error in escape_char directive. Directive ignored.");
}
}
}
s = p.nextToken();
}
return null;
}
private boolean seekEND(PushbackReader reader) throws IOException {
Lex p = new Lex(LCStates, reader);
final String END = "END";
int s = p.nextToken();
while ((s != EOF_TOKEN)) {
if (s == TAG_TOKEN) {
if (p.dataStartsWith(END)) {
do {
s = p.nextToken();
} while (s != EOL_TOKEN && s != EOF_TOKEN);
return true;
}
}
s = p.nextToken();
}
return false;
}
private void parseCTYPE(Hashtable table, PushbackReader reader) throws IOException {
Lex p = new Lex(dataStates, reader);
StringBuffer temp = new StringBuffer();
int s = p.nextToken();
if ((s == TAG_TOKEN) && p.dataEquals("copy")) {
p.accept(TAG_TOKEN);
parseCopy("LC_CTYPE", p.getData(), table);
p.accept(EOL_TOKEN);
p.accept(TAG_TOKEN, "END");
p.accept(TAG_TOKEN, "LC_CTYPE");
} else {
while ((s == TAG_TOKEN) && !p.dataEquals("END")) {
String key = p.getData();
temp.setLength(0);
p.accept(TAG_TOKEN);
p.appendDataTo(temp);
s = p.nextToken();
while (s == SEPARATOR_TOKEN) {
p.accept(TAG_TOKEN);
p.appendDataTo(temp);
s = p.nextToken();
}
if (s != EOL_TOKEN) {
throw new IOException();
} else {
table.put(key, temp.toString());
}
s = p.nextToken();
}
p.accept(TAG_TOKEN, "LC_CTYPE");
}
}
private void parseCopy(String section, String toCopy, Hashtable t) throws IOException {
char oldEscapeChar = EscapeTransition.setDefaultEscapeChar();
char oldCommentChar = EOLTransition.setDefaultCommentChar();
try {
PushbackReader reader = createParserInput(toCopy);
String tag = seekLC(reader);
while (tag != null && !section.equals(tag)) {
tag = seekLC(reader);
}
if (tag != null) {
parseSection(t, reader, section);
} else {
//hey {jf} - is this an error?
}
} finally {
EscapeTransition.setEscapeChar(oldEscapeChar);
EOLTransition.setCommentChar(oldCommentChar);
}
}
private void parseLC(Hashtable t, PushbackReader reader, String sectionTag) throws IOException {
Lex input = new Lex(dataStates, reader);
input.accept(TAG_TOKEN);
if (input.dataEquals("copy")) {
input.accept(TAG_TOKEN);
parseCopy(sectionTag, input.getData(), t);
} else {
while ((input.getState() == TAG_TOKEN) && !input.dataEquals("END")) {
String label = input.getData();
Vector values = new Vector();
input.accept(TAG_TOKEN);
String temp = input.getData();
values.addElement(temp);
while (input.nextToken() == SEPARATOR_TOKEN) {
input.accept(TAG_TOKEN);
String value = input.getData();
values.addElement(value);
}
if (values.size() > 1) {
String[] data = new String[values.size()];
values.copyInto(data);
t.put(label, data);
} else {
t.put(label, values.elementAt(0));
}
if (input.getState() != EOL_TOKEN) {
System.out.println(label);
throw new IOException();
}
input.nextToken();
}
}
input.accept(TAG_TOKEN, sectionTag);
}
private void parseCOLLATE(Hashtable table, PushbackReader reader)
throws IOException {
PosixCharMap map = new PosixCharMap(SymbolTransition.getCharMap());
SymbolTransition.setCharMap(map);
try {
Lex input = new Lex(dataStates, reader);
PosixCollationBuilder builder = new PosixCollationBuilder(map);
int s = input.nextToken();
while (s == EOL_TOKEN) s = input.nextToken();
while (s == TAG_TOKEN) {
if (input.dataEquals("END")) {
break;
} else if (input.dataEquals("UNDEFINED")) {
System.err.println("WARNING: Undefined characters will sort last.");
s = input.nextToken();
while (s != EOF_TOKEN && s != EOL_TOKEN) {
s = input.nextToken();
}
} else if (input.dataEquals("copy")) {
//copy collation rules from another locale
input.accept(TAG_TOKEN);
String toCopy = input.getData();
input.accept(EOL_TOKEN);
parseCopy("LC_COLLATE", toCopy, table);
System.err.println("Copying collation rules from "+toCopy+"...");
} else if (input.dataEquals("...")) {
//fill the space between the last element and the next element
System.err.println("ERROR: Ellipsis not supported in collation rules.");
System.err.println(" Line ignored");
} else if (input.dataEquals("replace-after")) {
System.err.println("ERROR: Replace-after not supported in collation rules.");
System.err.println(" Skipping until next replace-end.");
s = input.nextToken();
while (s != EOF_TOKEN) {
if (s == TAG_TOKEN && input.dataEquals("replace-end")) {
input.accept(EOL_TOKEN);
break;
}
}
} else if (input.dataEquals("collating-element")) {
//Several characters should sort as a single element.
input.accept(TAG_TOKEN); //get the symbol
String key = input.getData();
input.accept(TAG_TOKEN, "from");
input.accept(TAG_TOKEN); //get the expansion
String value = input.getData();
builder.defineContraction(key, value);
input.accept(EOL_TOKEN);
} else if (input.dataEquals("collating-symbol")) {
//define a weight symbol. This symbol does not represent a character.
//It's only used for comparison purposes. We define the character
//value for this character to be in the private area since our
//collation stuff doesn't sort that area.
input.accept(TAG_TOKEN);
builder.defineWeightSymbol(input.getData());
input.accept(EOL_TOKEN);
} else if (input.dataEquals("order_start")) {
Vector tempVector = new Vector();
//start reading collation ordering rules.
input.accept(TAG_TOKEN);
tempVector.addElement(input.getData());
s = input.nextToken();
while (s == SEPARATOR_TOKEN) {
input.accept(TAG_TOKEN);
tempVector.addElement(input.getData());
s = input.nextToken();
}
String[] order_start = new String[tempVector.size()];
tempVector.copyInto(order_start);
table.put("sort_order", order_start);
} else if (input.dataEquals("order_end")) {
//build a list of ordered collation elements
input.accept(EOL_TOKEN);
SortedVector order = builder.getSortOrder();
PosixCollationBuilder.CollationRule[] ruleSource =
new PosixCollationBuilder.CollationRule[order.size()];
order.copyInto(ruleSource); //copy into an array so we can add it to the output table
//this is only for information purposes so we can retrieve the source of the
//collationItems with the weights if we want them later
table.put("posix_sort_rules", ruleSource);
} else {
//add a collation item to the list
builder.addRule(input.getData());
s = input.nextToken();
while (s == TAG_TOKEN) {
//we're expecting weights here
builder.addWeight(input.getData());
s = input.nextToken();
if (s == SEPARATOR_TOKEN) {
s = input.nextToken();
}
}
}
s = input.nextToken();
}
input.accept(TAG_TOKEN, "LC_COLLATE");
} finally {
SymbolTransition.setCharMap(map.getParent());
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,328 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/PosixCharMap.java,v $
* $Date: 2002/01/31 01:22:21 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
import com.ibm.text.*;
public class PosixCharMap {
private Hashtable table = new Hashtable();
private Hashtable backTable = null;
private PosixCharMap parentMap;
private String encoding;
public PosixCharMap() {
}
public PosixCharMap(PosixCharMap parent) {
parentMap = parent;
}
public PosixCharMap(String fileName) throws IOException {
this(new FileReader(fileName));
}
public PosixCharMap(String pathName, String fileName) throws IOException {
this(new FileReader(new File(pathName, fileName)));
}
public PosixCharMap(Reader inputReader) throws IOException {
load(new BufferedReader(inputReader));
}
public PosixCharMap getParent() {
return parentMap;
}
public void setParent(PosixCharMap parent) {
parentMap = parent;
}
public void load(String pathName, String fileName) throws IOException {
load(new File(pathName, fileName),"");
}
public void load(String pathName, String fileName, String enc)throws IOException{
load(new File(pathName, fileName),enc);
}
public void load(File file, String enc) throws IOException {
encoding =enc;
load(new BufferedReader(new FileReader(file)));
}
public void load(Reader inputReader) throws IOException {
PosixCharMap oldMap = SymbolTransition.getCharMap();
SymbolTransition.setCharMap(null);
try {
final int TOKEN = 1;
final int EOF = 2;
final int EOL = 3;
final int RANGE = 4;
final Lex.Transition[][] states1 = {
{ //state 0: start
new SpaceTransition(0),
new EOLTransition(EOL),
new Lex.EOFTransition(EOF),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //grab first word
new Lex.StringTransition(SpaceTransition.SPACE_CHARS, Lex.IGNORE_CONSUME, TOKEN),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_CONSUME, TOKEN),
new Lex.EOFTransition(TOKEN),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
}
};
final Lex.Transition[][] states2 = {
{ //These states only return <symbols>. All
//other text is ignored.
new Lex.EOFTransition(EOF),
new EOLTransition(EOL),
new SymbolTransition(TOKEN),
new SpaceTransition(0),
new RangeTransition(RANGE),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, 0)
},
};
PushbackReader input = new PushbackReader(inputReader);
Lex p = new Lex(states1, input);
int state;
do {
state = p.nextToken();
} while ((state != EOF) && !p.dataEquals("CHARMAP"));
p.accept(EOL);
if (state != EOF) {
p = new Lex(states2, input);
state = p.nextToken();
while (state != EOF) {
String key = p.getData();
state = p.nextToken();
while (state == EOL) {
String data = p.getData();
data.trim();
if (data.startsWith("<U") || data.startsWith("#U")) {
String numData = data.substring(2,data.length()-1);
int digit = Integer.parseInt(numData, 16);
defineMapping(key, ""+(char)digit);
}else if(data.startsWith("\\x")){
byte[] encData = new byte[6];
int num = hexToByte(data,encData);
String tData = new String(encData,0,num,encoding);
defineMapping(key,tData);
}
state = p.nextToken();
key=p.getData();
}
// we come here only if there is a range transition
if( state ==RANGE){
String begin = key;
state = p.nextToken();
String end = p.getData();
state = p.nextToken();
String data = p.getData();
data.trim();
byte[] encData = new byte[6];
int num = hexToByte(data,encData);
String tData = new String(encData,0,num,encoding);
String stringVal;
int[] val = getInt(begin);
int beginRange = val[1];
val =getInt(end);
int endRange = val[1];
stringVal = key.substring(0,val[0]);
int digit = (int)(char)tData.charAt(0);
while(beginRange <= endRange){
defineMapping((stringVal+beginRange+">"),""+(char)digit++);
beginRange++;
}
state = p.nextToken();
key=p.getData();
}
//state = p.nextToken();
}
}
} catch (EOFException e) {
} finally {
SymbolTransition.setCharMap(oldMap);
}
}
public int[] getInt(String data){
int i=0;
int[] retVal = new int[2];
int len =data.length();
while(i< len){
if((data.charAt(i))-0x30 < (0x39-0x30)){
break;
}
i++;
}
String sub =data.substring(i,len-1);
retVal[0] =i;
retVal[1]=Integer.parseInt(sub,10);
return retVal;
}
public int hexToByte(String data, byte[] retval){
String tData = data;
int i=0;
for(i=0;i < data.length()/4; i++){
if(tData.charAt(0)=='\\' && tData.charAt(1)=='x'){
String numData = tData.substring(2,4);
retval[i] = (byte) Integer.parseInt(numData,16);
tData = tData.substring(4,tData.length());
}
}
return i;
}
public void defineMapping(String from, String to) {
table.put(from, to);
backTable = null;
}
public void undefineMapping(String from) {
table.remove(from);
backTable = null;
}
public void swap() {
Hashtable newTable = new Hashtable();
Enumeration enum = table.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
String code = (String)table.get(key);
String newKey = toSymbol(code);
String newCode = toLiteral(key);
String prevCode = (String)newTable.get(newKey);
if (prevCode == null || prevCode.compareTo(newCode) > 0) {
newTable.put(newKey, newCode);
}
}
table = newTable;
}
private String toLiteral(String code) {
String data = code.substring(2,code.length()-1);
int digit = Integer.parseInt(data, 16);
return "" + (char)digit;
}
private String toSymbol(String code) {
StringBuffer escapeBuffer = new StringBuffer();
escapeBuffer.append(">");
for (int i = 0; i < code.length(); i++) {
int value = ((int)code.charAt(i)) & 0xFFFF;
while ((value > 0) || (escapeBuffer.length() < 5)) {
char digit = Character.forDigit(value % 16, 16);
escapeBuffer.append(digit);
value >>= 4;
}
}
escapeBuffer.append("U<");
escapeBuffer.reverse();
return escapeBuffer.toString();
}
public void dump(PrintStream out) {
StringBuffer escapeBuffer = new StringBuffer();
Enumeration enum = table.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
String code = (String)table.get(key);
out.print(key);
out.print(" <U");
for (int i = 0; i < code.length(); i++) {
int value = ((int)code.charAt(i)) & 0xFFFF;
escapeBuffer.setLength(0);
while ((value > 0) || (escapeBuffer.length() < 4)) {
char digit = Character.forDigit(value % 16, 16);
escapeBuffer.append(digit);
value >>= 4;
}
escapeBuffer.reverse();
out.print(escapeBuffer.toString());
}
out.println(">");
}
}
public String mapKey(final String key) {
String result = (String)table.get(key);
if (result == null) {
if (parentMap != null) {
result = parentMap.mapKey(key);
} else {
result = key;
}
}
return result;
}
public String backmapValue(final String value) {
if (backTable == null) {
backTable = new Hashtable();
Enumeration enum = table.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
String val = (String)table.get(key);
backTable.put(val, key);
}
}
String result = (String)backTable.get(value);
if (result == null) {
if (parentMap != null) {
result = parentMap.backmapValue(value);
} else {
result = value;
}
}
return result;
}
public Enumeration keys() {
return table.keys();
}
public Enumeration elements() {
return table.elements();
}
public static void main(String args[]) {
try {
PosixCharMap map1 = new PosixCharMap(
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps",
"IBM-1129.UPMAP100.txt");
map1.swap();
map1.dump(System.out);
SymbolTransition.setCharMap(map1);
System.out.println(); System.out.println();
//PosixCharMap map = new PosixCharMap("C:\\projects\\data\\ISO-8859-1.html");
PosixCharMap map = new PosixCharMap(
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps",
"ibm1129.txt");
map.dump(System.out);
System.out.println();
} catch (Exception e) {
System.out.println(e);
}
}
}

View file

@ -0,0 +1,349 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/PosixCollationBuilder.java,v $
* $Date: 2002/01/31 01:22:24 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import com.ibm.text.*;
import java.io.*;
import java.util.*;
class PosixCollationBuilder {
private static final int MAX_WEIGHTS = 4;
private static final int MAX_COMPOSITION = 4;
private static int nextCharNumber = 1;
private Hashtable weightSymbols = new Hashtable();
private Hashtable contractions = new Hashtable();
private Hashtable rules = new Hashtable();
private CollationRule lastRule = null;
private PosixCharMap map;
private SortedVector order;
private static int FIRST_WEIGHT_CHAR = 0x0000F7FF;
private int nextWeightChar = FIRST_WEIGHT_CHAR;
private CollationRule ignoreRule; //rule for the collating-symbol IGNORE
public class CollationRule {
int charNumber;
String value;
int nextWeight = 0;
String[] weightSource = new String[MAX_WEIGHTS];
int weight[][] = null;
StringBuffer source = new StringBuffer();
public CollationRule(String symbol) {
charNumber= nextCharNumber++;
value = symbol;
for (int i = 0; i < MAX_WEIGHTS; i++) {
weightSource[i] = symbol;
}
source.append(map.backmapValue(symbol));
source.append("\t\t");
}
private CollationRule(CollationRule other, int composition) {
charNumber = other.charNumber;
value = other.value;
nextWeight = other.nextWeight;
for (int i = 0; i < MAX_WEIGHTS; i++) {
String source = other.weightSource[i];
if (source.length() > composition) {
weightSource[i] = ""+source.charAt(composition);
} else {
weightSource[i] = value;
}
}
}
//HexToUnicodeTransliterator myTranslit = new HexToUnicodeTransliterator("<U###0>");
public void addWeight(String symbol) {
// ReplaceableString tSymbol = new ReplaceableString(symbol);
// myTranslit.transliterate(tSymbol);
//limit the size of a single weight
if (symbol.length() > MAX_COMPOSITION) {
System.err.println("WARNING: Weights of composition greater than "+MAX_COMPOSITION+" were truncated.");
symbol = symbol.substring(0, MAX_COMPOSITION);
}
//limit the number of weights
if (nextWeight < MAX_WEIGHTS) {
if (nextWeight > 0) {
source.append(";");
}
for (int i = 0; i < symbol.length(); i++) {
source.append(map.backmapValue(""+symbol.charAt(i)));
}
weightSource[nextWeight++] = symbol;
weight = null;
}
}
public int compare(CollationRule other) {
if (other == null) return compare(ignoreRule);
resolveWeights();
other.resolveWeights();
int compareSize = Math.min(getSize(), other.getSize());
for (int j = 0; j < compareSize; j++) {
for (int i = 0; i < MAX_WEIGHTS; i++) {
int diff = weight[j][i] - other.weight[j][i];
if (diff < 0) {
return -(i+1);
} if (diff > 0) {
return i+1;
}
}
}
return getSize() - other.getSize();
}
public boolean isMultiWeight() {
return getSize() > 1;
}
public int getSize() {
int size = 0;
for (int i = 1; i < weightSource.length; i++) {
size = Math.max(size, weightSource[i].length());
}
return size;
}
public CollationRule getComponent(int ndx) {
return new CollationRule(this, ndx);
}
public String getValue() {
return value;
}
public String getSymbol() {
String newValue = isContraction();
if (newValue != null) {
return newValue;
} else {
newValue = isWeightSymbol();
if (newValue != null) {
return newValue;
} else {
return value;
}
}
}
public String getSource() {
return source.toString();
}
private String isContraction() {
return (String)contractions.get(value);
}
private String isWeightSymbol() {
return (String)weightSymbols.get(value);
}
public CollationRule seeksToRule() {
CollationRule comp;
if (getSize() <= 1) {
comp = this; //save an object creation
} else {
comp = getComponent(0);
}
int ndx = order.indexOf(comp);
if (ndx == 0) {
return this;
} else {
CollationRule exp;
do {
exp = (CollationRule)order.elementAt(ndx--);
} while (ndx > 0 && exp.getSize() > 1);
return exp;
}
}
public String getExpansion() {
if (getSize() <= 1) {
return null;
} else {
StringBuffer expansion = new StringBuffer();
for (int j = 0; j < getSize(); j++) {
CollationRule comp = getComponent(j);
int ndx = order.indexOf(comp);
CollationRule exp;
do {
exp = (CollationRule)order.elementAt(ndx--);
} while (ndx >= 0 && exp.getSize() > 1);
expansion.append(exp.getSymbol());
}
return expansion.toString();
}
}
public String toString() {
return source.toString();
/* resolveWeights();
StringBuffer buf = new StringBuffer();
buf.append(charNumber);
buf.append(' ');
buf.append(value);
buf.append(' ');
buf.append(getSymbol());
buf.append(' ');
buf.append((isWeightSymbol() != null)?"W":" ");
buf.append(' ');
for (int i = 0; i < MAX_WEIGHTS; i++) {
buf.append(weightSource[i]);
buf.append(' ');
}
for (int i = 0; i < getSize(); i++) {
buf.append("[ ");
for (int j = 0; j < MAX_WEIGHTS; j++) {
int w = weight[i][j];
buf.append(w);
buf.append(' ');
}
buf.append(']');
}
return buf.toString();
*/
}
private void resolveWeights() {
if (weight == null) {
weight = new int[MAX_COMPOSITION][MAX_WEIGHTS];
for (int j = 0; j < MAX_WEIGHTS; j++) {
String symbol = weightSource[j];
if (symbol.length() <= 1) {
weight[0][j] = ordinalityOf(symbol);
} else {
for (int i = 0; i < symbol.length(); i++) {
char c = symbol.charAt(i);
weight[i][j] = ordinalityOf(""+c);
}
}
}
}
}
}
public PosixCollationBuilder(PosixCharMap map) {
this.map = map;
String ignoreSymbol = defineWeightSymbol("IGNORE");
ignoreRule = new CollationRule(ignoreSymbol);
rules.put(ignoreSymbol, ignoreRule);
lastRule = ignoreRule;
//{{INIT_CONTROLS
//}}
}
public String defineWeightSymbol(String symbol) {
order = null;
String c = nextFreeWeightChar();
map.defineMapping(symbol, c);
weightSymbols.put(c, symbol);
weightSymbols.put(symbol, c);
return c;
}
public String defineContraction(String symbol, String value) {
order = null;
String c = nextFreeWeightChar();
map.defineMapping(symbol, c);
contractions.put(c, value);
return c;
}
private String nextFreeWeightChar() {
String result = "";
String mappedSource;
do {
result = ""+(char)nextWeightChar--;
mappedSource = map.backmapValue(result);
} while (result != mappedSource);
return result;
}
public int ordinalityOf(String symbol) {
// HexToUnicodeTransliterator newTranslit = new HexToUnicodeTransliterator();
// ReplaceableString tSymbol = new ReplaceableString(symbol);
// newTranslit.transliterate(tSymbol);
CollationRule w = (CollationRule)rules.get(symbol);
if (w != null) {
return w.charNumber;
} else {
System.err.print("ERROR: Weight symbol not found: ");
for (int i = 0 ; i < symbol.length(); i++) {
char c = symbol.charAt(i);
System.err.print("\\u");
System.err.print(HEX_DIGIT[(c & 0x0F000) >> 12]); // HEX_DIGIT works for octal
System.err.print(HEX_DIGIT[(c & 0x0F00) >> 8]); // HEX_DIGIT works for octal
System.err.print(HEX_DIGIT[(c & 0x00F0) >> 4]);
System.err.println(HEX_DIGIT[(c & 0x000F)]);
}
System.err.println(" Weight given maximum possible value.");
return Integer.MAX_VALUE;
}
}
// HexToUnicodeTransliterator myTranslit = new HexToUnicodeTransliterator("<U###0>");
public void addRule(String symbol) {
// ReplaceableString tSymbol = new ReplaceableString(symbol);
// myTranslit.transliterate(tSymbol);
if (symbol.length() > 1) {
System.err.println("WARNING: Undefined element '"+symbol+"'. collating-symbol generated.");
symbol = defineWeightSymbol(symbol);
}
order = null;
lastRule = new CollationRule(symbol);
rules.put(symbol, lastRule);
}
public void addRule(CollationRule rule) {
order = null;
lastRule = rule;
rules.put(rule.value, rule);
}
public void addWeight(String weight) {
if (weight.length() > 1) {
//check to see if it's a bogus weight symbol.
weight = map.mapKey(weight);
}
order = null;
lastRule.addWeight(weight);
}
public Enumeration getRules() {
return rules.elements();
}
public SortedVector getSortOrder() {
if (order == null) {
order = new SortedVector(
new Comparator() {
public int compare(final Object i, final Object j) {
final CollationRule o1 = (CollationRule)i;
final CollationRule o2 = (CollationRule)j;
final boolean w1 = o1.isWeightSymbol() != null;
final boolean w2 = o2.isWeightSymbol() != null;
//sort weights first
if (w1 && !w2) {
return -1;
} else if (!w1 && w2) {
return 1;
} else {
return o1.compare(o2);
}
}
}
);
order.addElements(rules.elements());
//remove weight symbols from the list
int i;
for (i = 0; i < order.size(); i++) {
CollationRule r = (CollationRule)order.elementAt(i);
if (r.isWeightSymbol() == null) {
break;
}
}
order.removeElements(0, i);
}
return order;
}
static final char[] HEX_DIGIT = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'};
//{{DECLARE_CONTROLS
//}}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,76 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/QuoteTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class QuoteTransition extends ComplexTransition {
public static final QuoteTransition GLOBAL = new QuoteTransition(SUCCESS);
public static final char STRING_CHAR = '"';
public QuoteTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return STRING_CHAR == (char)c;
}
protected Lex.Transition[][] getStates() {
return states;
}
private static final Lex.Transition[][] states = {
{ //state 0:
new Lex.CharTransition(STRING_CHAR, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal character in quoted string")
},
{ //state 1:
new Lex.CharTransition(STRING_CHAR, Lex.IGNORE_CONSUME, SUCCESS),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_CONSUME, -2),
new EscapeTransition(-1),
new SymbolTransition(-1),
new Lex.EOFTransition(-2),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 2: failure from eof
new Lex.ParseExceptionTransition("unterminated string")
}
};
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new QuoteTransition(SUCCESS),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
EscapeTransition.setEscapeChar('/');
String text = "\"hello<\"/>>/d32world\"\"<one>/\n<two>\"";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
System.out.println(parser.getData());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,47 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/RangeTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class RangeTransition extends ComplexTransition {
public static final RangeTransition GLOBAL = new RangeTransition(SUCCESS);
public static final String RANGE_CHARS = "...";
public RangeTransition(int success){
super(success);
}
public boolean accepts(int c){
return RANGE_CHARS.indexOf((char)c) >=0;
}
protected Lex.Transition[][]getStates(){
return states;
}
private static final Lex.Transition[][] states= {
{ //state 0:
new Lex.StringTransition(RANGE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal space character")
},
{ //state 1:
new Lex.EOFTransition(SUCCESS),
new Lex.StringTransition(RANGE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, SUCCESS)
},
};
}

View file

@ -0,0 +1,356 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/SortedVector.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.util.Vector;
import java.util.Enumeration;
/**
Implements a sorted vector. You can add anything to it; when you access any element, it sorts
the array internally when necessary.
<p>A Comparator is used to compare the elements, allowing arbitrary orderings.
If no Comparator is supplied, then one is constructed based on the type
of the first element added. Only Numbers and Comparables are handled.
<p>Duplicates are allowed.
*/
final public class SortedVector {
/**
Copies elements of vector, enumeration or array
Note: the objects in the source are NOT cloned.
Do not change them or the sorting will be invalid.
*/
public SortedVector(Object[] newValues, Comparator comparator) {
this.comparator = comparator;
addElements(newValues);
//{{INIT_CONTROLS
//}}
}
public SortedVector(Vector newValues, Comparator comparator) {
this.comparator = comparator;
addElements(newValues);
}
public SortedVector(Enumeration newValues, Comparator comparator) {
this.comparator = comparator;
addElements(newValues);
}
public SortedVector(Object[] newValues) {
addElements(newValues);
}
public SortedVector(Comparator comparator) {
this.comparator = comparator;
}
public SortedVector(Vector newValues) {
addElements(newValues);
}
public SortedVector(Enumeration newValues) {
addElements(newValues);
}
public SortedVector() {
}
/**
Adds one element.
*/
public void addElement(Object element) {
if (count >= dataArray.length) setCapacity(count*2 + 17);
dataArray[count++] = element;
isValid = false;
}
/**
Adds multiple elements. Faster than adding one at a time.
*/
public void addElements(Object[] newValues) {
int newCount = count + newValues.length;
if (newCount > dataArray.length) setCapacity(newCount);
for (int i = count; i < newCount; ++i)
dataArray[i] = newValues[i-count];
count = newCount;
isValid = false;
}
public void addElements(Vector newValues) {
int newCount = count + newValues.size();
if (newCount > dataArray.length) setCapacity(newCount);
for (int i = count; i < newCount; ++i)
dataArray[i] = newValues.elementAt(i-count);
count = newCount;
isValid = false;
}
public void addElements(Enumeration newValues) {
while (newValues.hasMoreElements()) {
addElement(newValues.nextElement());
}
}
/**
Removes elements at indices >= startIndex and < endIndex
*/
public void removeElements(int startIndex, int endIndex) {
if (!isValid) validate();
System.arraycopy(dataArray,endIndex,dataArray,startIndex,count - endIndex);
for (int i = count - (endIndex - startIndex); i < count;++i)
dataArray[i] = null; // free up storage
count -= (endIndex - startIndex);
}
/**
Sets comparator
*/
public void setComparator(Comparator comparator) {
this.comparator = comparator;
isValid = false;
}
public Comparator getComparator() {
if (comparator == null) validateComparator();
return this.comparator;
}
/**
Gets size, the actual number of elements.
*/
public int size() {
return count;
}
/**
Gets capacity, the number of elements you can have without growing the array.
*/
public int capacity() {
return dataArray.length;
}
/**
Sets capacity, the number of elements you can have without growing the array.
*/
public void setCapacity(int newSize) {
Object[] temp = new Object[newSize];
System.arraycopy(dataArray, 0, temp, 0, Math.min(count,newSize));
dataArray = temp;
}
/**
Trims the array.
*/
public void trimToSize() {
setCapacity(count);
}
/**
Gets the element at the index
*/
public Object elementAt (int index) {
if (!isValid) validate();
if (index >= count) return dataArray[dataArray.length];
return dataArray[index];
}
/**
Sees whether the vector contains the object
*/
public boolean contains (Object value) {
int index = indexOf(value);
return (index >= 0 && comparator.compare(value,dataArray[index]) == 0);
}
/**
Gets an enumeration
*/
public Enumeration elements() {
if (!isValid) validate();
return new ArrayEnumeration(dataArray,0,count);
}
public void copyInto(Object[] toFill) {
if (!isValid) validate();
System.arraycopy(dataArray,0,toFill,0,toFill.length);
}
/**
Finds first index whose value is greater than or equal to searchValue
If there are none, returns -1
*/
public int indexOf(Object searchValue)
{
if (!isValid) validate();
int index = startIndex;
if (0 <= comparator.compare(searchValue, dataArray[auxStart])) {
index += auxStart;
}
// very fast, completely unrolled binary search
// each case deliberately falls through to the next
switch (power) {
case 31: if (0 > comparator.compare(searchValue, dataArray[index-0x40000000])) index -= 0x40000000;
case 30: if (0 > comparator.compare(searchValue, dataArray[index-0x20000000])) index -= 0x20000000;
case 29: if (0 > comparator.compare(searchValue, dataArray[index-0x10000000])) index -= 0x10000000;
case 28: if (0 > comparator.compare(searchValue, dataArray[index-0x8000000])) index -= 0x8000000;
case 27: if (0 > comparator.compare(searchValue, dataArray[index-0x4000000])) index -= 0x4000000;
case 26: if (0 > comparator.compare(searchValue, dataArray[index-0x2000000])) index -= 0x2000000;
case 25: if (0 > comparator.compare(searchValue, dataArray[index-0x1000000])) index -= 0x1000000;
case 24: if (0 > comparator.compare(searchValue, dataArray[index-0x800000])) index -= 0x800000;
case 23: if (0 > comparator.compare(searchValue, dataArray[index-0x400000])) index -= 0x400000;
case 22: if (0 > comparator.compare(searchValue, dataArray[index-0x200000])) index -= 0x200000;
case 21: if (0 > comparator.compare(searchValue, dataArray[index-0x100000])) index -= 0x100000;
case 20: if (0 > comparator.compare(searchValue, dataArray[index-0x80000])) index -= 0x80000;
case 19: if (0 > comparator.compare(searchValue, dataArray[index-0x40000])) index -= 0x40000;
case 18: if (0 > comparator.compare(searchValue, dataArray[index-0x20000])) index -= 0x20000;
case 17: if (0 > comparator.compare(searchValue, dataArray[index-0x10000])) index -= 0x10000;
case 16: if (0 > comparator.compare(searchValue, dataArray[index-0x8000])) index -= 0x8000;
case 15: if (0 > comparator.compare(searchValue, dataArray[index-0x4000])) index -= 0x4000;
case 14: if (0 > comparator.compare(searchValue, dataArray[index-0x2000])) index -= 0x2000;
case 13: if (0 > comparator.compare(searchValue, dataArray[index-0x1000])) index -= 0x1000;
case 12: if (0 > comparator.compare(searchValue, dataArray[index-0x800])) index -= 0x800;
case 11: if (0 > comparator.compare(searchValue, dataArray[index-0x400])) index -= 0x400;
case 10: if (0 > comparator.compare(searchValue, dataArray[index-0x200])) index -= 0x200;
case 9: if (0 > comparator.compare(searchValue, dataArray[index-0x100])) index -= 0x100;
case 8: if (0 > comparator.compare(searchValue, dataArray[index-0x80])) index -= 0x80;
case 7: if (0 > comparator.compare(searchValue, dataArray[index-0x40])) index -= 0x40;
case 6: if (0 > comparator.compare(searchValue, dataArray[index-0x20])) index -= 0x20;
case 5: if (0 > comparator.compare(searchValue, dataArray[index-0x10])) index -= 0x10;
case 4: if (0 > comparator.compare(searchValue, dataArray[index-0x8])) index -= 8;
case 3: if (0 > comparator.compare(searchValue, dataArray[index-0x4])) index -= 4;
case 2: if (0 > comparator.compare(searchValue, dataArray[index-0x2])) index -= 2;
case 1: if (0 > comparator.compare(searchValue, dataArray[index-0x1])) index -= 1;
case 0: if (0 > comparator.compare(searchValue, dataArray[index])) index -= 1;
}
return index;
}
// ================= privates ==================
/** Only call if comparator is null
*/
private void validateComparator() {
try {
Object trial = dataArray[0];
if (trial instanceof Float || trial instanceof Double) {
comparator = new DoubleComparator();
} else if (trial instanceof Integer) {
comparator = new IntegerComparator();
} else if (trial instanceof Number) {
comparator = new LongComparator();
} else if (trial instanceof String) {
comparator = new StringComparator();
} else {
comparator = new ComparableComparator();
}
} catch (Exception e) {} // leave null
}
private void validate() {
if (isValid) return;
// if the Comparator is null, then pick a reasonable one
if (comparator == null) validateComparator();
// determine search parameters
// find least power of 2 greater than count
for (power = exp2.length-1; power > 0 && count < exp2[power]; power--) {}
// determine the starting point
if (exp2[power] != count) {
auxStart = count - exp2[power];
} else {
auxStart = 0;
}
startIndex = exp2[power]-1;
// shell sort. Later, make this a QuickSort
int lo = 0;
int up = count-1;
for (int step = up - lo + 1; step > 1;) {
if (step < 5)
step = 1;
else step = (5 * step - 1) / 11;
for (int i = up - step; i >= lo; --i) {
Object temp = dataArray[i];
int j;
for (j = i + step; j <= up && 0 > comparator.compare(dataArray[j],temp); j += step)
dataArray[j-step] = dataArray[j];
dataArray[j-step] = temp;
}
}
isValid = true;
}
private Object[] dataArray = new Object[16];
private Comparator comparator;
private int count = 0;
private boolean isValid = false;
private int auxStart;
private int startIndex;
private int power;
private static final int exp2[] = {
0x1, 0x2, 0x4, 0x8,
0x10, 0x20, 0x40, 0x80,
0x100, 0x200, 0x400, 0x800,
0x1000, 0x2000, 0x4000, 0x8000,
0x10000, 0x20000, 0x40000, 0x80000,
0x100000, 0x200000, 0x400000, 0x800000,
0x1000000, 0x2000000, 0x4000000, 0x8000000,
0x10000000, 0x20000000, 0x40000000};
// Utility Classes
public static final class LongComparator implements Comparator {
public int compare(Object a, Object b) {
long aa = ((Number)a).longValue();
long bb = ((Number)b).longValue();
return (aa < bb ? -1 : aa > bb ? 1 : 0);
}
}
public static final class IntegerComparator implements Comparator {
public int compare(Object a, Object b) {
return (((Number)a).intValue() - ((Number)b).intValue());
}
}
public static final class DoubleComparator implements Comparator {
public int compare(Object a, Object b) {
double aa = ((Number)a).doubleValue();
double bb = ((Number)b).doubleValue();
return (aa < bb ? -1 : aa > bb ? 1 : 0);
}
}
public static final class ComparableComparator implements Comparator {
public int compare(Object a, Object b) {
return ((Comparable)a).compareTo(b);
}
}
public static final class StringComparator implements Comparator {
public int compare(Object a, Object b) {
return ((String)a).compareTo((String)b);
};
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,46 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/SpaceTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class SpaceTransition extends ComplexTransition {
public static final SpaceTransition GLOBAL = new SpaceTransition(SUCCESS);
public static final String SPACE_CHARS = " \t";
public SpaceTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return SPACE_CHARS.indexOf((char)c) >= 0;
}
protected Lex.Transition[][] getStates() {
return states;
}
private static final Lex.Transition[][] states = {
{ //state 0:
new Lex.StringTransition(SPACE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal space character")
},
{ //state 1:
new Lex.EOFTransition(SUCCESS),
new Lex.StringTransition(SPACE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, SUCCESS)
},
};
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,103 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/SymbolTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class SymbolTransition extends ComplexTransition {
private static PosixCharMap mapping = new PosixCharMap();
public static final SymbolTransition GLOBAL = new SymbolTransition(SUCCESS);
public static void setCharMap(PosixCharMap mappingIn) {
mapping = mappingIn;
if (mapping == null) {
mapping = new PosixCharMap();
}
}
public static PosixCharMap getCharMap() {
return mapping;
}
public SymbolTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return '<' == (char)c;
}
protected void handleSuccess(Lex parser, StringBuffer output) {
String text = parser.getData();
String mappedText = mapping.mapKey(text);
if (mappedText != null) {
output.append(mappedText);
} else {
output.append(text);
}
}
protected Lex.Transition[][] getStates() {
synchronized (getClass()) {
if (states == null) {
states = new Lex.Transition[][] {
{ //state 0:
new Lex.CharTransition('<', Lex.ACCUMULATE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal characters in symbol")
},
{ //state 1:
new Lex.CharTransition('/', Lex.ACCUMULATE_CONSUME, -2),
new Lex.CharTransition('>', Lex.ACCUMULATE_CONSUME, SUCCESS),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, -3),
new Lex.EOFTransition(-3),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 2:
new Lex.CharTransition('>', Lex.ACCUMULATE_CONSUME, -1),
new Lex.CharTransition('/', Lex.ACCUMULATE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal escape character in symbol")
},
{ //state 3: failure
new Lex.ParseExceptionTransition("unexpected end of line/file")
}
};
}
}
return states;
}
private static Lex.Transition[][] states;
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new SymbolTransition(SUCCESS),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
//String text = "<CAPITAL><\"<><//><V%><N6><CYRILLIC>";
String text = "<U><S><D> ";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
System.out.println(parser.getData());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,72 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/TokenTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class TokenTransition extends ComplexTransition {
public static final TokenTransition GLOBAL = new TokenTransition(SUCCESS);
public static final String SEPARATOR_CHARS = ";" + SpaceTransition.SPACE_CHARS;
public TokenTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return (c > 0) &&
!EOLTransition.GLOBAL.accepts(c) &&
!SpaceTransition.GLOBAL.accepts(c) &&
(
(SEPARATOR_CHARS.indexOf((char)c) < 0) ||
SymbolTransition.GLOBAL.accepts(c) ||
QuoteTransition.GLOBAL.accepts(c) ||
EscapeTransition.GLOBAL.accepts(c)
);
}
protected Lex.Transition[][] getStates() {
return states;
}
private static final Lex.Transition[][] states = {
{ //state 0:
new SymbolTransition(-1),
new QuoteTransition(-1),
new EscapeTransition(-1),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, -2),
new Lex.StringTransition(SEPARATOR_CHARS, Lex.IGNORE_PUTBACK, -3),
new Lex.EOFTransition(-4),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 1:
new SymbolTransition(-1),
new QuoteTransition(-1),
new EscapeTransition(-1),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, SUCCESS),
new Lex.StringTransition(SEPARATOR_CHARS, Lex.IGNORE_PUTBACK, SUCCESS),
new Lex.EOFTransition(SUCCESS),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 2: failure - unexpected EOL
new Lex.ParseExceptionTransition("unexpected EOL in token")
},
{ //state 3: failure
new Lex.ParseExceptionTransition("unexpected seperator character in token")
},
{ //state 4: failure
new Lex.ParseExceptionTransition("unexpected EOF in token")
},
};
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,603 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/tool/localeconverter/myLocaleElements.java,v $
* $Date: 2002/01/31 01:22:21 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
/*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
*
* Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
*
*/
/**
*
* Table of Java supplied standard locale elements
*
* automatically generated by java LocaleTool LocaleElements.java
*
* Date Created: Wed Aug 21 15:47:57 1996
*
* Locale Elements and Patterns: last update 10/23/96
*
*
*/
// WARNING : the format of this file will change in the future!
package com.ibm.tools.localeconverter;
import java.util.ListResourceBundle;
public class myLocaleElements extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "LocaleString", "en_US" }, // locale id based on iso codes
{ "LocaleID", "0409" }, // Windows id
{ "ShortLanguage", "eng" }, // iso-3 abbrev lang name
{ "ShortCountry", "USA" }, // iso-3 abbrev country name
{ "Languages", // language names
new String[][] {
{ "ab", "Abkhazian" },
{ "aa", "Afar" },
{ "af", "Afrikaans" },
{ "sq", "Albanian" },
{ "am", "Amharic" },
{ "ar", "Arabic" },
{ "hy", "Armenian" },
{ "as", "Assamese" },
{ "ay", "Aymara" },
{ "az", "Azerbaijani" },
{ "ba", "Bashkir" },
{ "eu", "Basque" },
{ "bn", "Bengali" },
{ "dz", "Bhutani" },
{ "bh", "Bihari" },
{ "bi", "Bislama" },
{ "br", "Breton" },
{ "bg", "Bulgarian" },
{ "my", "Burmese" },
{ "be", "Byelorussian" },
{ "km", "Cambodian" },
{ "ca", "Catalan" },
{ "zh", "Chinese" },
{ "co", "Corsican" },
{ "hr", "Croatian" },
{ "cs", "Czech" },
{ "da", "Danish" },
{ "nl", "Dutch" },
{ "en", "English" },
{ "eo", "Esperanto" },
{ "et", "Estonian" },
{ "fo", "Faeroese" },
{ "fj", "Fiji" },
{ "fi", "Finnish" },
{ "fr", "French" },
{ "fy", "Frisian" },
{ "gl", "Galician" },
{ "ka", "Georgian" },
{ "de", "German" },
{ "el", "Greek" },
{ "kl", "Greenlandic" },
{ "gn", "Guarani" },
{ "gu", "Gujarati" },
{ "ha", "Hausa" },
{ "iw", "Hebrew" },
{ "hi", "Hindi" },
{ "hu", "Hungarian" },
{ "is", "Icelandic" },
{ "in", "Indonesian" },
{ "ia", "Interlingua" },
{ "ie", "Interlingue" },
{ "ik", "Inupiak" },
{ "ga", "Irish" },
{ "it", "Italian" },
{ "ja", "Japanese" },
{ "jw", "Javanese" },
{ "kn", "Kannada" },
{ "ks", "Kashmiri" },
{ "kk", "Kazakh" },
{ "rw", "Kinyarwanda" },
{ "ky", "Kirghiz" },
{ "rn", "Kirundi" },
{ "ko", "Korean" },
{ "ku", "Kurdish" },
{ "lo", "Laothian" },
{ "la", "Latin" },
{ "lv", "Latvian (Lettish)" },
{ "ln", "Lingala" },
{ "lt", "Lithuanian" },
{ "mk", "Macedonian" },
{ "mg", "Malagasy" },
{ "ms", "Malay" },
{ "ml", "Malayalam" },
{ "mt", "Maltese" },
{ "mi", "Maori" },
{ "mr", "Marathi" },
{ "mo", "Moldavian" },
{ "mn", "Mongolian" },
{ "na", "Nauru" },
{ "ne", "Nepali" },
{ "no", "Norwegian" },
{ "oc", "Occitan" },
{ "or", "Oriya" },
{ "om", "Oromo (Afan)" },
{ "ps", "Pashto (Pushto)" },
{ "fa", "Persian" },
{ "pl", "Polish" },
{ "pt", "Portuguese" },
{ "pa", "Punjabi" },
{ "qu", "Quechua" },
{ "rm", "Rhaeto-Romance" },
{ "ro", "Romanian" },
{ "ru", "Russian" },
{ "sm", "Samoan" },
{ "sg", "Sangro" },
{ "sa", "Sanskrit" },
{ "gd", "Scots Gaelic" },
{ "sr", "Serbian" },
{ "sh", "Serbo-Croatian" },
{ "st", "Sesotho" },
{ "tn", "Setswana" },
{ "sn", "Shona" },
{ "sd", "Sindhi" },
{ "si", "Singhalese" },
{ "ss", "Siswati" },
{ "sk", "Slovak" },
{ "sl", "Slovenian" },
{ "so", "Somali" },
{ "es", "Spanish" },
{ "su", "Sundanese" },
{ "sw", "Swahili" },
{ "sv", "Swedish" },
{ "tl", "Tagalog" },
{ "tg", "Tajik" },
{ "ta", "Tamil" },
{ "tt", "Tatar" },
{ "te", "Telugu" },
{ "th", "Thai" },
{ "bo", "Tibetan" },
{ "ti", "Tigrinya" },
{ "to", "Tonga" },
{ "ts", "Tsonga" },
{ "tr", "Turkish" },
{ "tk", "Turkmen" },
{ "tw", "Twi" },
{ "uk", "Ukrainian" },
{ "ur", "Urdu" },
{ "uz", "Uzbek" },
{ "vi", "Vietnamese" },
{ "vo", "Volapuk" },
{ "cy", "Welsh" },
{ "wo", "Wolof" },
{ "xh", "Xhosa" },
{ "ji", "Yiddish" },
{ "yo", "Yoruba" },
{ "zu", "Zulu" }
}
},
{ "Countries", // country names
new String[][] {
{ "AF", "Afghanistan" },
{ "AL", "Albania" },
{ "DZ", "Algeria" },
{ "AD", "Andorra" },
{ "AO", "Angola" },
{ "AI", "Anguilla" },
{ "AR", "Argentina" },
{ "AM", "Armenia" },
{ "AW", "Aruba" },
{ "AU", "Australia" },
{ "AT", "Austria" },
{ "AZ", "Azerbaijan" },
{ "BS", "Bahamas" },
{ "BH", "Bahrain" },
{ "BD", "Bangladesh" },
{ "BB", "Barbados" },
{ "BY", "Belarus" },
{ "BE", "Belgium" },
{ "BZ", "Belize" },
{ "BJ", "Benin" },
{ "BM", "Bermuda" },
{ "BT", "Bhutan" },
{ "BO", "Bolivia" },
{ "BA", "Bosnia and Herzegovina" },
{ "BW", "Botswana" },
{ "BR", "Brazil" },
{ "BN", "Brunei Darussalam" },
{ "BG", "Bulgaria" },
{ "BF", "Burkina Faso" },
{ "BI", "Burundi" },
{ "KH", "Cambodia" },
{ "CM", "Cameroon" },
{ "CA", "Canada" },
{ "CV", "Cape Verde" },
{ "CF", "Central African Republic" },
{ "TD", "Chad" },
{ "CL", "Chile" },
{ "CN", "China" },
{ "CO", "Colombia" },
{ "KM", "Comoros" },
{ "CG", "Congo" },
{ "CR", "Costa Rica" },
{ "CI", "Cote D'ivoire" },
{ "HR", "Croatia" },
{ "CU", "Cuba" },
{ "CY", "Cyprus" },
{ "CZ", "Czech Republic" },
{ "DK", "Denmark" },
{ "DJ", "Djibouti" },
{ "DM", "Dominica" },
{ "DO", "Dominican Republic" },
{ "TP", "East Timor" },
{ "EC", "Ecuador" },
{ "EG", "Egypt" },
{ "SV", "El Salvador" },
{ "GQ", "Equatorial Guinea" },
{ "ER", "Eritrea" },
{ "EE", "Estonia" },
{ "ET", "Ethiopia" },
{ "FJ", "Fiji" },
{ "FI", "Finland" },
{ "FR", "France" },
{ "GF", "French Guiana" },
{ "PF", "French Polynesia" },
{ "TF", "French Southern Territories" },
{ "GA", "Gabon" },
{ "GM", "Gambia" },
{ "GE", "Georgia" },
{ "DE", "Germany" },
{ "GH", "Ghana" },
{ "GR", "Greece" },
{ "GP", "Guadeloupe" },
{ "GT", "Guatemala" },
{ "GN", "Guinea" },
{ "GW", "Guinea-Bissau" },
{ "GY", "Guyana" },
{ "HT", "Haiti" },
{ "HN", "Honduras" },
{ "HK", "Hong Kong" },
{ "HU", "Hungary" },
{ "IS", "Iceland" },
{ "IN", "India" },
{ "ID", "Indonesia" },
{ "IR", "Iran" },
{ "IQ", "Iraq" },
{ "IE", "Ireland" },
{ "IL", "Israel" },
{ "IT", "Italy" },
{ "JM", "Jamaica" },
{ "JP", "Japan" },
{ "JO", "Jordan" },
{ "KZ", "Kazakhstan" },
{ "KE", "Kenya" },
{ "KI", "Kiribati" },
{ "KP", "North Korea" },
{ "KR", "South Korea" },
{ "KW", "Kuwait" },
{ "KG", "Kyrgyzstan" },
{ "LA", "Laos" },
{ "LV", "Latvia" },
{ "LB", "Lebanon" },
{ "LS", "Lesotho" },
{ "LR", "Liberia" },
{ "LY", "Libyan Arab Jamahiriya" },
{ "LI", "Liechtenstein" },
{ "LT", "Lithuania" },
{ "LU", "Luxembourg" },
{ "MK", "Macedonia" },
{ "MG", "Madagascar" },
{ "MY", "Malaysia" },
{ "ML", "Mali" },
{ "MT", "Malta" },
{ "MQ", "Martinique" },
{ "MR", "Mauritania" },
{ "MU", "Mauritius" },
{ "YT", "Mayotte" },
{ "MX", "Mexico" },
{ "FM", "Micronesia" },
{ "MD", "Moldova" },
{ "MC", "Monaco" },
{ "MN", "Mongolia" },
{ "MS", "Montserrat" },
{ "MA", "Morocco" },
{ "MZ", "Mozambique" },
{ "MM", "Myanmar" },
{ "NA", "Namibia" },
{ "NP", "Nepal" },
{ "NL", "Netherlands" },
{ "AN", "Netherlands Antilles" },
{ "NC", "New Caledonia" },
{ "NZ", "New Zealand" },
{ "NI", "Nicaragua" },
{ "NE", "Niger" },
{ "NG", "Nigeria" },
{ "NU", "Niue" },
{ "NO", "Norway" },
{ "OM", "Oman" },
{ "PK", "Pakistan" },
{ "PA", "Panama" },
{ "PG", "Papua New Guinea" },
{ "PY", "Paraguay" },
{ "PE", "Peru" },
{ "PH", "Philippines" },
{ "PL", "Poland" },
{ "PT", "Portugal" },
{ "PR", "Puerto Rico" },
{ "QA", "Qatar" },
{ "RO", "Romania" },
{ "RU", "Russian Federation" },
{ "RW", "Rwanda" },
{ "SA", "Saudi Arabia" },
{ "SN", "Senegal" },
{ "SP", "Serbia" },
{ "SC", "Seychelles" },
{ "SL", "Sierra Leone" },
{ "SG", "Singapore" },
{ "SK", "Slovakia" },
{ "SI", "Slovenia" },
{ "SO", "Somalia" },
{ "ZA", "South Africa" },
{ "ES", "Spain" },
{ "LK", "Sri Lanka" },
{ "SD", "Sudan" },
{ "SR", "Suriname" },
{ "SZ", "Swaziland" },
{ "SE", "Sweden" },
{ "CH", "Switzerland" },
{ "SY", "Syria" },
{ "TW", "Taiwan" },
{ "TJ", "Tajikistan" },
{ "TZ", "Tanzania" },
{ "TH", "Thailand" },
{ "TG", "Togo" },
{ "TK", "Tokelau" },
{ "TO", "Tonga" },
{ "TT", "Trinidad and Tobago" },
{ "TN", "Tunisia" },
{ "TR", "Turkey" },
{ "TM", "Turkmenistan" },
{ "UG", "Uganda" },
{ "UA", "Ukraine" },
{ "AE", "United Arab Emirates" },
{ "GB", "United Kingdom" },
{ "US", "United States" },
{ "UY", "Uruguay" },
{ "UZ", "Uzbekistan" },
{ "VU", "Vanuatu" },
{ "VA", "Vatican" },
{ "VE", "Venezuela" },
{ "VN", "Viet Nam" },
{ "VG", "British Virgin Islands" },
{ "VI", "U.S. Virgin Islands" },
{ "EH", "Western Sahara" },
{ "YE", "Yemen" },
{ "YU", "Yugoslavia" },
{ "ZR", "Zaire" },
{ "ZM", "Zambia" },
{ "ZW", "Zimbabwe" }
}
},
{ "%%EURO", "Euro" }, // Euro variant display name
{ "LocaleNamePatterns",
/* Formats for the display name of a locale, for a list of
* items, and for composing two items in a list into one item.
* The list patterns are used in the variant name and in the
* full display name.
*/
new String[] {
"{0,choice,0#|1#{1}|2#{1} ({2})}", // Display name
"{0,choice,0#|1#{1}|2#{1},{2}|3#{1},{2},{3}}", // List
"{0},{1}" // List composition
}
},
{ "MonthNames",
new String[] {
"January", // january
"February", // february
"March", // march
"April", // april
"May", // may
"June", // june
"July", // july
"August", // august
"September", // september
"October", // october
"November", // november
"December", // december
"" // month 13 if applicable
}
},
{ "MonthAbbreviations",
new String[] {
"Jan", // abb january
"Feb", // abb february
"Mar", // abb march
"Apr", // abb april
"May", // abb may
"Jun", // abb june
"Jul", // abb july
"Aug", // abb august
"Sep", // abb september
"Oct", // abb october
"Nov", // abb november
"Dec", // abb december
"" // abb month 13 if applicable
}
},
{ "DayNames",
new String[] {
"Sunday", // Sunday
"Monday", // Monday
"Tuesday", // Tuesday
"Wednesday", // Wednesday
"Thursday", // Thursday
"Friday", // Friday
"Saturday" // Saturday
}
},
{ "DayAbbreviations",
new String[] {
"Sun", // abb Sunday
"Mon", // abb Monday
"Tue", // abb Tuesday
"Wed", // abb Wednesday
"Thu", // abb Thursday
"Fri", // abb Friday
"Sat" // abb Saturday
}
},
{ "AmPmMarkers",
new String[] {
"AM", // am marker
"PM" // pm marker
}
},
{ "Eras",
new String[] { // era strings
"BC",
"AD"
}
},
{ "NumberPatterns",
new String[] {
"#,##0.###;-#,##0.###", // decimal pattern
"$#,##0.00;($#,##0.00)", // currency pattern
"#,##0%" // percent pattern
}
},
{ "NumberElements",
new String[] {
".", // decimal separator
",", // group (thousands) separator
";", // list separator
"%", // percent sign
"0", // native 0 digit
"#", // pattern digit
"-", // minus sign
"E", // exponential
"\u2030", // per mille
"\u221e", // infinity
"\ufffd" // NaN
}
},
{ "CurrencyElements",
new String[] {
"$", // local currency symbol
"USD", // intl currency symbol
"." // monetary decimal separator
}
},
{ "DateTimePatterns",
new String[] {
"h:mm:ss 'o''''clock' a z", // full time pattern
"h:mm:ss a z", // long time pattern
"h:mm:ss a", // medium time pattern
"h:mm a", // short time pattern
"EEEE, MMMM d, yyyy", // full date pattern
"MMMM d, yyyy", // long date pattern
"dd-MMM-yy", // medium date pattern
"M/d/yy", // short date pattern
"{1} {0}" // date-time pattern
}
},
{ "DateTimeElements",
new String[] {
"1", // first day of week
"1" // min days in first week
}
},
{ "CollationElements",new String[][]{
{"Version","1.0"},
{"Overide","false"},
{"Sequence",""}
}
},
{ "Measurement" ,""},
{ "CountryNumber" , ""},
{ "CountryISBNNumber" , ""},
{ "LanguageLibraryUse" , ""},
{ "PaperSize", new String[][]{
{"Hieght",""},
{"Width",""},
{"Units", ""}
}
},
{ "Messages" , new String[][] {
{"yesExpression",""}, /* yes expression */
{"noExpression",""} /* no expression */
}
},
{ "AddressFormat", new String[][]{
{"PostalFormat",""},
}
},
{"NameFormat", new String[][]{
{"NamePattern",""},
{"GeneralSalutaion", ""},
{"ShortSalutationMr", ""},
{"ShortSalutationMiss",""},
{"ShortSalutationMrs",""},
{"LongSalutationMr",""},
{"LongSalutationMiss",""},
{"LongSalutationMrs",""}
}
},
{ "Identification", new String[][]{
{"Title",""},
{"Source",""},
{"Address",""},
{"Contact",""},
{"Email",""},
{"Telephone", ""},
{"Fax", ""},
{"Language",""},
{"Territory",""},
{"Audience", ""},
{"Application", ""},
{"Abbreviation", ""},
{"Revision", ""},
{"Date",""}
}
},
{ "TelephoneFormat", new String[][]{
{"InternationalFormat",""},
{"DomesticFormat",""},
{"InternationalDialCode",""},
{"InternationalPrefix",""}
}
}
};
}
}

View file

@ -0,0 +1,93 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ArrayEnumeration.java,v $
* $Date: 2002/01/31 01:21:23 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.util.*;
public final class ArrayEnumeration implements Enumeration {
public ArrayEnumeration(Object[] array, int start, int limit) {
this.array = array;
position = start;
this.limit = limit;
}
public ArrayEnumeration(byte[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Byte(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(char[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Character(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(short[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Short(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(int[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Integer(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(float[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Float(array[i]);
}
position = start;
this.limit = limit;
}
public ArrayEnumeration(double[] array, int start, int limit) {
this.array = new Object[array.length];
for (int i = 0; i < array.length; ++i) {
this.array[i] = new Double(array[i]);
}
position = start;
this.limit = limit;
}
public boolean hasMoreElements() {
return position < limit;
}
public Object nextElement() {
if (position < limit)
return array[position++];
else
throw new java.util.NoSuchElementException();
}
// privates
private Object[] array;
private int position = 0;
private int limit = 0;
}

View file

@ -0,0 +1,95 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/CollationItem.java,v $
* $Date: 2002/01/31 01:21:23 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* A CollationItem represents a single entry in a collation sequence.
*/
public class CollationItem {
private static final char[] OP_CHARS = {'=', '<', ';', ',', '&' };
private static final char[] SPECIAL_CHARS = { '&', '@' , '=', '<', ';', ',' };
public static final int NONE = 0;
public static final int PRIMARY = 1;
public static final int SECONDARY = 2;
public static final int TERTIARY = 3;
private static final int FIRST = 4;
public int op;
public String item;
public String expansion;
public String comment;
public static final CollationItem FORWARD = new CollationItem(NONE, "") {
public String toString() { return ""; }
};
public static final CollationItem BACKWARD = new CollationItem(NONE, "") {
public String toString() { return "@"; }
};
public CollationItem(String item) {
this.op = FIRST;
this.item = cleanString(item);
this.expansion = "";
}
public CollationItem(int op, String item) {
this(op, item, null);
}
public CollationItem(int op, String item, String expansion) {
this.op = Math.abs(op);
if (this.op > TERTIARY) this.op = TERTIARY;
this.item = cleanString(item);
this.expansion = cleanString(expansion);
}
public void setComment(String comment) {
this.comment = comment;
}
public String toString() {
String itemString = item;
if (expansion.length() == 0) {
return ""+OP_CHARS[op]+item;
} else {
return "&"+expansion+OP_CHARS[op]+item;
}
}
private String cleanString(String source) {
if (source == null) return "";
String result = source;
for (int i = 0; i < result.length(); i++) {
final char c = result.charAt(i);
if ((c == '@') || (c == '\t') || (c == '\n')
|| (c == '\f') || (c =='\r') || (c == '\013')
|| ((c <= '\u002F') && (c >= '\u0020'))
|| ((c <= '\u003F') && (c >= '\u003A'))
|| ((c <= '\u0060') && (c >= '\u005B'))
|| ((c <= '\u007E') && (c >= '\u007B'))) {
if (i < result.length()-1) {
result = result.substring(0, i)
+ "'" + c +"'"
+ result.substring(i+1);
} else {
result = result.substring(0, i)
+ "'" + c +"'";
}
i += 2; //skip the two characters we inserted
}
}
return result;
}
}

View file

@ -0,0 +1,20 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/Comparable.java,v $
* $Date: 2002/01/31 01:21:24 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
public interface Comparable {
/**
returns 0 if objects are equal, -1 if a is less than b, 1 otherwise.
*/
public int compareTo(Object b);
}

View file

@ -0,0 +1,20 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/Comparator.java,v $
* $Date: 2002/01/31 01:21:27 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
public interface Comparator {
/**
returns 0 if objects are equal, -1 if a is less than b, 1 otherwise.
*/
public int compare(Object a, Object b);
}

View file

@ -0,0 +1,73 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ComplexTransition.java,v $
* $Date: 2002/01/31 01:21:27 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* A ComplexTransition is conceptually a single transition that
* consumes multiple input characters.
*/
public abstract class ComplexTransition implements Lex.Transition {
//the value that is returned by subclasses indicating that
//the transition was successfull. This value is then
//discarded and the value passed to the constructor
//is then returned to the caller.
protected static final int SUCCESS = Lex.END_OF_FILE - 1;
private int success; //value to return if successfull
private Lex parser; //the parser used for this transition
public ComplexTransition(int success) {
this.success = success;
this.parser = new Lex(null);
//this.parser.debug(true);
}
public int doAction(int c, PushbackReader input, StringBuffer buffer) throws IOException {
input.unread(c);
parser.setStates(getStates());
parser.setInput(input);
try {
int s = parser.nextToken();
handleSuccess(parser, buffer);
return success;
} catch (IOException e) {
handleFailure(parser, buffer);
throw e;
}
}
//called after a successful parse
protected void handleSuccess(Lex parser, StringBuffer output) throws IOException {
parser.appendDataTo(output);
}
//called after a failed parse
protected void handleFailure(Lex parser, StringBuffer output) {
}
//subclasses should return the states to use to parse this
//transition
protected abstract Lex.Transition[][] getStates();
public ComplexTransition debug(boolean debug) {
parser.debug(debug);
return this;
}
public ComplexTransition debug(boolean debug, String tag) {
parser.debug(debug, tag);
return this;
}
}

View file

@ -0,0 +1,88 @@
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
The ConvertJavaLocale application converts java locales to
Java and ICU Locale files. It's usage is as follows
ConvertJavaLocale [-11] [-12] [-icu] locale...
Usage
-11
If this option is specified, data is output in
Java 1.1.x locale format.
-12
If this option is specified, data is output in
Java 1.2.x locale format. If an output format
is not specified, -12 is the default.
-icu
If this option is specified, data is output in
ICU locale format.
locale
The locale to convert
*/
import java.lang.reflect.*;
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ConvertAllJavaLocales.java,v $
* $Date: 2002/01/31 01:21:28 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
public class ConvertAllJavaLocales {
public static void main(String args[]) {
try {
new ConvertAllJavaLocales(args);
} catch (Throwable t) {
System.err.println("Unknown error: "+t);
}
}
public ConvertAllJavaLocales(String argsIn[]) {
try {
String packageName = argsIn[0];
System.out.println("This is the packagename : "+packageName);
String classname = packageName+".Locale";
//classname.concat();
System.out.println("This is the classname : "+classname);
/* Class cl = Class.forName(classname);
Class[] paramList=null;
Method gvl = cl.getMethod("getAvailableLocales", paramList);
Object[] params = new Object[]{""};
gvl.invoke(null,params);*/
final Locale[] locales = java.util.Locale.getAvailableLocales();//(Locale[])gvl.invoke(null,params);;
for (int i = 0; i < locales.length; i++) {
final String localeName = locales[i].toString();
final String[] args = {"-package",packageName,"-icu", localeName};
System.out.println("Converting "+localeName);
final FileOutputStream outFile = new FileOutputStream("ICULocale_"+localeName);
final PrintStream out = new PrintStream(outFile, true);
new ConvertJavaLocale(args, out);
out.close();
}
} catch (IOException e) {
System.err.println("Unexpected IO error");
}catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,196 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ConvertJavaLocale.java,v $
* $Date: 2002/01/31 01:21:29 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
The ConvertJavaLocale application converts java locales to
Java and ICU Locale files. It's usage is as follows
ConvertJavaLocale [-11] [-12] [-icu] locale...
Usage
-11
If this option is specified, data is output in
Java 1.1.x locale format.
-12
If this option is specified, data is output in
Java 1.2.x locale format. If an output format
is not specified, -12 is the default.
-icu
If this option is specified, data is output in
ICU locale format.
locale
The locale to convert
*/
public class ConvertJavaLocale {
private static final byte OPT_11 = (byte)0x01;
private static final byte OPT_12 = (byte)0x02;
private static final byte OPT_ICU = (byte)0x04;
private static final byte OPT_PACKAGE = (byte)0x08;
private static final byte OPT_UNKNOWN = (byte)0x80;
private static final String USER_OPTIONS[] = {
"-11",
"-12",
"-icu",
"-package"
};
private static final String[] tags = {
"LocaleString",
"LocaleID",
"ShortLanguage",
"ShortCountry",
"Languages",
"Countries",
"MonthNames",
"MonthAbbreviations",
"DayNames",
"DayAbbreviations",
"AmPmMarkers",
"Eras",
"NumberPatterns",
"NumberElements",
"CurrencyElements",
"DateTimePatterns",
"DateTimeElements",
"CollationElements",
"zoneStrings",
"localPatternChars",
};
public static void main(String args[]) {
try {
new ConvertJavaLocale(args, System.out);
} catch (Throwable t) {
System.err.println("Unknown error: "+t);
}
}
public ConvertJavaLocale(String args[], PrintStream out) {
process(args, out);
}
public void process(String args[], PrintStream out) {
short options = identifyOptions(args);
if ((args.length < 1) || ((options & OPT_UNKNOWN) != 0)) {
printUsage();
} else {
String localeName = null;
String packagename = null;
for (int i = 0; i < args.length; i++) {
final String thisArg = args[i];
if(args[i].equalsIgnoreCase("-package")){
i++;
packagename = args[i];
}else if(args[i].equalsIgnoreCase("-icu")){
}else if (!args[i].startsWith("-")) {
localeName = args[i];
}
}
final Hashtable data = new Hashtable();
final String localeElements = packagename+".LocaleElements" +
(String)((localeName != null) ? "_"+localeName : "");
final String DateFormatZoneData = packagename+".DateFormatZoneData" +
(String)((localeName != null) ? "_"+localeName : "");
addLocaleData(localeElements, data);
addLocaleData(DateFormatZoneData, data);
final Locale locale = localeFromString(localeName);
if ((options & OPT_11) != 0) {
new Java1LocaleWriter(out, System.err).write(locale, data);
}
if ((options & OPT_12) != 0) {
new JavaLocaleWriter(out, System.err).write(locale, data);
}
if ((options & OPT_ICU) != 0) {
new ICULocaleWriter(out, System.err).write(locale, data);
}
}
}
private void addLocaleData(final String bundleClassName, final Hashtable data) {
try {
final Class bundleClass = Class.forName(bundleClassName);
final ResourceBundle bundle = (ResourceBundle)bundleClass.newInstance();
for (int i = 0; i < tags.length; i++) {
try {
final Object resource = bundle.getObject(tags[i]);
data.put(tags[i], resource);
} catch (MissingResourceException e) {
}
}
} catch (ClassNotFoundException e) {
System.err.println("Could not find bundle class for bundle: "+bundleClassName);
} catch (InstantiationException e) {
System.err.println("Could not create bundle instance for bundle: "+bundleClassName);
} catch (IllegalAccessException e) {
System.err.println("Could not create bundle instance for bundle: "+bundleClassName);
}
}
private void printUsage() {
System.err.println("Usage: ConvertJavaLocale [-11] [-12] [-icu] localeName");
}
private short identifyOptions(String[] options) {
short result = 0;
for (int j = 0; j < options.length; j++) {
String option = options[j];
if (option.startsWith("-")) {
boolean optionRecognized = false;
for (short i = 0; i < USER_OPTIONS.length; i++) {
if (USER_OPTIONS[i].equals(option)) {
result |= (short)(1 << i);
optionRecognized = true;
break;
}
}
if (!optionRecognized) {
result |= OPT_UNKNOWN;
}
}
}
return result;
}
private Locale localeFromString(final String localeName) {
if (localeName == null) return new Locale("", "", "");
String language = localeName;
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx+1);
country = country.substring(0, ndx);
}
return new Locale(language, country, variant);
}
}

View file

@ -0,0 +1,98 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ConvertLocaleTest.java,v $
* $Date: 2002/01/31 01:21:30 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/*
ConvertPOSIXLocale [-11] [-12] [-icu] [-icu2] localeDataFile [charMapFile ...]
*/
public class ConvertLocaleTest {
public static void main(String args[]) {
/*
ConvertPOSIXLocale.main( new String[] {
"-12",
"C:\\projects\\com\\taligent\\localeconverter\\collationTest.txt"
} );
ConvertPOSIXLocale.main( new String[] {
"-icu",
"C:\\projects\\com\\taligent\\localeconverter\\collationTest2.txt",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
} );
ConvertPOSIXLocale.main( new String[] {
"-icu", "-LC_MESSAGES",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\Vivnx43.ibm",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ibm1129-2-UniCode.chm",
} );
/* ConvertPOSIXLocale.main( new String[] {
"-12",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\en_US",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
/* ConvertPOSIXLocale.main( new String[] {
"-12",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fi_FI",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
ConvertPOSIXLocale.main( new String[] {
"-12", "en_BE",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\ENBEWIN.IBM",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\Ibm1252.chm",
});
ConvertPOSIXLocale.main( new String[] {
"-12", "vi_VN",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\Vivnx43.ibm",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ibm1129-2-UniCode.chm",
});
ConvertPOSIXLocale.main( new String[] {
"-icu", "fr_FR",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fr_FR",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
ConvertPOSIXLocale.main( new String[] {
"-icu", "fo_FO",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fo_FO",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
*/
ConvertPOSIXLocale.main( new String[] {
"-icu", "fr_LU",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\fr_LU",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
/*
ConvertPOSIXLocale.main( new String[] {
"-icu", "de_LU",
"C:\\projects\\com\\taligent\\localeconverter\\Locales\\POSIXLocales\\de_LU",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\ISO-8859-1",
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps\\mnemonic.ds",
});
*/
}
}

View file

@ -0,0 +1,349 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ConvertPOSIXLocale.java,v $
* $Date: 2002/01/31 01:21:31 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
The ConvertPOSIXLocale application converts POSIX locale files to
Java and ICU Locale files. It's usage is as follows
ConvertPOSIXLocale
[-LC_CTYPE]
[-LC_TIME]
[-LC_NUMERIC]
[-LC_MONETARY]
[-LC_MESSAGES]
[-11]
[-12]
[-icu]
[-icu2]
localeName
localeDataFile
[charMapFile ...]
The application is invoked with options specifying the format(s) of
the locale file(s) to generate as well as the POSIX locale file and
character mapping files.
Usage
-LC_CTYPE
If the -LC_CTYPE option is specified, the
following items are added to the locale if they
are present in the source: upper, lower, alpha, digit,
space, cntrl, punct, graph, print, xdigit, blank,
toupper, tolower.
<CODE>-LC_TIME
If the -LC_TIME option is specified, the following
items will be included if they are present in the POSIX source:
abday, day, abmon, mon, d_t_fmt, d_ftm, t_fmt, am_pm,
t_fmt_ampm, era, era_year, era_d_fmt, alt_digits.
-LC_NUMERIC
If the -LC_NUMERIC option is specified, the following
items will be included if they are present in the source:
decimal_point, thousands_sep, grouping
-LC_MONETARY
If the -LC_MONETARY option is specified, the following
items will be included if they are present in the source:
int_curr_symbol, currency_symbol, mon_decimal_point,
mon_thousands_sep, mon_grouping, positive_sign,
negative_sign, int_frac_digits, frac_digits, p_cs_precedes,
p_sep_by_space, n_cs_precedes, n_sep_by_space, p_sign_posn.
-LC_MESSAGES
If the -LC_MESSAGES option is specified, the
following items are added to the locale if they
are present in the source: yesexpr, noexpr
-11
If this option is specified, data is output in
Java 1.1.x locale format.
-12
If this option is specified, data is output in
Java 1.2.x locale format. If an output format
is not specified, -12 is the default.
-icu
If this option is specified, data is output in
ICU locale format.
localeName
The name of the locale in the localeDataFile. Ex. en_US.
localeDataFile
The localeDataFile path is required and specifies the path
to the locale data file. If a "copy" directive is encountered
while processing the localeDataFile, ConvertPOSIXLocale will look
in the same directory as the localeDataFile for additional
POSIX locale data files. Files must be in the POSIX format
specified in ISO/IEC 9945- with exceptions noted below. Exactly
one localeDataFile must be specified.
charMapFile
Zero or more character mapping files may be specified. charMapFiles are used
to map symbols in the localeDataFile to Unicode values. They are processed
as follows. ConvertPOSIXLocale searchs for a line containing only the
word "CHARMAP" and reads symbol mappings until it reaches a line
containing only the words "END CHARMAP". Symbol mappings have
the form "<SYMBOL> <Uhhhh>" where "<SYMBOL>" is any symbol valid
in a localeDataFile and "hhhh" is four hexidecimal digits representing
the Unicode value for that symbol. Surrogate pairs are not supported
in charMapFiles. An example charMapFile might contain the following:
CHARMAP
<START_OF_TEXT> <U0002>
<E> <U0045>
<q> <U0071>
END CHARMAP
specifying that the symbol <START_OF_TEXT> should be replaced by
the Unicode value of 0x0002 wherever it occurs.
When multiple charMapFiles are specified, mappings in files listed
later take precedence over earlier ones.
Conversion to ICU and Java:
CollationElements
Converted from the LC_COLLATE section. The "..." directive is ignored.
The "replace-after" directive is ignored.
CurrencyElements
element 0 is set to currency_symbol
element 1 is set to int_curr_symbol
element 2 is set to mon_decimal_point
All other elements default.
NumberElements
element 0 is set to decimal_point
element 1 is set to thousands_sep
MonthNames is set to mon
MonthAbbreviations is set to abmon
DayNames is set to day
DayAbbreviations is set to abday
AmPmMarkers is set to am_pm
DateTimePatterns
elements 0 through 3 are set to t_fmt_ampm with the patterns converted
elements 4 through 7 are set to d_fmt with the patterns converted
Adition POSIX data may be included in the Locale as follows:
LC_TYPE
This section is ignored unless the -LC_CTYPE option is
specified. If the -LC_CTYPE option is specified, the
following items are added to the locale if they
are present in the source: upper, lower, alpha, digit,
space, cntrl, punct, graph, print, xdigit, blank,
toupper, tolower.
LC_MESSAGES
LC_MONETARY
LC_NUMERIC
LC_TIME
If the -LC_TIME option is specified, the following
items will be included if they are present in the source:
abday, day, abmon, mon, d_t_fmt, d_ftm, t_fmt, am_pm,
t_fmt_ampm, era, era_year, era_d_fmt, alt_digits.
LC_COLLATE
Converted to CollationElements in the resource file.
*/
public class ConvertPOSIXLocale {
private static final short OPT_LC_CTYPE = 0x001;
private static final short OPT_LC_TIME = 0x002;
private static final short OPT_LC_NUMERIC = 0x004;
private static final short OPT_LC_MONETARY = 0x008;
private static final short OPT_LC_MESSAGES = 0x010;
private static final short OPT_11 = 0x020;
private static final short OPT_12 = 0x040;
private static final short OPT_ICU = 0x080;
private static final short OPT_ICU2 = 0x100;
private static final short OPT_RAW = 0x200;
private static final short OPT_UNKNOWN = 0x4000;
private static final String USER_OPTIONS[] = {
"-LC_CTYPE",
"-LC_TIME",
"-LC_NUMERIC",
"-LC_MONETARY",
"-LC_MESSAGES",
"-11",
"-12",
"-icu",
"-icu2",
"-RAW",
"-enc",
};
private static final short OPT_CONVERT = (short)(OPT_LC_CTYPE | OPT_LC_TIME
| OPT_LC_NUMERIC | OPT_LC_MONETARY | OPT_LC_MESSAGES);
private Hashtable data;
public static void main(String args[]) {
try {
new ConvertPOSIXLocale(args);
} catch (Throwable t) {
t.printStackTrace();
System.err.println("Unknown error: "+t);
}
}
public ConvertPOSIXLocale(String args[]) {
process(args);
//{{INIT_CONTROLS
//}}
}
public void process(String args[]) {
short options = identifyOptions(args);
String enc="";
if ((args.length < 2) || ((options & OPT_UNKNOWN) != 0)) {
printUsage();
} else {
Vector mapFiles = new Vector();
Locale locale = null;
String fileName = null;
for (int i = 0; i < args.length; i++) {
final String thisArg = args[i];
if (thisArg.startsWith("-")) {
if(thisArg.startsWith("-enc")){
enc = args[++i];
}
} else if (locale == null) {
locale = localeFromString(thisArg);
} else if (fileName == null) {
fileName = thisArg;
} else {
mapFiles.addElement(thisArg);
}
}
if ((fileName == null) || (locale == null) || (options == 0)) {
printUsage();
} else {
PosixCharMap map = new PosixCharMap();
Enumeration enum = mapFiles.elements();
while (enum.hasMoreElements()) {
String mapFile = (String)enum.nextElement();
System.err.println("Locale: "+locale);
System.err.println("Loading character map file: "+mapFile);
try {
map.load(new File(mapFile),enc);
} catch (IOException e) {
System.err.println("Error loading map file: "+mapFile+" "+e);
System.err.println("File skipped");
}
}
SymbolTransition.setCharMap(map);
File dataFile = new File(fileName);
System.err.println("Locale directory: "+dataFile.getParent());
POSIXLocaleReader reader = new POSIXLocaleReader(dataFile.getParent(), locale);
System.err.println("Parsing file: "+dataFile.getName());
try {
data = reader.parse(dataFile.getName(), (byte)(options & OPT_CONVERT));
System.err.println("Converting....");
if ((options & OPT_11) != 0) {
new Java1LocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_12) != 0) {
new JavaLocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_ICU) != 0) {
new ICULocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_ICU2) != 0) {
new ICU2LocaleWriter(System.out, System.err).write(locale, data);
}
if ((options & OPT_RAW) != 0) {
new ICULocaleWriter(System.out, System.err).write(locale, data);
}
} catch (IOException e) {
System.err.println(e);
}
}
}
}
private void printUsage() {
System.err.println("Usage: ConvertPOSIXLocale [-LC_CTYPE] [-LC_TIME]"+
" [-LC_NUMERIC] [-LC_MONETARY] [-LC_MESSAGES] [-11] [-12] [-icu]"+
" localeName localeDataFile [charMapFile ...]");
}
private short identifyOptions(String[] options) {
short result = 0;
for (int j = 0; j < options.length; j++) {
String option = options[j];
if (option.startsWith("-")) {
boolean optionRecognized = false;
for (short i = 0; i < USER_OPTIONS.length; i++) {
if (USER_OPTIONS[i].equals(option)) {
result |= (short)(1 << i);
optionRecognized = true;
break;
}
}
if (!optionRecognized) {
result |= OPT_UNKNOWN;
}
}
}
return result;
}
private Locale localeFromString(final String localeName) {
String language = localeName;
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx+1);
country = country.substring(0, ndx);
}
ndx = country.indexOf('@');
if(ndx>0){
variant = country.substring(ndx+1);
country = country.substring(0,ndx);
}
return new Locale(language, country, variant);
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,113 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/EOLTransition.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* This transition parses an end-of-line sequence. The comment character
* can be set to an arbitrary character, but it is shared globally.
* A comment may only occur after an end-of-line.
* EOL := <EOF> | <EOL_CHARS> [ <EOL_SEGMENT> ]*
* EOL_SEGMENT := <EOL_CHARS> | <SPACE_CHARS> | <COMMENT>
* SPACE_CHARS := " \t";
* EOL_CHARS = "\r\n\u2028\u2029";
* COMMENT_STRING := <COMMENT_CHAR> <COMMENT_BODY>
* COMMENT_CHAR = "#";
* COMMENT_BODY = [ ~<EOF> & ~<EOL_CHARS> ]*
*/
public class EOLTransition extends ComplexTransition {
public static final String EOL_CHARS = "\r\n\u2028\u2029";
public static final char DEFAULT_COMMENT_CHAR = '#';
public static char COMMENT_CHAR = DEFAULT_COMMENT_CHAR;
public static final EOLTransition GLOBAL = new EOLTransition(SUCCESS);
/** Restore the comment character to the default value */
public static synchronized char setDefaultCommentChar() {
return setCommentChar(DEFAULT_COMMENT_CHAR);
}
/** Set a new comment character */
public static synchronized char setCommentChar(char c) {
char result = COMMENT_CHAR;
COMMENT_CHAR = c;
states = null; //flush states
return result;
}
public EOLTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return EOL_CHARS.indexOf((char)c) >= 0;
}
protected Lex.Transition[][] getStates() {
synchronized (getClass()) {
if (states == null) {
//cache the states so they can be shared. This states
//need to be flushed and rebuilt when the comment
//character changes.
states = new Lex.Transition[][] {
{ //state 0:
new Lex.StringTransition(EOL_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.EOFTransition(SUCCESS),
new Lex.ParseExceptionTransition("bad characters in EOL")
},
{ //state 1:
new Lex.CharTransition(COMMENT_CHAR, Lex.IGNORE_CONSUME, -2),
new Lex.StringTransition(EOL_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.StringTransition(SpaceTransition.SPACE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.EOFTransition(SUCCESS),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, SUCCESS)
},
{ //state 2:
new Lex.StringTransition(EOL_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.EOFTransition(SUCCESS),
new Lex.DefaultTransition(Lex.IGNORE_CONSUME, -2)
}
};
}
}
return states;
}
private static Lex.Transition[][] states;
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new EOLTransition(SUCCESS).debug(true),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
String text = "\n\r\n# Hello World\n\r\n\n\n\r\r\n#hello kdsj\n";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
parser.debug(true);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
//System.out.println(parser.getData());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,152 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/EscapeTransition.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* An escape transition parses a POSIX escape sequence. An escape
* sequence can be a hex, octal, or decimal constant, or an escaped
* character. The resultant value is ALWAYS on byte long. Longer
* escaped values (ie.\xFF63) overflow and are truncated. An escape
* character followed by an EOL sequence is silently eaten.
*/
public class EscapeTransition extends ComplexTransition {
public static final EscapeTransition GLOBAL = new EscapeTransition(SUCCESS);
public static final char DEFAULT_ESCAPE_CHAR = '\\';
public static char ESCAPE_CHAR = DEFAULT_ESCAPE_CHAR;
private static final int DECIMAL = 1; //decimal escape sequence was parsed
private static final int OCTAL = 2; //octal escape sequence was parsed
private static final int HEX = 3; //hex escape sequence was parsed
private static final int ESCAPE = 4; //character escape sequence was parsed
private static final int EOL = 5; //an escape character followed by EOF eaten
private static final String OCTAL_CHARS = "01234567";
private static final String DECIMAL_CHARS = "0123456789";
private static final String HEX_CHARS = "0123456789abcdefABCDEF";
/** Set the escape character to the default */
public static synchronized char setDefaultEscapeChar() {
return setEscapeChar(DEFAULT_ESCAPE_CHAR);
}
/** Set the escape character */
public static synchronized char setEscapeChar(char c) {
char result = ESCAPE_CHAR;
ESCAPE_CHAR = c;
theStates = null;
return result;
}
public EscapeTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return ESCAPE_CHAR == (char)c;
}
/** Convert the accepted text into the appropriate unicode character */
protected void handleSuccess(Lex parser, StringBuffer output) throws IOException {
switch (parser.getState()) {
case DECIMAL:
output.append((char)parser.dataAsNumber(10));
break;
case OCTAL:
output.append((char)parser.dataAsNumber(8));
break;
case HEX:
output.append((char)parser.dataAsNumber(16));
break;
case ESCAPE:
parser.appendDataTo(output);
break;
case EOL:
//silently eat the EOL characters
break;
default:
//should never get here
throw new Lex.ParseException("Internal error parsing escape sequence");
// parser.appendDataTo(output);
}
}
/** return the states for this transaction */
protected Lex.Transition[][] getStates() {
synchronized (getClass()) {
if (theStates == null) {
//cache the states so they can be shared. They must
//be rebuilt when the escape character is changed.
theStates = new Lex.Transition[][] {
{ //state 0:
new Lex.CharTransition(ESCAPE_CHAR, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal escape character")
},
{ //state 1:
new Lex.EOFTransition(OCTAL),
new Lex.CharTransition('d', Lex.IGNORE_CONSUME, -3),
new Lex.CharTransition('x', Lex.IGNORE_CONSUME, -2),
new Lex.StringTransition(OCTAL_CHARS, Lex.ACCUMULATE_CONSUME, -4),
new Lex.CharTransition(ESCAPE_CHAR, Lex.ACCUMULATE_CONSUME, ESCAPE),
new EOLTransition(EOL),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, ESCAPE)
},
{ //state 2: hex
new Lex.EOFTransition(HEX),
new Lex.StringTransition(HEX_CHARS, Lex.ACCUMULATE_CONSUME, -2),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, HEX)
},
{ //state 3: decimal
new Lex.EOFTransition(DECIMAL),
new Lex.StringTransition(DECIMAL_CHARS, Lex.ACCUMULATE_CONSUME, -3),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, DECIMAL)
},
{ //state 4: octal
new Lex.EOFTransition(OCTAL),
new Lex.StringTransition(OCTAL_CHARS, Lex.ACCUMULATE_CONSUME, -4),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, OCTAL)
},
};
}
}
return theStates;
}
private static Lex.Transition[][] theStates = null;
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new EscapeTransition(SUCCESS),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
String text = "\\d100\\xAf\\\\\\777\\\n\\123\\x2028\\x2029";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
System.out.println(parser.getState());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,122 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ICU2LocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class ICU2LocaleWriter extends LocaleWriter {
public ICU2LocaleWriter(PrintStream out) {
super(out);
//{{INIT_CONTROLS
//}}
}
public ICU2LocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
protected void open(Locale locale) {
print(locale.toString());
println(" {");
indent();
}
protected void write(String tag, String value) {
print(tag);
print(" { ");
printString(value);
println(" }");
}
protected void write(String tag, String[] value) {
if (tag != null) {
print(tag);
println(" { ");
} else {
println("{");
}
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
}
protected void write(String tag, Object o) {
if ("CollationElements".equals(tag)) {
writeTagged(tag,(Object[][])o);
} else if (!(o instanceof CollationItem[])) {
super.write(tag, o);
} else {
CollationItem[] items = (CollationItem[])o;
print("CollationElements");
println(" { ");
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
printString(items[i].toString());
if (items[i].comment != null) {
tabTo(30);
print("//");
println(items[i].comment);
}
}
}
}
}
protected void writeTagged(String tag, Object[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write((String)value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void write2D(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(null, value[i]);
}
outdent();
println("}");
}
protected void writeTagged(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void close() {
outdent();
println("}");
}
protected String getStringJoiningCharacter() {
return "";
}
protected boolean isEscapeChar(final char c) {
return true;
}
protected String getEscapeChar() {
return "%u";
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,115 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/ICULocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class ICULocaleWriter extends LocaleWriter {
public ICULocaleWriter(PrintStream out) {
super(out);
}
public ICULocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
protected void open(Locale locale) {
print(locale.toString());
println(" {");
indent();
}
protected void write(String tag, Object o) {
if ("CollationElements".equals(tag)) {
if(o instanceof Object[][]){
writeTagged(tag,(Object[][])o);
}else{
write(tag,(String)o);
}
} else if (!(o instanceof CollationItem[])) {
super.write(tag, o);
} else {
CollationItem[] items = (CollationItem[])o;
print("CollationElements");
println(" { ");
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
printString(items[i].toString());
if (items[i].comment != null) {
tabTo(30);
print("//");
println(items[i].comment);
}
}
}
}
}
protected void write(String tag, String value) {
print(tag);
print(" { ");
printString(value);
println(" }");
}
protected void write(String tag, String[] value) {
if (tag != null) {
print(tag);
println(" { ");
} else {
println("{");
}
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
}
protected void write2D(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(null, value[i]);
}
outdent();
println("}");
}
protected void writeTagged(String tag, Object[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write((String)value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void writeTagged(String tag, String[][] value) {
print(tag);
println(" { ");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
}
protected void close() {
outdent();
println("}");
super.closeFileHandle();
}
protected String getStringJoiningCharacter() {
return "";
}
}

View file

@ -0,0 +1,147 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/Java1LocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class Java1LocaleWriter extends LocaleWriter {
public Java1LocaleWriter(PrintStream out) {
super(out);
//{{INIT_CONTROLS
//}}
}
public Java1LocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
public void write(Locale locale, Hashtable localeData) {
try {
Hashtable temp = new NeutralToJ1Converter(locale).convert(localeData);
super.write(locale, temp);
} catch (LocaleConverter.ConversionError e) {
err.println(e);
}
}
protected void open(Locale locale) {
print(HEADER1);
print(locale.toString());
print(HEADER2);
print(locale.toString());
println(HEADER3);
indent(3);
}
protected void write(String tag, String value) {
print("{ ");
printString(tag);
print(", ");
printString(value);
println(" },");
}
protected void write(String tag, String[] value) {
print("{ ");
if (tag != null) {
printString(tag);
println(",");
} else {
println("");
}
indent();
println("new String[] {");
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
outdent();
println("},");
}
protected void write2D(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
println("{");
indent();
for (int j = 0; j < value[i].length; j++) {
printString(value[i][j]);
println(",");
}
outdent();
println("},");
}
outdent();
println("}");
outdent();
println("},");
}
protected void writeTagged(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
outdent();
println("},");
}
protected void close() {
outdent(3);
print(FOOTER);
}
protected void appendEscapedChar(char c, StringBuffer buffer) {
if (c < '\u0020' || c == '"' || c == '\\') {
buffer.append('\\');
buffer.append(HEX_DIGIT[(c & 0700) >> 6]); // HEX_DIGIT works for octal
buffer.append(HEX_DIGIT[(c & 0070) >> 3]);
buffer.append(HEX_DIGIT[(c & 0007)]);
} else {
super.appendEscapedChar(c, buffer);
}
}
protected String getStringJoiningCharacter() {
return "+";
}
private static final String HEADER1 =
"package java.text.resources;\n"+
"public class LocaleElements_";
private static final String HEADER2 =
" extends LocaleData {\n"+
" public LocaleElements_";
private static final String HEADER3 =
"() {\n"+
" super.init(table);\n"+
" }\n"+
" static String table []=";
private static final String FOOTER =
" }\n"+
"}";
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,170 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/JavaLocaleWriter.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class JavaLocaleWriter extends LocaleWriter {
public JavaLocaleWriter(PrintStream out) {
super(out);
}
public JavaLocaleWriter(PrintStream out, PrintStream err) {
super(out, err);
}
public void open(Locale locale) {
println(HEADER);
indent(3);
}
protected void write(String tag, Object o) {
if ("CollationElements".equals(tag)) {
writeTagged(tag,(Object[][])o);
} else if (!(o instanceof CollationItem[])) {
super.write(tag, o);
} else {
CollationItem[] items = (CollationItem[])o;
print("{ ");
printString("CollationElements");
println(", ");
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
printString(items[i].toString());
if (items[i].comment != null) {
print("+");
tabTo(30);
print("//");
println(items[i].comment);
} else {
println("+");
}
}
}
println("\"\"");
println(" },");
}
}
public void write(String tag, String value) {
print("{ ");
printString(tag);
print(", ");
printString(value);
println(" },");
}
public void write(String tag, String[] value) {
print("{ ");
if (tag != null) {
printString(tag);
println(",");
} else {
println("");
}
indent();
println("new String[] {");
indent();
for (int i = 0; i < value.length; i++) {
printString(value[i]);
println(",");
}
outdent();
println("}");
outdent();
println("},");
}
public void write2D(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
println("{");
indent();
for (int j = 0; j < value[i].length; j++) {
printString(value[i][j]);
println(",");
}
outdent();
println("},");
}
outdent();
println("}");
outdent();
println("},");
}
public void writeTagged(String tag, String[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
write(value[i][0], value[i][1]);
}
outdent();
println("}");
outdent();
println("},");
}
public void writeTagged(String tag, Object[][] value) {
print("{ ");
printString(tag);
println(",");
indent();
println("new String[][] {");
indent();
for (int i = 0; i < value.length; i++) {
write((String)value[i][0], value[i][1]);
}
outdent();
println("}");
outdent();
println("},");
}
public void close() {
outdent(3);
print(FOOTER);
println("");
}
protected void appendEscapedChar(char c, StringBuffer buffer) {
if (c < '\u0020' || c == '"' || c == '\\') {
buffer.append('\\');
buffer.append(HEX_DIGIT[(c & 0700) >> 6]); // HEX_DIGIT works for octal
buffer.append(HEX_DIGIT[(c & 0070) >> 3]);
buffer.append(HEX_DIGIT[(c & 0007)]);
} else {
super.appendEscapedChar(c, buffer);
}
}
protected String getStringJoiningCharacter() {
return "+";
}
private static final String HEADER =
"package java.text.resources;\n"+
"import java.util.ListResourceBundle;\n"+
"public class TestLocaleElements extends ListResourceBundle {\n"+
" public Object[][] getContents() {\n"+
" return new Object[][] {";
private static final String FOOTER =
" };\n"+
" }\n"+
"}";
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,416 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/Lex.java,v $
* $Date: 2002/01/31 01:21:32 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
/**
* A Lex is a state machine. Transitions can be activated
* arbitrarily and can consume arbitrary amounts of text.
* A transition simply says it can consume the next character
* and returns the state that the machine should transition into.
* States that are > 0 are final states and cause the nextToken
* routine to return a value.
*/
public final class Lex {
private Transition[][] states; //final
private PushbackReader input; //final
private int state;
private String data;
private final StringBuffer dataBuffer = new StringBuffer();
private boolean debugMessagesOn;
private String debugTag;
public static final int END_OF_FILE = Integer.MAX_VALUE;
/** Construct a new machine. NOTE: setInput must be
* called before nextToken is called */
public Lex(final Transition[][] states) {
this.states = states;
//{{INIT_CONTROLS
//}}
}
/** Construct a new machine. */
public Lex(final Transition[][] statesIn, final PushbackReader inputIn) {
states = statesIn;
input = inputIn;
}
/** Return the current state */
public int getState() {
return state;
}
/** Return the data resulting from the last call to nextToken */
public String getData() {
if (data == null) {
data = dataBuffer.toString();
}
return data;
}
/** Return the input reader used by this machine */
public PushbackReader getInput() {
return input;
}
/** set the input reader used by this machine */
public void setInput(PushbackReader input) {
this.input = input;
}
/** Return the states used by this machine */
public Transition[][] getStates() {
return states;
}
public void setStates(Transition[][] states) {
this.states = states;
}
/** Return true if the specified string equals the
* string returned by getData(). This routine
* may be faster than calling getData because
* it does not create a string on the heap.
*/
public boolean dataEquals(final String other) {
if (data != null) {
//if dataBuffer has already been converted to
//a string, just compare the strings.
return data.equals(other);
} else {
if (other.length() != dataBuffer.length()) return false;
final int len = dataBuffer.length();
for (int i = 0; i < len; i++) {
if (other.charAt(i) != dataBuffer.charAt(i)) {
return false;
}
}
return true;
}
}
/**
* Append the data returned from getData() to the
* specified StringBuffer. This routine avoids
* the creation of a String on the heap.
*/
public void appendDataTo(StringBuffer buffer) {
buffer.append(dataBuffer);
}
/**
* Return true if the data returned by getData()
* starts with the specified string. This routine avoids
* the creation of a String on the heap.
*/
public boolean dataStartsWith(String s) {
if (dataBuffer.length() < s.length()) {
return false;
} else {
final int sLength = s.length();
for (int i = 0; i < sLength; i++) {
if (dataBuffer.charAt(i) != s.charAt(i)) {
return false;
}
}
return true;
}
}
/**
* Convert the contents of the data buffer to an integer
* of the specified radix
*/
public int dataAsNumber(int radix) {
int value = 0;
final int len = dataBuffer.length();
for (int i = 0; i < len; i++) {
value = value*radix + Character.digit(dataBuffer.charAt(i), radix);
}
return value;
}
/**
* Get the next token from the input stream. The
* dataBuffer is cleared and the state is set to zero before
* parsing begins. Parsing continues until a state
* greater of equal to 0 s reached or an exception is thrown.
* After each non-terminal transition, the state machine
* walks through all the transitions, in order, for the current
* state until it finds one that will accept the current
* input character and then calls doAction on that transition.
*/
public int nextToken() throws IOException {
state = 0;
dataBuffer.setLength(0);
do {
int c = input.read();
final Transition[] transition = states[-state];
for (int i = 0; i < transition.length; i++) {
if (transition[i].accepts(c)) {
//System.out.println("state["+ -state+"].transition["+i+"] on "+c+" '"+(char)c+"' to state[");
state = transition[i].doAction(c, input, dataBuffer);
//println("" + -state + "]");
break;
}
}
} while (state <= 0);
data = null; //dump the cached data string
return state;
}
/**
* Get the next token and throw an acception if
* the state machine is not in the specified state.
*/
public void accept(final int neededState) throws IOException {
if (neededState != nextToken()) {
throw new ParseException("Unexpected token - "+getData());
}
}
/**
* Get the next token and throw an exception if the
* state machine is not in the specified state and the
* value returned by getData() does not match the
* specified value.
*/
public void accept(final int neededState, final String neededValue) throws IOException {
accept(neededState);
if (!dataEquals(neededValue)) {
throw new ParseException("Unexpected token - "+getData());
}
}
public void debug(boolean debugMessagesOn) {
this.debugMessagesOn = debugMessagesOn;
debugTag = null;
}
public void debug(boolean debugMessagesOn, String tag) {
this.debugMessagesOn = debugMessagesOn;
this.debugTag = tag;
}
/* private void print(String s) {
if (debugMessagesOn) {
System.out.print(s);
}
}
private void println(String s) {
if (debugMessagesOn) {
System.out.println(s+" <"+debugTag);
}
}
/**
* The interface for state machine transitions.
*/
public interface Transition {
/**
* Return true if the transition can accept the current input
* character.
*/
public boolean accepts(int c);
/**
* Perform the transition.
* @param c the current input character
* @param input the current input stream, minus the current input character
* @param buffer the current output buffer
* @return the state the machine should be in next
*/
public int doAction(int c, PushbackReader input, StringBuffer buffer) throws IOException;
}
/* constants for BaseTransitions */
/** Don't copy the current character to the output */
public static final byte IGNORE = 0x01;
/** Append the current character to the output */
public static final byte ACCUMULATE = 0x00;
private static final byte BUFFER_MASK = 0x01;
/** Remove the current character from the input stream */
public static final byte CONSUME = 0x00;
/** Return the current character to the input stream */
public static final byte PUTBACK = 0x10;
private static final byte INPUT_MASK = 0x10;
public static final byte
ACCUMULATE_CONSUME = (byte)(ACCUMULATE | CONSUME),
IGNORE_CONSUME = (byte)(IGNORE | CONSUME),
ACCUMULATE_PUTBACK = (byte)(ACCUMULATE | PUTBACK),
IGNORE_PUTBACK = (byte)(IGNORE | PUTBACK);
/**
* Base class for simple transition classes
*/
public static abstract class BaseTransition implements Transition {
private final boolean addToBuffer;
private final boolean unreadInput;
private final int next;
/**
* Construct a new transition. On execution, the
* specified action is performed and the
* specified state is returned.
* @param action the actions to perform to the
* input and output buffers.
* @param next the next state the machine should
* move into
*/
public BaseTransition(byte action, int next) {
this.addToBuffer = (action & BUFFER_MASK) == ACCUMULATE;
this.unreadInput = (action & INPUT_MASK) == PUTBACK;
this.next = next;
}
public abstract boolean accepts(int c);
public int doAction(final int c,
final PushbackReader input,
final StringBuffer buffer) throws IOException {
if (addToBuffer) {
buffer.append((char)c);
}
if (unreadInput) {
input.unread(c);
}
return next;
}
}
/**
* Accept end-of-file.
*/
public static final class EOFTransition extends BaseTransition {
public EOFTransition() {
this(IGNORE_CONSUME, END_OF_FILE);
}
public EOFTransition(int next) {
this(IGNORE_CONSUME, next);
}
public EOFTransition(byte action, int next) {
super(action, next);
}
public boolean accepts(int c) {
return c == -1;
}
}
/**
* Accept anything.
*/
public static final class DefaultTransition extends BaseTransition {
public DefaultTransition(byte action, int nextState) {
super(action, nextState);
}
public boolean accepts(int c) {
return true;
}
}
/**
* Accept any characters in the specified string.
*/
public static final class StringTransition extends BaseTransition {
private String chars;
public StringTransition(String chars, byte action, int nextState) {
super(action, nextState);
this.chars = chars;
}
public boolean accepts(int c) {
return chars.indexOf((char)c) != -1;
}
}
/**
* Accept only the specified character.
*/
public static final class CharTransition extends BaseTransition {
private char c;
public CharTransition(char c, byte action, int nextState) {
super(action, nextState);
this.c = c;
}
public boolean accepts(int c) {
return this.c == (char)c;
}
}
/**
* Accept anything, but throw the specified exception after
* performing the specified action
*/
public static final class ExceptionTransition extends BaseTransition {
private IOException e;
public ExceptionTransition(IOException e) {
super(IGNORE_PUTBACK, END_OF_FILE); //state is ignored
}
public ExceptionTransition(byte action, IOException e) {
super(action, END_OF_FILE); //state is ignored
}
public boolean accepts(int c) {
return true;
}
public final int doAction(final int c,
final PushbackReader input,
final StringBuffer buffer) throws IOException {
super.doAction(c, input, buffer);
throw e;
}
}
/**
* The base class for parse exceptions. Exceptions
* resulting from parsing errors should be subclasses of this
* class.
*/
public static final class ParseException extends IOException {
public final String reason;
public ParseException() {
this.reason = "unkown";
}
public ParseException(String reason) {
this.reason = reason;
}
public String toString() {
return reason;
}
}
/**
* Accept anything, execute as IGNORE_PUTBACK, and throw
* a ParseException with the specified message
*/
public static final class ParseExceptionTransition implements Transition {
private String reason;
public ParseExceptionTransition(String reason) {
this.reason = reason;
}
public boolean accepts(int c) {
return true;
}
public final int doAction(final int c,
final PushbackReader input,
final StringBuffer buffer) throws IOException {
input.unread((char)c);
throw new ParseException(reason);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,146 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/LineCharNumberReader.java,v $
* $Date: 2002/01/31 01:21:33 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
/**
* A LineCharNumberReader is a BufferedReader that
* keeps track of the line number and character offset
* on that line of the current input stream.
*/
public class LineCharNumberReader extends BufferedReader {
private int lineNumber = 0;
private int charNumber = 0;
private int markedLineNumber;
private int markedCharNumber;
private boolean skipLF;
public LineCharNumberReader(Reader in) {
super(in);
//{{INIT_CONTROLS
//}}
}
public LineCharNumberReader(Reader in, int sz) {
super(in, sz);
}
public int getLineNumber() {
return lineNumber;
}
public int getCharNumber() {
return charNumber;
}
public int read() throws IOException {
synchronized (lock) {
int c = super.read();
charNumber++;
if (skipLF) {
if (c == '\n') c = super.read();
skipLF = false;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
case '\u2028': /* Fall through */
case '\u2029': /* Fall through */
lineNumber++;
charNumber = 0;
return '\n';
}
return c;
}
}
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
int n = super.read(cbuf, off, len);
for (int i = off; i < off + len; i++) {
int c = cbuf[i];
charNumber++;
if (skipLF) {
skipLF = false;
if (c == '\n')
continue;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
case '\u2028': /* Fall through */
case '\u2029': /* Fall through */
lineNumber++;
charNumber = 0;
break;
}
}
return n;
}
}
public String readLine() throws IOException {
synchronized (lock) {
String l = super.readLine();
if (l != null)
lineNumber++;
charNumber = 0;
skipLF = false;
return l;
}
}
private static final int maxSkipBufferSize = 8192;
private char skipBuffer[] = null;
public long skip(long n) throws IOException {
int nn = (int) Math.min(n, maxSkipBufferSize);
synchronized (lock) {
if ((skipBuffer == null) || (skipBuffer.length < nn))
skipBuffer = new char[nn];
long r = n;
while (r > 0) {
int nc = read(skipBuffer, 0, nn);
if (nc == -1)
break;
r -= nc;
}
return n - r;
}
}
public void mark(int readAheadLimit) throws IOException {
synchronized (lock) {
super.mark(readAheadLimit);
markedLineNumber = lineNumber;
markedCharNumber = charNumber;
}
}
public void reset() throws IOException {
synchronized (lock) {
super.reset();
lineNumber = markedLineNumber;
charNumber = markedCharNumber;
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,42 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/LocaleConverter.java,v $
* $Date: 2002/01/31 01:21:35 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class LocaleConverter {
public Hashtable convert(Hashtable table) throws ConversionError {
Hashtable result = new Hashtable();
convert(result, table);
return result;
}
protected void convert(Hashtable result, Hashtable source) throws ConversionError {
Enumeration enum = source.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
Object data = source.get(key);
result.put(key, data);
}
}
public static class ConversionError extends Exception {
public ConversionError() {
}
public ConversionError(String reason) {
super(reason);
}
}
}

View file

@ -0,0 +1,418 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/LocaleWriter.java,v $
* $Date: 2002/01/31 01:22:18 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import com.ibm.text.*;
import java.io.*;
import java.util.*;
/**
* A LocaleWriter takes locale data in standard form and
* writes it to standard output in a form suitable for
* loading programatically.
*/
public abstract class LocaleWriter {
private static final String INDENT_CHARS =
" "+
" "+
" ";
private static final char EOL_CHARS[] = {'\r', '\n', '\u2028', '\u2029'};
private static final int INDENT_SIZE = 4;
private static final int MAX_LINE_LENGTH = 80;
private int indentLevel;
private String indentString;
private boolean needsIndent;
protected StringBuffer lineBuffer = new StringBuffer();
private int lineLength;
protected PrintStream out;
protected PrintStream err;
public static final HexToUnicodeTransliterator huTranslit = new HexToUnicodeTransliterator("<U###0>");
public static final UnicodeToHexTransliterator uhTranslit = new UnicodeToHexTransliterator("\\\\u0000");
final File outFile = new File( "cnvLoc.txt");
FileOutputStream outFileStream;
BufferedWriter outBufWrite;
PrintWriter myOut;
public LocaleWriter(PrintStream out) {
this.out = out;
this.err = out;
try{
outFile.canWrite();
outFileStream = new FileOutputStream(outFile);
outBufWrite = new BufferedWriter(new OutputStreamWriter(outFileStream,"UTF8"));
}
catch(java.io.IOException e){
System.out.println("Encoding unsupported");
return;
}
}
public LocaleWriter(PrintStream out, PrintStream err) {
this.out = out;
this.err = err;
try{
outFile.canWrite();
outFileStream = new FileOutputStream(outFile);
outBufWrite = new BufferedWriter(new OutputStreamWriter(outFileStream,"UTF8"));
}
catch(java.io.IOException e){
System.out.println("Encoding unsupported");
return;
}
}
public void write(Locale locale, Hashtable localeData) {
open(locale);
//sort the key so the tags are in order in the resource file
SortedVector order = new SortedVector(localeData.keys(), new SortedVector.StringComparator());
Enumeration e = order.elements();
while (e.hasMoreElements()) {
final String key = (String)e.nextElement();
final Object data = localeData.get(key);
if (isDuplicateOfInheritedValue(locale, key, data)) {
println("///* Discarding duplicate data for tag: "+key+" */");
} else {
write(key, data);
}
}
close();
}
public void closeFileHandle(){
try{
outBufWrite.close();
}
catch(java.io.IOException excp){
out.println("could not close the output file");
}
}
protected void write(String tag, Object o) {
if (o instanceof String) {
write(tag, (String)o);
} else if (o instanceof String[]) {
write(tag, (String[]) o);
} else if (o instanceof String[][]) {
write(tag, (String[][])o);
} else if (o instanceof Object[]) {
Object[] data = (Object[])o;
String[] temp = new String[data.length];
for (int i = 0; i < data.length; i++) {
temp[i] = data[i].toString();
}
write(tag, temp);
} else if (o instanceof Object[][]) {
Object[][] data = (Object[][])o;
String[][] temp = new String[data.length][];
for (int i = 0; i < data.length; i++) {
temp[i] = new String[data[i].length];
for (int j = 0; j < temp[i].length; j++) {
temp[i][j] = data[i][j].toString();
}
}
write(tag, temp);
} else {
write(tag, o.toString());
}
}
protected final void write(String tag, String[][] value) {
if (value.length > 0) {
if (value[0].length > 2) {
write2D(tag, value);
} else {
writeTagged(tag, value);
}
} else {
writeTagged(tag, value);
}
}
protected abstract void open(Locale locale);
protected abstract void write(String tag, String value);
protected abstract void write(String tag, String[] value);
protected abstract void write2D(String tag, String[][] value);
protected abstract void writeTagged(String tag, String[][] value);
protected abstract void close();
protected abstract String getStringJoiningCharacter();
protected void tabTo(int pos) {
if (pos > lineLength) {
for (int i = lineLength; i < pos; i++) {
print(" ");
}
}
}
protected void writeToFile(String str){
ReplaceableString tempStr = new ReplaceableString();
tempStr.replace(0,tempStr.length(),str);
//huTranslit.transliterate(tempStr);
//uhTranslit.transliterate(tempStr);
try{
outBufWrite.write(tempStr.toString());
}
catch(java.io.IOException e){
out.println("Could not write to file");
}
}
protected void print(String val) {
if (needsIndent) {
out.print(indentString);
writeToFile(indentString);
lineLength += indentString.length();
needsIndent = false;
}
ReplaceableString tempStr = new ReplaceableString();
tempStr.replace(0,tempStr.length(),val);
huTranslit.transliterate(tempStr);
String tval = tempStr.toString();
if(tval.length()< val.length()){
// uhTranslit.transliterate(tempStr);
tval=prependEsc(tempStr.toString());
}
if (tval != null) {
out.print(tval);
writeToFile(tval);
int len = 0;
for (int i = 0; i < EOL_CHARS.length; i++) {
len = Math.max(len, tval.lastIndexOf(EOL_CHARS[i]));
}
if (len == 0) {
lineLength += tval.length();
} else {
lineLength = tval.length() - len;
}
}
}
protected String prependEsc(String str){
StringBuffer myStr = new StringBuffer();
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
if(ch > 0x007f){
myStr.append("\\u");
myStr.append(toHexString(ch,16,4));
}
else{
myStr.append(ch);
}
}
return myStr.toString();
}
protected String toHexString(char ch, int radix, int pad){
final int MAX_DIGITS = 10;
int length = 0;
char buffer[] = new char[10];
int num = 0;
int digit;
int j;
char temp;
int i = (int)ch;
do{
digit = (int)(i % radix);
buffer[length++]=(char)(digit<=9?(0x0030+digit):(0x0030+digit+7));
i=(i/radix);
}while(i>0);
while (length < pad){
buffer[length++] = 0x0030;/*zero padding */
}
/* null terminate the buffer */
if(length<MAX_DIGITS){
buffer[length] = 0x0000;
}
num= (pad>=length) ? pad :length;
/* Reverses the string */
for (j = 0; j < (num / 2); j++){
temp = buffer[(length-1) - j];
buffer[(length-1) - j] = buffer[j];
buffer[j] = temp;
}
return new String(buffer,0,length);
}
protected void println(String val) {
print(val);
out.println();
writeToFile("\n");
lineLength = 0;
needsIndent = true;
}
protected void printString(String val) {
if (val != null) {
indent();
lineBuffer.setLength(0);
lineBuffer.append("\"");
final int size = val.length();
for (int i = 0; i < size; i++) {
append(val.charAt(i));
/*if (!append(val.charAt(i))) {
lineBuffer.append("\"");
lineBuffer.append(getStringJoiningCharacter());
println(lineBuffer.toString());
lineBuffer.setLength(0);
lineBuffer.append("\"");
}*/
}
lineBuffer.append("\"");
print(lineBuffer.toString());
outdent();
} else {
print("\"\"");
}
}
protected boolean append(final char c) {
boolean escape = isEscapeChar(c);
if (escape) {
appendEscapedChar(c, lineBuffer);
} else {
lineBuffer.append(c);
}
return (lineLength + lineBuffer.length() < MAX_LINE_LENGTH);
}
protected boolean isEscapeChar(final char c) {
switch (c) {
case '"':
case '\\':
case '\n':
case '\r':
case '\u2028':
case '\u2029':
return true;
default:
return (c < ' ') || (c > 0x07F);
}
}
protected void appendEscapedChar(char c, StringBuffer buffer) {
buffer.append(getEscapeChar());
int value = ((int)c) & 0xFFFF;
buffer.append(HEX_DIGIT[(value & 0xF000) >> 12]);
buffer.append(HEX_DIGIT[(value & 0x0F00) >> 8]);
buffer.append(HEX_DIGIT[(value & 0x00F0) >> 4]);
buffer.append(HEX_DIGIT[(value & 0x000F)]);
}
protected String getEscapeChar() {
return "\\u";
}
protected final void indent() {
indent(1);
}
protected void indent(int amount) {
indentLevel += amount;
indentString = INDENT_CHARS.substring(0, indentLevel*INDENT_SIZE);
}
protected final void outdent() {
outdent(1);
}
protected void outdent(int amount) {
indentLevel -= amount;
indentString = INDENT_CHARS.substring(0, indentLevel*INDENT_SIZE);
}
static final char[] HEX_DIGIT = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'};
/** Return true if the value for the specified tag is the same
* as the value inherited from the parent for that tag */
private boolean isDuplicateOfInheritedValue(final Locale loc, String tag, Object value) {
if (value == null) return true;
try {
final ResourceBundle parentBundle = getParentBundle(loc);
if (parentBundle == null) return false;
Object parentValue = parentBundle.getObject(tag);
if (!objectsAreEqual(value, parentValue)) {
return false;
} else {
return true;
}
} catch (java.util.MissingResourceException e) {
return false;
}
}
private boolean objectsAreEqual(final Object item, final Object parentItem) {
if (item instanceof Object[] && parentItem instanceof Object[]) {
return arraysAreEqual((Object[])item, (Object[])parentItem);
} else {
return item.equals(parentItem);
}
}
private boolean arraysAreEqual(final Object[] item, final Object[] parentItem) {
boolean matches = item.length == parentItem.length;
for (int i = 0; i < item.length && matches; i++) {
matches = objectsAreEqual(item[i], parentItem[i]);
}
return matches;
}
private ResourceBundle getParentBundle(final Locale loc) {
try {
final String x = loc.toString();
final int ndx = x.lastIndexOf('_');
if (ndx < 0) {
return null;
} else {
final String parentLocName = x.substring(0, ndx);
final Locale parentLoc = localeFromString(parentLocName);
return ResourceBundle.getBundle("com.ibm.jtc.localeconverter.myLocaleElements", parentLoc);
}
} catch (MissingResourceException e) {
return null;
}
}
private String replace(String source, String target, String replacement) {
if (target.equals(replacement)) {
return source;
} else {
StringBuffer result = new StringBuffer();
int lastNdx = 0;
int ndx = source.indexOf(target);
while (ndx >= 0) {
result.append(source.substring(lastNdx, ndx));
result.append(replacement);
ndx += target.length();
lastNdx = ndx;
ndx = source.indexOf(target, ndx);
}
result.append(source.substring(lastNdx));
return result.toString();
}
}
public Locale localeFromString(final String localeName) {
String language = localeName;
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx);
country = country.substring(0, ndx);
}
return new Locale(language, country, variant);
}
}

View file

@ -0,0 +1,209 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/NeutralToJ1Converter.java,v $
* $Date: 2002/01/31 01:22:21 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class NeutralToJ1Converter extends LocaleConverter {
private static class Conversion {
private String propName;
private int ndx;
protected Conversion() {
}
public Conversion(String propName) {
this.propName = propName;
this.ndx = -1;
}
public Conversion(String propName, int ndx) {
this.propName = propName;
this.ndx = ndx;
}
public String getPropName() {
return propName;
}
public String convert(Hashtable source) throws ConversionError {
Object sourceData = source.get(propName);
if (sourceData == null) {
return null;
}
if (ndx >= 0) {
if (sourceData instanceof String[]) {
sourceData = ((String[])sourceData)[ndx];
} else if (sourceData instanceof String[][]) {
sourceData = ((String[][])sourceData)[ndx];
}
}
if (sourceData instanceof String) {
return (String)sourceData;
} else if (sourceData instanceof String[]) {
String[] data = (String[])sourceData;
StringBuffer result = new StringBuffer();
for (int i = 0; i < data.length; i++) {
if (i > 0) result.append(';');
result.append(data[i]);
}
return result.toString();
} else {
throw new ConversionError("could not convert tag: "+propName);
}
}
}
private static class CollationConversion extends Conversion {
public String convert(Hashtable source) throws ConversionError {
Object[][] elements = (Object[][])source.get("CollationElements");
CollationItem[] items = (CollationItem[])elements[2][1];
if (items == null) {
return "";
} else {
StringBuffer result = new StringBuffer();
for (int i = 0; i < items.length; i++) {
if(items[i]!=null){
result.append(items[i].toString());
}
}
return result.toString();
}
}
}
private static final Conversion[] conversions = {
new Conversion("LocaleString"), /*locale id based on iso codes*/
new Conversion("LocaleID"), /*Windows id*/
new Conversion("ShortLanguage"), /*iso-3 abbrev lang name*/
new Conversion("ShortCountry"), /*iso-3 abbrev country name*/
new Conversion("Languages"), /*language names*/
new Conversion("Countries"), /*country names*/
new Conversion("MonthNames",0), /*january*/
new Conversion("MonthNames",1), /*february*/
new Conversion("MonthNames",2), /*march*/
new Conversion("MonthNames",3), /*april*/
new Conversion("MonthNames",4), /*may*/
new Conversion("MonthNames",5), /*june*/
new Conversion("MonthNames",6), /*july*/
new Conversion("MonthNames",7), /*august*/
new Conversion("MonthNames",8), /*september*/
new Conversion("MonthNames",9), /*october*/
new Conversion("MonthNames",10), /*november*/
new Conversion("MonthNames",11), /*december*/
new Conversion("MonthNames",12), /*month 13 if applicable*/
new Conversion("MonthAbbreviations",0), /*abb january*/
new Conversion("MonthAbbreviations",1), /*abb february*/
new Conversion("MonthAbbreviations",2), /*abb march*/
new Conversion("MonthAbbreviations",3), /*abb april*/
new Conversion("MonthAbbreviations",4), /*abb may*/
new Conversion("MonthAbbreviations",5), /*abb june*/
new Conversion("MonthAbbreviations",6), /*abb july*/
new Conversion("MonthAbbreviations",7), /*abb august*/
new Conversion("MonthAbbreviations",8), /*abb september*/
new Conversion("MonthAbbreviations",9), /*abb october*/
new Conversion("MonthAbbreviations",10), /*abb november*/
new Conversion("MonthAbbreviations",11), /*abb december*/
new Conversion("MonthAbbreviations",12), /*abb month 13 if applicable*/
new Conversion("DayNames",0), /*Monday*/
new Conversion("DayNames",1), /*Tuesday*/
new Conversion("DayNames",2), /*Wednesday*/
new Conversion("DayNames",3), /*Thursday*/
new Conversion("DayNames",4), /*Friday*/
new Conversion("DayNames",5), /*Saturday*/
new Conversion("DayNames",6), /*Sunday*/
new Conversion("DayAbbreviations",0), /*abb Monday*/
new Conversion("DayAbbreviations",1), /*abb Tuesday*/
new Conversion("DayAbbreviations",2), /*abb Wednesday*/
new Conversion("DayAbbreviations",3), /*abb Thursday*/
new Conversion("DayAbbreviations",4), /*abb Friday*/
new Conversion("DayAbbreviations",5), /*abb Saturday*/
new Conversion("DayAbbreviations",6), /*abb Sunday*/
new Conversion("AmPmMarkers",0), /*am marker*/
new Conversion("AmPmMarkers",1), /*pm marker*/
new Conversion("Eras"),/*era strings*/
new Conversion("NumberPatterns",0), /*decimal pattern*/
new Conversion("NumberPatterns",1), /*currency pattern*/
new Conversion("NumberPatterns",2), /*percent pattern*/
new Conversion("NumberElements",0), /*decimal separator*/
new Conversion("NumberElements",1), /*group (thousands) separator*/
new Conversion("NumberElements",2), /*list separator*/
new Conversion("NumberElements",3), /*percent sign*/
new Conversion("NumberElements",4), /*native 0 digit*/
new Conversion("NumberElements",5), /*pattern digit*/
new Conversion("NumberElements",6), /*minus sign*/
new Conversion("NumberElements",7), /*exponential*/
new Conversion("CurrencyElements",0), /*local currency symbol*/
new Conversion("CurrencyElements",1), /*intl currency symbol*/
new Conversion("CurrencyElements",2), /*monetary decimal separator*/
new Conversion("DateTimePatterns",0), /*full time pattern*/
new Conversion("DateTimePatterns",1), /*long time pattern*/
new Conversion("DateTimePatterns",2), /*medium time pattern*/
new Conversion("DateTimePatterns",3), /*short time pattern*/
new Conversion("DateTimePatterns",4), /*full date pattern*/
new Conversion("DateTimePatterns",5), /*long date pattern*/
new Conversion("DateTimePatterns",6), /*medium date pattern*/
new Conversion("DateTimePatterns",7), /*short date pattern*/
new Conversion("DateTimePatterns",8), /*date-time pattern*/
new Conversion("DateTimeElements",9), /*first day of week*/
new Conversion("DateTimeElements",10), /*min days in first week*/
new CollationConversion(), /*collation order*/
};
private Locale locale;
private Locale parentLocale;
private ResourceBundle defaultData;
public NeutralToJ1Converter(Locale locale) {
this.locale = locale;
String language = locale.toString();
String country = "";
String variant = "";
int ndx = language.indexOf('_');
if (ndx >= 0) {
country = language.substring(ndx+1);
language = language.substring(0, ndx);
}
ndx = country.indexOf('_');
if (ndx >= 0) {
variant = country.substring(ndx);
country = country.substring(0, ndx);
}
if ("".equals(country)) {
language = "";
variant = "";
} else if ("".equals(variant)) {
country = "";
}
parentLocale = new Locale(language, country, variant);
defaultData =
ResourceBundle.getBundle("com.ibm.jtc.localeconverter.myLocaleElements", parentLocale);
//{{INIT_CONTROLS
//}}
}
/** convert the source table to the result */
protected void convert(Hashtable result, Hashtable source) throws ConversionError {
Vector localeElements = new Vector();
for (int i = 0; i < conversions.length; i++) {
final Conversion conv = conversions[i];
final String newValue = conv.convert(source);
if (newValue != null) {
localeElements.addElement(newValue);
} else {
localeElements.addElement(defaultData.getObject(conv.getPropName()));
}
}
result.put("LocaleElements", localeElements);
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,407 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/POSIXLocaleReader.java,v $
* $Date: 2002/01/31 01:22:24 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class POSIXLocaleReader {
private final String localeDataPath;
private final Locale locale;
public static final int TAG_TOKEN = 1;
public static final int SEPARATOR_TOKEN = 2;
public static final int EOL_TOKEN = 3;
public static final int EOF_TOKEN = 4;
//these states are used to parse the bulk of the
//input file. They translate escaped characters
//and symolic character references inline.
static final Lex.Transition[][] dataStates = {
{ //state 0: start
new SpaceTransition(0),
new Lex.CharTransition(';', Lex.IGNORE_CONSUME, SEPARATOR_TOKEN),
new Lex.CharTransition(',', Lex.IGNORE_CONSUME, SEPARATOR_TOKEN),
new EOLTransition(EOL_TOKEN),
new TokenTransition(TAG_TOKEN),
new Lex.EOFTransition(EOF_TOKEN),
new Lex.ParseExceptionTransition("unexpected characters")
}
};
static final Lex.Transition[][] LCStates = {
{ //state 0: start
new SpaceTransition(0),
new EOLTransition(EOL_TOKEN),
new Lex.EOFTransition(EOF_TOKEN),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //grab first word
new Lex.StringTransition(SpaceTransition.SPACE_CHARS, Lex.IGNORE_PUTBACK, TAG_TOKEN),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, TAG_TOKEN),
new Lex.EOFTransition(TAG_TOKEN),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
}
};
public POSIXLocaleReader(final String localeDataPath, final Locale locale) {
this.localeDataPath = localeDataPath;
this.locale = locale;
//{{INIT_CONTROLS
//}}
}
public Hashtable parse(String fileName, byte flags) throws IOException {
try {
Hashtable table = parseNative(fileName);
Hashtable result = new PosixToNeutralConverter(flags, locale,fileName).convert(table);
return result;
} catch (LocaleConverter.ConversionError e) {
System.err.println("Internal error converting locale data");
return null;
}
}
public Hashtable parseNative(String fileName) throws IOException {
char oldEscapeChar = EscapeTransition.setDefaultEscapeChar();
char oldCommentChar = EOLTransition.setDefaultCommentChar();
Hashtable table = new Hashtable();
try {
LineCharNumberReader lines = new LineCharNumberReader(
new BufferedReader(
new FileReader(
new File(localeDataPath, fileName)
)
)
);
PushbackReader reader = new PushbackReader(lines);
//Shove a newline at the start of the file. This has the affect of allowing
//the file to start with a comment, since the parser only allows comments as
//part of an EOL
reader.unread('\n');
String sectionTag = seekLC(reader);
while (sectionTag != null) {
try {
parseSection(table, reader, sectionTag);
} catch (Lex.ParseException e) {
System.err.println("ERROR parsing: "+e.reason);
System.err.println(" Line: "+lines.getLineNumber());
System.err.println(" char: "+lines.getCharNumber());
seekEND(reader);
System.err.println("Skipped to line: "+(lines.getLineNumber()+1));
}
sectionTag = seekLC(reader);
}
} finally {
EscapeTransition.setEscapeChar(oldEscapeChar);
EOLTransition.setCommentChar(oldCommentChar);
}
return table;
}
private void parseSection(Hashtable table, PushbackReader reader, String sectionTag) throws IOException {
if (sectionTag.equals("LC_CTYPE")) {
parseCTYPE(table, reader);
} else if (sectionTag.equals("LC_COLLATE")) {
parseCOLLATE(table, reader);
} else if (sectionTag.equals("LC_MONETARY")) {
parseLC(table, reader, sectionTag);
} else if (sectionTag.equals("LC_NUMERIC")) {
parseLC(table, reader, sectionTag);
} else if (sectionTag.equals("LC_TIME")) {
parseLC(table, reader, sectionTag);
} else if (sectionTag.equals("LC_MESSAGES")) {
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_MEASUREMENT")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_ADDRESS")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_PAPER")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_NAME")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_IDENTIFICATION")){
parseLC(table, reader, sectionTag);
}else if(sectionTag.equals("LC_TELEPHONE")){
parseLC(table, reader, sectionTag);
}else {
System.out.println("Unrecognised section:"+sectionTag);
System.out.println("Default parsing applied.");
parseLC(table, reader, sectionTag);
}
}
private PushbackReader createParserInput(String localeName) throws IOException {
PushbackReader reader = new PushbackReader(
new BufferedReader(
new FileReader(
new File(localeDataPath, localeName)
)
)
);
//Shove a newline at the start of the file. This has the affect of allowing
//the file to start with a comment, since the parser only allows comments as
//part of an EOL
reader.unread('\n');
return reader;
}
private String seekLC(PushbackReader reader) throws IOException {
Lex p = new Lex(LCStates, reader);
final String LC = "LC_";
int s = p.nextToken();
while ((s != EOF_TOKEN)) {
if (s == TAG_TOKEN) {
if (p.dataStartsWith(LC)) {
String tag = p.getData();
do {
s = p.nextToken();
} while (s != EOL_TOKEN && s != EOF_TOKEN);
return tag;
} else if (p.dataEquals("escape_char")) {
s = p.nextToken();
if (s == TAG_TOKEN || p.getData().length() != 1) {
String escape_char = p.getData();
EscapeTransition.setEscapeChar(escape_char.charAt(0));
} else {
System.out.println("Error in escape_char directive. Directive ignored.");
}
} else if (p.dataEquals("comment_char")) {
s = p.nextToken();
if (s == TAG_TOKEN || p.getData().length() != 1) {
String comment_char = p.getData();
EOLTransition.setCommentChar(comment_char.charAt(0));
} else {
System.out.println("Error in escape_char directive. Directive ignored.");
}
}
}
s = p.nextToken();
}
return null;
}
private boolean seekEND(PushbackReader reader) throws IOException {
Lex p = new Lex(LCStates, reader);
final String END = "END";
int s = p.nextToken();
while ((s != EOF_TOKEN)) {
if (s == TAG_TOKEN) {
if (p.dataStartsWith(END)) {
do {
s = p.nextToken();
} while (s != EOL_TOKEN && s != EOF_TOKEN);
return true;
}
}
s = p.nextToken();
}
return false;
}
private void parseCTYPE(Hashtable table, PushbackReader reader) throws IOException {
Lex p = new Lex(dataStates, reader);
StringBuffer temp = new StringBuffer();
int s = p.nextToken();
if ((s == TAG_TOKEN) && p.dataEquals("copy")) {
p.accept(TAG_TOKEN);
parseCopy("LC_CTYPE", p.getData(), table);
p.accept(EOL_TOKEN);
p.accept(TAG_TOKEN, "END");
p.accept(TAG_TOKEN, "LC_CTYPE");
} else {
while ((s == TAG_TOKEN) && !p.dataEquals("END")) {
String key = p.getData();
temp.setLength(0);
p.accept(TAG_TOKEN);
p.appendDataTo(temp);
s = p.nextToken();
while (s == SEPARATOR_TOKEN) {
p.accept(TAG_TOKEN);
p.appendDataTo(temp);
s = p.nextToken();
}
if (s != EOL_TOKEN) {
throw new IOException();
} else {
table.put(key, temp.toString());
}
s = p.nextToken();
}
p.accept(TAG_TOKEN, "LC_CTYPE");
}
}
private void parseCopy(String section, String toCopy, Hashtable t) throws IOException {
char oldEscapeChar = EscapeTransition.setDefaultEscapeChar();
char oldCommentChar = EOLTransition.setDefaultCommentChar();
try {
PushbackReader reader = createParserInput(toCopy);
String tag = seekLC(reader);
while (tag != null && !section.equals(tag)) {
tag = seekLC(reader);
}
if (tag != null) {
parseSection(t, reader, section);
} else {
//hey {jf} - is this an error?
}
} finally {
EscapeTransition.setEscapeChar(oldEscapeChar);
EOLTransition.setCommentChar(oldCommentChar);
}
}
private void parseLC(Hashtable t, PushbackReader reader, String sectionTag) throws IOException {
Lex input = new Lex(dataStates, reader);
input.accept(TAG_TOKEN);
if (input.dataEquals("copy")) {
input.accept(TAG_TOKEN);
parseCopy(sectionTag, input.getData(), t);
} else {
while ((input.getState() == TAG_TOKEN) && !input.dataEquals("END")) {
String label = input.getData();
Vector values = new Vector();
input.accept(TAG_TOKEN);
String temp = input.getData();
values.addElement(temp);
while (input.nextToken() == SEPARATOR_TOKEN) {
input.accept(TAG_TOKEN);
String value = input.getData();
values.addElement(value);
}
if (values.size() > 1) {
String[] data = new String[values.size()];
values.copyInto(data);
t.put(label, data);
} else {
t.put(label, values.elementAt(0));
}
if (input.getState() != EOL_TOKEN) {
System.out.println(label);
throw new IOException();
}
input.nextToken();
}
}
input.accept(TAG_TOKEN, sectionTag);
}
private void parseCOLLATE(Hashtable table, PushbackReader reader)
throws IOException {
PosixCharMap map = new PosixCharMap(SymbolTransition.getCharMap());
SymbolTransition.setCharMap(map);
try {
Lex input = new Lex(dataStates, reader);
PosixCollationBuilder builder = new PosixCollationBuilder(map);
int s = input.nextToken();
while (s == EOL_TOKEN) s = input.nextToken();
while (s == TAG_TOKEN) {
if (input.dataEquals("END")) {
break;
} else if (input.dataEquals("UNDEFINED")) {
System.err.println("WARNING: Undefined characters will sort last.");
s = input.nextToken();
while (s != EOF_TOKEN && s != EOL_TOKEN) {
s = input.nextToken();
}
} else if (input.dataEquals("copy")) {
//copy collation rules from another locale
input.accept(TAG_TOKEN);
String toCopy = input.getData();
input.accept(EOL_TOKEN);
parseCopy("LC_COLLATE", toCopy, table);
System.err.println("Copying collation rules from "+toCopy+"...");
} else if (input.dataEquals("...")) {
//fill the space between the last element and the next element
System.err.println("ERROR: Ellipsis not supported in collation rules.");
System.err.println(" Line ignored");
} else if (input.dataEquals("replace-after")) {
System.err.println("ERROR: Replace-after not supported in collation rules.");
System.err.println(" Skipping until next replace-end.");
s = input.nextToken();
while (s != EOF_TOKEN) {
if (s == TAG_TOKEN && input.dataEquals("replace-end")) {
input.accept(EOL_TOKEN);
break;
}
}
} else if (input.dataEquals("collating-element")) {
//Several characters should sort as a single element.
input.accept(TAG_TOKEN); //get the symbol
String key = input.getData();
input.accept(TAG_TOKEN, "from");
input.accept(TAG_TOKEN); //get the expansion
String value = input.getData();
builder.defineContraction(key, value);
input.accept(EOL_TOKEN);
} else if (input.dataEquals("collating-symbol")) {
//define a weight symbol. This symbol does not represent a character.
//It's only used for comparison purposes. We define the character
//value for this character to be in the private area since our
//collation stuff doesn't sort that area.
input.accept(TAG_TOKEN);
builder.defineWeightSymbol(input.getData());
input.accept(EOL_TOKEN);
} else if (input.dataEquals("order_start")) {
Vector tempVector = new Vector();
//start reading collation ordering rules.
input.accept(TAG_TOKEN);
tempVector.addElement(input.getData());
s = input.nextToken();
while (s == SEPARATOR_TOKEN) {
input.accept(TAG_TOKEN);
tempVector.addElement(input.getData());
s = input.nextToken();
}
String[] order_start = new String[tempVector.size()];
tempVector.copyInto(order_start);
table.put("sort_order", order_start);
} else if (input.dataEquals("order_end")) {
//build a list of ordered collation elements
input.accept(EOL_TOKEN);
SortedVector order = builder.getSortOrder();
PosixCollationBuilder.CollationRule[] ruleSource =
new PosixCollationBuilder.CollationRule[order.size()];
order.copyInto(ruleSource); //copy into an array so we can add it to the output table
//this is only for information purposes so we can retrieve the source of the
//collationItems with the weights if we want them later
table.put("posix_sort_rules", ruleSource);
} else {
//add a collation item to the list
builder.addRule(input.getData());
s = input.nextToken();
while (s == TAG_TOKEN) {
//we're expecting weights here
builder.addWeight(input.getData());
s = input.nextToken();
if (s == SEPARATOR_TOKEN) {
s = input.nextToken();
}
}
}
s = input.nextToken();
}
input.accept(TAG_TOKEN, "LC_COLLATE");
} finally {
SymbolTransition.setCharMap(map.getParent());
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,328 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/PosixCharMap.java,v $
* $Date: 2002/01/31 01:22:21 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
import com.ibm.text.*;
public class PosixCharMap {
private Hashtable table = new Hashtable();
private Hashtable backTable = null;
private PosixCharMap parentMap;
private String encoding;
public PosixCharMap() {
}
public PosixCharMap(PosixCharMap parent) {
parentMap = parent;
}
public PosixCharMap(String fileName) throws IOException {
this(new FileReader(fileName));
}
public PosixCharMap(String pathName, String fileName) throws IOException {
this(new FileReader(new File(pathName, fileName)));
}
public PosixCharMap(Reader inputReader) throws IOException {
load(new BufferedReader(inputReader));
}
public PosixCharMap getParent() {
return parentMap;
}
public void setParent(PosixCharMap parent) {
parentMap = parent;
}
public void load(String pathName, String fileName) throws IOException {
load(new File(pathName, fileName),"");
}
public void load(String pathName, String fileName, String enc)throws IOException{
load(new File(pathName, fileName),enc);
}
public void load(File file, String enc) throws IOException {
encoding =enc;
load(new BufferedReader(new FileReader(file)));
}
public void load(Reader inputReader) throws IOException {
PosixCharMap oldMap = SymbolTransition.getCharMap();
SymbolTransition.setCharMap(null);
try {
final int TOKEN = 1;
final int EOF = 2;
final int EOL = 3;
final int RANGE = 4;
final Lex.Transition[][] states1 = {
{ //state 0: start
new SpaceTransition(0),
new EOLTransition(EOL),
new Lex.EOFTransition(EOF),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //grab first word
new Lex.StringTransition(SpaceTransition.SPACE_CHARS, Lex.IGNORE_CONSUME, TOKEN),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_CONSUME, TOKEN),
new Lex.EOFTransition(TOKEN),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
}
};
final Lex.Transition[][] states2 = {
{ //These states only return <symbols>. All
//other text is ignored.
new Lex.EOFTransition(EOF),
new EOLTransition(EOL),
new SymbolTransition(TOKEN),
new SpaceTransition(0),
new RangeTransition(RANGE),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, 0)
},
};
PushbackReader input = new PushbackReader(inputReader);
Lex p = new Lex(states1, input);
int state;
do {
state = p.nextToken();
} while ((state != EOF) && !p.dataEquals("CHARMAP"));
p.accept(EOL);
if (state != EOF) {
p = new Lex(states2, input);
state = p.nextToken();
while (state != EOF) {
String key = p.getData();
state = p.nextToken();
while (state == EOL) {
String data = p.getData();
data.trim();
if (data.startsWith("<U") || data.startsWith("#U")) {
String numData = data.substring(2,data.length()-1);
int digit = Integer.parseInt(numData, 16);
defineMapping(key, ""+(char)digit);
}else if(data.startsWith("\\x")){
byte[] encData = new byte[6];
int num = hexToByte(data,encData);
String tData = new String(encData,0,num,encoding);
defineMapping(key,tData);
}
state = p.nextToken();
key=p.getData();
}
// we come here only if there is a range transition
if( state ==RANGE){
String begin = key;
state = p.nextToken();
String end = p.getData();
state = p.nextToken();
String data = p.getData();
data.trim();
byte[] encData = new byte[6];
int num = hexToByte(data,encData);
String tData = new String(encData,0,num,encoding);
String stringVal;
int[] val = getInt(begin);
int beginRange = val[1];
val =getInt(end);
int endRange = val[1];
stringVal = key.substring(0,val[0]);
int digit = (int)(char)tData.charAt(0);
while(beginRange <= endRange){
defineMapping((stringVal+beginRange+">"),""+(char)digit++);
beginRange++;
}
state = p.nextToken();
key=p.getData();
}
//state = p.nextToken();
}
}
} catch (EOFException e) {
} finally {
SymbolTransition.setCharMap(oldMap);
}
}
public int[] getInt(String data){
int i=0;
int[] retVal = new int[2];
int len =data.length();
while(i< len){
if((data.charAt(i))-0x30 < (0x39-0x30)){
break;
}
i++;
}
String sub =data.substring(i,len-1);
retVal[0] =i;
retVal[1]=Integer.parseInt(sub,10);
return retVal;
}
public int hexToByte(String data, byte[] retval){
String tData = data;
int i=0;
for(i=0;i < data.length()/4; i++){
if(tData.charAt(0)=='\\' && tData.charAt(1)=='x'){
String numData = tData.substring(2,4);
retval[i] = (byte) Integer.parseInt(numData,16);
tData = tData.substring(4,tData.length());
}
}
return i;
}
public void defineMapping(String from, String to) {
table.put(from, to);
backTable = null;
}
public void undefineMapping(String from) {
table.remove(from);
backTable = null;
}
public void swap() {
Hashtable newTable = new Hashtable();
Enumeration enum = table.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
String code = (String)table.get(key);
String newKey = toSymbol(code);
String newCode = toLiteral(key);
String prevCode = (String)newTable.get(newKey);
if (prevCode == null || prevCode.compareTo(newCode) > 0) {
newTable.put(newKey, newCode);
}
}
table = newTable;
}
private String toLiteral(String code) {
String data = code.substring(2,code.length()-1);
int digit = Integer.parseInt(data, 16);
return "" + (char)digit;
}
private String toSymbol(String code) {
StringBuffer escapeBuffer = new StringBuffer();
escapeBuffer.append(">");
for (int i = 0; i < code.length(); i++) {
int value = ((int)code.charAt(i)) & 0xFFFF;
while ((value > 0) || (escapeBuffer.length() < 5)) {
char digit = Character.forDigit(value % 16, 16);
escapeBuffer.append(digit);
value >>= 4;
}
}
escapeBuffer.append("U<");
escapeBuffer.reverse();
return escapeBuffer.toString();
}
public void dump(PrintStream out) {
StringBuffer escapeBuffer = new StringBuffer();
Enumeration enum = table.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
String code = (String)table.get(key);
out.print(key);
out.print(" <U");
for (int i = 0; i < code.length(); i++) {
int value = ((int)code.charAt(i)) & 0xFFFF;
escapeBuffer.setLength(0);
while ((value > 0) || (escapeBuffer.length() < 4)) {
char digit = Character.forDigit(value % 16, 16);
escapeBuffer.append(digit);
value >>= 4;
}
escapeBuffer.reverse();
out.print(escapeBuffer.toString());
}
out.println(">");
}
}
public String mapKey(final String key) {
String result = (String)table.get(key);
if (result == null) {
if (parentMap != null) {
result = parentMap.mapKey(key);
} else {
result = key;
}
}
return result;
}
public String backmapValue(final String value) {
if (backTable == null) {
backTable = new Hashtable();
Enumeration enum = table.keys();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
String val = (String)table.get(key);
backTable.put(val, key);
}
}
String result = (String)backTable.get(value);
if (result == null) {
if (parentMap != null) {
result = parentMap.backmapValue(value);
} else {
result = value;
}
}
return result;
}
public Enumeration keys() {
return table.keys();
}
public Enumeration elements() {
return table.elements();
}
public static void main(String args[]) {
try {
PosixCharMap map1 = new PosixCharMap(
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps",
"IBM-1129.UPMAP100.txt");
map1.swap();
map1.dump(System.out);
SymbolTransition.setCharMap(map1);
System.out.println(); System.out.println();
//PosixCharMap map = new PosixCharMap("C:\\projects\\data\\ISO-8859-1.html");
PosixCharMap map = new PosixCharMap(
"C:\\projects\\com\\taligent\\localeconverter\\CharMaps",
"ibm1129.txt");
map.dump(System.out);
System.out.println();
} catch (Exception e) {
System.out.println(e);
}
}
}

View file

@ -0,0 +1,349 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/PosixCollationBuilder.java,v $
* $Date: 2002/01/31 01:22:24 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import com.ibm.text.*;
import java.io.*;
import java.util.*;
class PosixCollationBuilder {
private static final int MAX_WEIGHTS = 4;
private static final int MAX_COMPOSITION = 4;
private static int nextCharNumber = 1;
private Hashtable weightSymbols = new Hashtable();
private Hashtable contractions = new Hashtable();
private Hashtable rules = new Hashtable();
private CollationRule lastRule = null;
private PosixCharMap map;
private SortedVector order;
private static int FIRST_WEIGHT_CHAR = 0x0000F7FF;
private int nextWeightChar = FIRST_WEIGHT_CHAR;
private CollationRule ignoreRule; //rule for the collating-symbol IGNORE
public class CollationRule {
int charNumber;
String value;
int nextWeight = 0;
String[] weightSource = new String[MAX_WEIGHTS];
int weight[][] = null;
StringBuffer source = new StringBuffer();
public CollationRule(String symbol) {
charNumber= nextCharNumber++;
value = symbol;
for (int i = 0; i < MAX_WEIGHTS; i++) {
weightSource[i] = symbol;
}
source.append(map.backmapValue(symbol));
source.append("\t\t");
}
private CollationRule(CollationRule other, int composition) {
charNumber = other.charNumber;
value = other.value;
nextWeight = other.nextWeight;
for (int i = 0; i < MAX_WEIGHTS; i++) {
String source = other.weightSource[i];
if (source.length() > composition) {
weightSource[i] = ""+source.charAt(composition);
} else {
weightSource[i] = value;
}
}
}
//HexToUnicodeTransliterator myTranslit = new HexToUnicodeTransliterator("<U###0>");
public void addWeight(String symbol) {
// ReplaceableString tSymbol = new ReplaceableString(symbol);
// myTranslit.transliterate(tSymbol);
//limit the size of a single weight
if (symbol.length() > MAX_COMPOSITION) {
System.err.println("WARNING: Weights of composition greater than "+MAX_COMPOSITION+" were truncated.");
symbol = symbol.substring(0, MAX_COMPOSITION);
}
//limit the number of weights
if (nextWeight < MAX_WEIGHTS) {
if (nextWeight > 0) {
source.append(";");
}
for (int i = 0; i < symbol.length(); i++) {
source.append(map.backmapValue(""+symbol.charAt(i)));
}
weightSource[nextWeight++] = symbol;
weight = null;
}
}
public int compare(CollationRule other) {
if (other == null) return compare(ignoreRule);
resolveWeights();
other.resolveWeights();
int compareSize = Math.min(getSize(), other.getSize());
for (int j = 0; j < compareSize; j++) {
for (int i = 0; i < MAX_WEIGHTS; i++) {
int diff = weight[j][i] - other.weight[j][i];
if (diff < 0) {
return -(i+1);
} if (diff > 0) {
return i+1;
}
}
}
return getSize() - other.getSize();
}
public boolean isMultiWeight() {
return getSize() > 1;
}
public int getSize() {
int size = 0;
for (int i = 1; i < weightSource.length; i++) {
size = Math.max(size, weightSource[i].length());
}
return size;
}
public CollationRule getComponent(int ndx) {
return new CollationRule(this, ndx);
}
public String getValue() {
return value;
}
public String getSymbol() {
String newValue = isContraction();
if (newValue != null) {
return newValue;
} else {
newValue = isWeightSymbol();
if (newValue != null) {
return newValue;
} else {
return value;
}
}
}
public String getSource() {
return source.toString();
}
private String isContraction() {
return (String)contractions.get(value);
}
private String isWeightSymbol() {
return (String)weightSymbols.get(value);
}
public CollationRule seeksToRule() {
CollationRule comp;
if (getSize() <= 1) {
comp = this; //save an object creation
} else {
comp = getComponent(0);
}
int ndx = order.indexOf(comp);
if (ndx == 0) {
return this;
} else {
CollationRule exp;
do {
exp = (CollationRule)order.elementAt(ndx--);
} while (ndx > 0 && exp.getSize() > 1);
return exp;
}
}
public String getExpansion() {
if (getSize() <= 1) {
return null;
} else {
StringBuffer expansion = new StringBuffer();
for (int j = 0; j < getSize(); j++) {
CollationRule comp = getComponent(j);
int ndx = order.indexOf(comp);
CollationRule exp;
do {
exp = (CollationRule)order.elementAt(ndx--);
} while (ndx >= 0 && exp.getSize() > 1);
expansion.append(exp.getSymbol());
}
return expansion.toString();
}
}
public String toString() {
return source.toString();
/* resolveWeights();
StringBuffer buf = new StringBuffer();
buf.append(charNumber);
buf.append(' ');
buf.append(value);
buf.append(' ');
buf.append(getSymbol());
buf.append(' ');
buf.append((isWeightSymbol() != null)?"W":" ");
buf.append(' ');
for (int i = 0; i < MAX_WEIGHTS; i++) {
buf.append(weightSource[i]);
buf.append(' ');
}
for (int i = 0; i < getSize(); i++) {
buf.append("[ ");
for (int j = 0; j < MAX_WEIGHTS; j++) {
int w = weight[i][j];
buf.append(w);
buf.append(' ');
}
buf.append(']');
}
return buf.toString();
*/
}
private void resolveWeights() {
if (weight == null) {
weight = new int[MAX_COMPOSITION][MAX_WEIGHTS];
for (int j = 0; j < MAX_WEIGHTS; j++) {
String symbol = weightSource[j];
if (symbol.length() <= 1) {
weight[0][j] = ordinalityOf(symbol);
} else {
for (int i = 0; i < symbol.length(); i++) {
char c = symbol.charAt(i);
weight[i][j] = ordinalityOf(""+c);
}
}
}
}
}
}
public PosixCollationBuilder(PosixCharMap map) {
this.map = map;
String ignoreSymbol = defineWeightSymbol("IGNORE");
ignoreRule = new CollationRule(ignoreSymbol);
rules.put(ignoreSymbol, ignoreRule);
lastRule = ignoreRule;
//{{INIT_CONTROLS
//}}
}
public String defineWeightSymbol(String symbol) {
order = null;
String c = nextFreeWeightChar();
map.defineMapping(symbol, c);
weightSymbols.put(c, symbol);
weightSymbols.put(symbol, c);
return c;
}
public String defineContraction(String symbol, String value) {
order = null;
String c = nextFreeWeightChar();
map.defineMapping(symbol, c);
contractions.put(c, value);
return c;
}
private String nextFreeWeightChar() {
String result = "";
String mappedSource;
do {
result = ""+(char)nextWeightChar--;
mappedSource = map.backmapValue(result);
} while (result != mappedSource);
return result;
}
public int ordinalityOf(String symbol) {
// HexToUnicodeTransliterator newTranslit = new HexToUnicodeTransliterator();
// ReplaceableString tSymbol = new ReplaceableString(symbol);
// newTranslit.transliterate(tSymbol);
CollationRule w = (CollationRule)rules.get(symbol);
if (w != null) {
return w.charNumber;
} else {
System.err.print("ERROR: Weight symbol not found: ");
for (int i = 0 ; i < symbol.length(); i++) {
char c = symbol.charAt(i);
System.err.print("\\u");
System.err.print(HEX_DIGIT[(c & 0x0F000) >> 12]); // HEX_DIGIT works for octal
System.err.print(HEX_DIGIT[(c & 0x0F00) >> 8]); // HEX_DIGIT works for octal
System.err.print(HEX_DIGIT[(c & 0x00F0) >> 4]);
System.err.println(HEX_DIGIT[(c & 0x000F)]);
}
System.err.println(" Weight given maximum possible value.");
return Integer.MAX_VALUE;
}
}
// HexToUnicodeTransliterator myTranslit = new HexToUnicodeTransliterator("<U###0>");
public void addRule(String symbol) {
// ReplaceableString tSymbol = new ReplaceableString(symbol);
// myTranslit.transliterate(tSymbol);
if (symbol.length() > 1) {
System.err.println("WARNING: Undefined element '"+symbol+"'. collating-symbol generated.");
symbol = defineWeightSymbol(symbol);
}
order = null;
lastRule = new CollationRule(symbol);
rules.put(symbol, lastRule);
}
public void addRule(CollationRule rule) {
order = null;
lastRule = rule;
rules.put(rule.value, rule);
}
public void addWeight(String weight) {
if (weight.length() > 1) {
//check to see if it's a bogus weight symbol.
weight = map.mapKey(weight);
}
order = null;
lastRule.addWeight(weight);
}
public Enumeration getRules() {
return rules.elements();
}
public SortedVector getSortOrder() {
if (order == null) {
order = new SortedVector(
new Comparator() {
public int compare(final Object i, final Object j) {
final CollationRule o1 = (CollationRule)i;
final CollationRule o2 = (CollationRule)j;
final boolean w1 = o1.isWeightSymbol() != null;
final boolean w2 = o2.isWeightSymbol() != null;
//sort weights first
if (w1 && !w2) {
return -1;
} else if (!w1 && w2) {
return 1;
} else {
return o1.compare(o2);
}
}
}
);
order.addElements(rules.elements());
//remove weight symbols from the list
int i;
for (i = 0; i < order.size(); i++) {
CollationRule r = (CollationRule)order.elementAt(i);
if (r.isWeightSymbol() == null) {
break;
}
}
order.removeElements(0, i);
}
return order;
}
static final char[] HEX_DIGIT = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'};
//{{DECLARE_CONTROLS
//}}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,76 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/QuoteTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class QuoteTransition extends ComplexTransition {
public static final QuoteTransition GLOBAL = new QuoteTransition(SUCCESS);
public static final char STRING_CHAR = '"';
public QuoteTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return STRING_CHAR == (char)c;
}
protected Lex.Transition[][] getStates() {
return states;
}
private static final Lex.Transition[][] states = {
{ //state 0:
new Lex.CharTransition(STRING_CHAR, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal character in quoted string")
},
{ //state 1:
new Lex.CharTransition(STRING_CHAR, Lex.IGNORE_CONSUME, SUCCESS),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_CONSUME, -2),
new EscapeTransition(-1),
new SymbolTransition(-1),
new Lex.EOFTransition(-2),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 2: failure from eof
new Lex.ParseExceptionTransition("unterminated string")
}
};
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new QuoteTransition(SUCCESS),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
EscapeTransition.setEscapeChar('/');
String text = "\"hello<\"/>>/d32world\"\"<one>/\n<two>\"";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
System.out.println(parser.getData());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,47 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/RangeTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class RangeTransition extends ComplexTransition {
public static final RangeTransition GLOBAL = new RangeTransition(SUCCESS);
public static final String RANGE_CHARS = "...";
public RangeTransition(int success){
super(success);
}
public boolean accepts(int c){
return RANGE_CHARS.indexOf((char)c) >=0;
}
protected Lex.Transition[][]getStates(){
return states;
}
private static final Lex.Transition[][] states= {
{ //state 0:
new Lex.StringTransition(RANGE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal space character")
},
{ //state 1:
new Lex.EOFTransition(SUCCESS),
new Lex.StringTransition(RANGE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, SUCCESS)
},
};
}

View file

@ -0,0 +1,356 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/SortedVector.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.util.Vector;
import java.util.Enumeration;
/**
Implements a sorted vector. You can add anything to it; when you access any element, it sorts
the array internally when necessary.
<p>A Comparator is used to compare the elements, allowing arbitrary orderings.
If no Comparator is supplied, then one is constructed based on the type
of the first element added. Only Numbers and Comparables are handled.
<p>Duplicates are allowed.
*/
final public class SortedVector {
/**
Copies elements of vector, enumeration or array
Note: the objects in the source are NOT cloned.
Do not change them or the sorting will be invalid.
*/
public SortedVector(Object[] newValues, Comparator comparator) {
this.comparator = comparator;
addElements(newValues);
//{{INIT_CONTROLS
//}}
}
public SortedVector(Vector newValues, Comparator comparator) {
this.comparator = comparator;
addElements(newValues);
}
public SortedVector(Enumeration newValues, Comparator comparator) {
this.comparator = comparator;
addElements(newValues);
}
public SortedVector(Object[] newValues) {
addElements(newValues);
}
public SortedVector(Comparator comparator) {
this.comparator = comparator;
}
public SortedVector(Vector newValues) {
addElements(newValues);
}
public SortedVector(Enumeration newValues) {
addElements(newValues);
}
public SortedVector() {
}
/**
Adds one element.
*/
public void addElement(Object element) {
if (count >= dataArray.length) setCapacity(count*2 + 17);
dataArray[count++] = element;
isValid = false;
}
/**
Adds multiple elements. Faster than adding one at a time.
*/
public void addElements(Object[] newValues) {
int newCount = count + newValues.length;
if (newCount > dataArray.length) setCapacity(newCount);
for (int i = count; i < newCount; ++i)
dataArray[i] = newValues[i-count];
count = newCount;
isValid = false;
}
public void addElements(Vector newValues) {
int newCount = count + newValues.size();
if (newCount > dataArray.length) setCapacity(newCount);
for (int i = count; i < newCount; ++i)
dataArray[i] = newValues.elementAt(i-count);
count = newCount;
isValid = false;
}
public void addElements(Enumeration newValues) {
while (newValues.hasMoreElements()) {
addElement(newValues.nextElement());
}
}
/**
Removes elements at indices >= startIndex and < endIndex
*/
public void removeElements(int startIndex, int endIndex) {
if (!isValid) validate();
System.arraycopy(dataArray,endIndex,dataArray,startIndex,count - endIndex);
for (int i = count - (endIndex - startIndex); i < count;++i)
dataArray[i] = null; // free up storage
count -= (endIndex - startIndex);
}
/**
Sets comparator
*/
public void setComparator(Comparator comparator) {
this.comparator = comparator;
isValid = false;
}
public Comparator getComparator() {
if (comparator == null) validateComparator();
return this.comparator;
}
/**
Gets size, the actual number of elements.
*/
public int size() {
return count;
}
/**
Gets capacity, the number of elements you can have without growing the array.
*/
public int capacity() {
return dataArray.length;
}
/**
Sets capacity, the number of elements you can have without growing the array.
*/
public void setCapacity(int newSize) {
Object[] temp = new Object[newSize];
System.arraycopy(dataArray, 0, temp, 0, Math.min(count,newSize));
dataArray = temp;
}
/**
Trims the array.
*/
public void trimToSize() {
setCapacity(count);
}
/**
Gets the element at the index
*/
public Object elementAt (int index) {
if (!isValid) validate();
if (index >= count) return dataArray[dataArray.length];
return dataArray[index];
}
/**
Sees whether the vector contains the object
*/
public boolean contains (Object value) {
int index = indexOf(value);
return (index >= 0 && comparator.compare(value,dataArray[index]) == 0);
}
/**
Gets an enumeration
*/
public Enumeration elements() {
if (!isValid) validate();
return new ArrayEnumeration(dataArray,0,count);
}
public void copyInto(Object[] toFill) {
if (!isValid) validate();
System.arraycopy(dataArray,0,toFill,0,toFill.length);
}
/**
Finds first index whose value is greater than or equal to searchValue
If there are none, returns -1
*/
public int indexOf(Object searchValue)
{
if (!isValid) validate();
int index = startIndex;
if (0 <= comparator.compare(searchValue, dataArray[auxStart])) {
index += auxStart;
}
// very fast, completely unrolled binary search
// each case deliberately falls through to the next
switch (power) {
case 31: if (0 > comparator.compare(searchValue, dataArray[index-0x40000000])) index -= 0x40000000;
case 30: if (0 > comparator.compare(searchValue, dataArray[index-0x20000000])) index -= 0x20000000;
case 29: if (0 > comparator.compare(searchValue, dataArray[index-0x10000000])) index -= 0x10000000;
case 28: if (0 > comparator.compare(searchValue, dataArray[index-0x8000000])) index -= 0x8000000;
case 27: if (0 > comparator.compare(searchValue, dataArray[index-0x4000000])) index -= 0x4000000;
case 26: if (0 > comparator.compare(searchValue, dataArray[index-0x2000000])) index -= 0x2000000;
case 25: if (0 > comparator.compare(searchValue, dataArray[index-0x1000000])) index -= 0x1000000;
case 24: if (0 > comparator.compare(searchValue, dataArray[index-0x800000])) index -= 0x800000;
case 23: if (0 > comparator.compare(searchValue, dataArray[index-0x400000])) index -= 0x400000;
case 22: if (0 > comparator.compare(searchValue, dataArray[index-0x200000])) index -= 0x200000;
case 21: if (0 > comparator.compare(searchValue, dataArray[index-0x100000])) index -= 0x100000;
case 20: if (0 > comparator.compare(searchValue, dataArray[index-0x80000])) index -= 0x80000;
case 19: if (0 > comparator.compare(searchValue, dataArray[index-0x40000])) index -= 0x40000;
case 18: if (0 > comparator.compare(searchValue, dataArray[index-0x20000])) index -= 0x20000;
case 17: if (0 > comparator.compare(searchValue, dataArray[index-0x10000])) index -= 0x10000;
case 16: if (0 > comparator.compare(searchValue, dataArray[index-0x8000])) index -= 0x8000;
case 15: if (0 > comparator.compare(searchValue, dataArray[index-0x4000])) index -= 0x4000;
case 14: if (0 > comparator.compare(searchValue, dataArray[index-0x2000])) index -= 0x2000;
case 13: if (0 > comparator.compare(searchValue, dataArray[index-0x1000])) index -= 0x1000;
case 12: if (0 > comparator.compare(searchValue, dataArray[index-0x800])) index -= 0x800;
case 11: if (0 > comparator.compare(searchValue, dataArray[index-0x400])) index -= 0x400;
case 10: if (0 > comparator.compare(searchValue, dataArray[index-0x200])) index -= 0x200;
case 9: if (0 > comparator.compare(searchValue, dataArray[index-0x100])) index -= 0x100;
case 8: if (0 > comparator.compare(searchValue, dataArray[index-0x80])) index -= 0x80;
case 7: if (0 > comparator.compare(searchValue, dataArray[index-0x40])) index -= 0x40;
case 6: if (0 > comparator.compare(searchValue, dataArray[index-0x20])) index -= 0x20;
case 5: if (0 > comparator.compare(searchValue, dataArray[index-0x10])) index -= 0x10;
case 4: if (0 > comparator.compare(searchValue, dataArray[index-0x8])) index -= 8;
case 3: if (0 > comparator.compare(searchValue, dataArray[index-0x4])) index -= 4;
case 2: if (0 > comparator.compare(searchValue, dataArray[index-0x2])) index -= 2;
case 1: if (0 > comparator.compare(searchValue, dataArray[index-0x1])) index -= 1;
case 0: if (0 > comparator.compare(searchValue, dataArray[index])) index -= 1;
}
return index;
}
// ================= privates ==================
/** Only call if comparator is null
*/
private void validateComparator() {
try {
Object trial = dataArray[0];
if (trial instanceof Float || trial instanceof Double) {
comparator = new DoubleComparator();
} else if (trial instanceof Integer) {
comparator = new IntegerComparator();
} else if (trial instanceof Number) {
comparator = new LongComparator();
} else if (trial instanceof String) {
comparator = new StringComparator();
} else {
comparator = new ComparableComparator();
}
} catch (Exception e) {} // leave null
}
private void validate() {
if (isValid) return;
// if the Comparator is null, then pick a reasonable one
if (comparator == null) validateComparator();
// determine search parameters
// find least power of 2 greater than count
for (power = exp2.length-1; power > 0 && count < exp2[power]; power--) {}
// determine the starting point
if (exp2[power] != count) {
auxStart = count - exp2[power];
} else {
auxStart = 0;
}
startIndex = exp2[power]-1;
// shell sort. Later, make this a QuickSort
int lo = 0;
int up = count-1;
for (int step = up - lo + 1; step > 1;) {
if (step < 5)
step = 1;
else step = (5 * step - 1) / 11;
for (int i = up - step; i >= lo; --i) {
Object temp = dataArray[i];
int j;
for (j = i + step; j <= up && 0 > comparator.compare(dataArray[j],temp); j += step)
dataArray[j-step] = dataArray[j];
dataArray[j-step] = temp;
}
}
isValid = true;
}
private Object[] dataArray = new Object[16];
private Comparator comparator;
private int count = 0;
private boolean isValid = false;
private int auxStart;
private int startIndex;
private int power;
private static final int exp2[] = {
0x1, 0x2, 0x4, 0x8,
0x10, 0x20, 0x40, 0x80,
0x100, 0x200, 0x400, 0x800,
0x1000, 0x2000, 0x4000, 0x8000,
0x10000, 0x20000, 0x40000, 0x80000,
0x100000, 0x200000, 0x400000, 0x800000,
0x1000000, 0x2000000, 0x4000000, 0x8000000,
0x10000000, 0x20000000, 0x40000000};
// Utility Classes
public static final class LongComparator implements Comparator {
public int compare(Object a, Object b) {
long aa = ((Number)a).longValue();
long bb = ((Number)b).longValue();
return (aa < bb ? -1 : aa > bb ? 1 : 0);
}
}
public static final class IntegerComparator implements Comparator {
public int compare(Object a, Object b) {
return (((Number)a).intValue() - ((Number)b).intValue());
}
}
public static final class DoubleComparator implements Comparator {
public int compare(Object a, Object b) {
double aa = ((Number)a).doubleValue();
double bb = ((Number)b).doubleValue();
return (aa < bb ? -1 : aa > bb ? 1 : 0);
}
}
public static final class ComparableComparator implements Comparator {
public int compare(Object a, Object b) {
return ((Comparable)a).compareTo(b);
}
}
public static final class StringComparator implements Comparator {
public int compare(Object a, Object b) {
return ((String)a).compareTo((String)b);
};
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,46 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/SpaceTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class SpaceTransition extends ComplexTransition {
public static final SpaceTransition GLOBAL = new SpaceTransition(SUCCESS);
public static final String SPACE_CHARS = " \t";
public SpaceTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return SPACE_CHARS.indexOf((char)c) >= 0;
}
protected Lex.Transition[][] getStates() {
return states;
}
private static final Lex.Transition[][] states = {
{ //state 0:
new Lex.StringTransition(SPACE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal space character")
},
{ //state 1:
new Lex.EOFTransition(SUCCESS),
new Lex.StringTransition(SPACE_CHARS, Lex.IGNORE_CONSUME, -1),
new Lex.DefaultTransition(Lex.IGNORE_PUTBACK, SUCCESS)
},
};
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,103 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/SymbolTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class SymbolTransition extends ComplexTransition {
private static PosixCharMap mapping = new PosixCharMap();
public static final SymbolTransition GLOBAL = new SymbolTransition(SUCCESS);
public static void setCharMap(PosixCharMap mappingIn) {
mapping = mappingIn;
if (mapping == null) {
mapping = new PosixCharMap();
}
}
public static PosixCharMap getCharMap() {
return mapping;
}
public SymbolTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return '<' == (char)c;
}
protected void handleSuccess(Lex parser, StringBuffer output) {
String text = parser.getData();
String mappedText = mapping.mapKey(text);
if (mappedText != null) {
output.append(mappedText);
} else {
output.append(text);
}
}
protected Lex.Transition[][] getStates() {
synchronized (getClass()) {
if (states == null) {
states = new Lex.Transition[][] {
{ //state 0:
new Lex.CharTransition('<', Lex.ACCUMULATE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal characters in symbol")
},
{ //state 1:
new Lex.CharTransition('/', Lex.ACCUMULATE_CONSUME, -2),
new Lex.CharTransition('>', Lex.ACCUMULATE_CONSUME, SUCCESS),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, -3),
new Lex.EOFTransition(-3),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 2:
new Lex.CharTransition('>', Lex.ACCUMULATE_CONSUME, -1),
new Lex.CharTransition('/', Lex.ACCUMULATE_CONSUME, -1),
new Lex.ParseExceptionTransition("illegal escape character in symbol")
},
{ //state 3: failure
new Lex.ParseExceptionTransition("unexpected end of line/file")
}
};
}
}
return states;
}
private static Lex.Transition[][] states;
public static void main(String args[]) {
try {
Lex.Transition[][] states = {{
new SymbolTransition(SUCCESS),
new Lex.EOFTransition(),
new Lex.ParseExceptionTransition("bad test input")
}};
//String text = "<CAPITAL><\"<><//><V%><N6><CYRILLIC>";
String text = "<U><S><D> ";
StringReader sr = new StringReader(text);
PushbackReader pr = new PushbackReader(sr);
Lex parser = new Lex(states, pr);
//parser.debug(true);
int s = parser.nextToken();
while (s == SUCCESS) {
System.out.println(parser.getData());
s = parser.nextToken();
}
} catch (Exception e) {
System.out.println(e);
}
}
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,72 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/TokenTransition.java,v $
* $Date: 2002/01/31 01:22:25 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.tools.localeconverter;
import java.io.*;
import java.util.*;
public class TokenTransition extends ComplexTransition {
public static final TokenTransition GLOBAL = new TokenTransition(SUCCESS);
public static final String SEPARATOR_CHARS = ";" + SpaceTransition.SPACE_CHARS;
public TokenTransition(int success) {
super(success);
//{{INIT_CONTROLS
//}}
}
public boolean accepts(int c) {
return (c > 0) &&
!EOLTransition.GLOBAL.accepts(c) &&
!SpaceTransition.GLOBAL.accepts(c) &&
(
(SEPARATOR_CHARS.indexOf((char)c) < 0) ||
SymbolTransition.GLOBAL.accepts(c) ||
QuoteTransition.GLOBAL.accepts(c) ||
EscapeTransition.GLOBAL.accepts(c)
);
}
protected Lex.Transition[][] getStates() {
return states;
}
private static final Lex.Transition[][] states = {
{ //state 0:
new SymbolTransition(-1),
new QuoteTransition(-1),
new EscapeTransition(-1),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, -2),
new Lex.StringTransition(SEPARATOR_CHARS, Lex.IGNORE_PUTBACK, -3),
new Lex.EOFTransition(-4),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 1:
new SymbolTransition(-1),
new QuoteTransition(-1),
new EscapeTransition(-1),
new Lex.StringTransition(EOLTransition.EOL_CHARS, Lex.IGNORE_PUTBACK, SUCCESS),
new Lex.StringTransition(SEPARATOR_CHARS, Lex.IGNORE_PUTBACK, SUCCESS),
new Lex.EOFTransition(SUCCESS),
new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME, -1)
},
{ //state 2: failure - unexpected EOL
new Lex.ParseExceptionTransition("unexpected EOL in token")
},
{ //state 3: failure
new Lex.ParseExceptionTransition("unexpected seperator character in token")
},
{ //state 4: failure
new Lex.ParseExceptionTransition("unexpected EOF in token")
},
};
//{{DECLARE_CONTROLS
//}}
}

View file

@ -0,0 +1,603 @@
/*
*******************************************************************************
* Copyright (C) 2002-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/tools/localeconverter/Attic/myLocaleElements.java,v $
* $Date: 2002/01/31 01:22:21 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
/*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
*
* Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
*
*/
/**
*
* Table of Java supplied standard locale elements
*
* automatically generated by java LocaleTool LocaleElements.java
*
* Date Created: Wed Aug 21 15:47:57 1996
*
* Locale Elements and Patterns: last update 10/23/96
*
*
*/
// WARNING : the format of this file will change in the future!
package com.ibm.tools.localeconverter;
import java.util.ListResourceBundle;
public class myLocaleElements extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "LocaleString", "en_US" }, // locale id based on iso codes
{ "LocaleID", "0409" }, // Windows id
{ "ShortLanguage", "eng" }, // iso-3 abbrev lang name
{ "ShortCountry", "USA" }, // iso-3 abbrev country name
{ "Languages", // language names
new String[][] {
{ "ab", "Abkhazian" },
{ "aa", "Afar" },
{ "af", "Afrikaans" },
{ "sq", "Albanian" },
{ "am", "Amharic" },
{ "ar", "Arabic" },
{ "hy", "Armenian" },
{ "as", "Assamese" },
{ "ay", "Aymara" },
{ "az", "Azerbaijani" },
{ "ba", "Bashkir" },
{ "eu", "Basque" },
{ "bn", "Bengali" },
{ "dz", "Bhutani" },
{ "bh", "Bihari" },
{ "bi", "Bislama" },
{ "br", "Breton" },
{ "bg", "Bulgarian" },
{ "my", "Burmese" },
{ "be", "Byelorussian" },
{ "km", "Cambodian" },
{ "ca", "Catalan" },
{ "zh", "Chinese" },
{ "co", "Corsican" },
{ "hr", "Croatian" },
{ "cs", "Czech" },
{ "da", "Danish" },
{ "nl", "Dutch" },
{ "en", "English" },
{ "eo", "Esperanto" },
{ "et", "Estonian" },
{ "fo", "Faeroese" },
{ "fj", "Fiji" },
{ "fi", "Finnish" },
{ "fr", "French" },
{ "fy", "Frisian" },
{ "gl", "Galician" },
{ "ka", "Georgian" },
{ "de", "German" },
{ "el", "Greek" },
{ "kl", "Greenlandic" },
{ "gn", "Guarani" },
{ "gu", "Gujarati" },
{ "ha", "Hausa" },
{ "iw", "Hebrew" },
{ "hi", "Hindi" },
{ "hu", "Hungarian" },
{ "is", "Icelandic" },
{ "in", "Indonesian" },
{ "ia", "Interlingua" },
{ "ie", "Interlingue" },
{ "ik", "Inupiak" },
{ "ga", "Irish" },
{ "it", "Italian" },
{ "ja", "Japanese" },
{ "jw", "Javanese" },
{ "kn", "Kannada" },
{ "ks", "Kashmiri" },
{ "kk", "Kazakh" },
{ "rw", "Kinyarwanda" },
{ "ky", "Kirghiz" },
{ "rn", "Kirundi" },
{ "ko", "Korean" },
{ "ku", "Kurdish" },
{ "lo", "Laothian" },
{ "la", "Latin" },
{ "lv", "Latvian (Lettish)" },
{ "ln", "Lingala" },
{ "lt", "Lithuanian" },
{ "mk", "Macedonian" },
{ "mg", "Malagasy" },
{ "ms", "Malay" },
{ "ml", "Malayalam" },
{ "mt", "Maltese" },
{ "mi", "Maori" },
{ "mr", "Marathi" },
{ "mo", "Moldavian" },
{ "mn", "Mongolian" },
{ "na", "Nauru" },
{ "ne", "Nepali" },
{ "no", "Norwegian" },
{ "oc", "Occitan" },
{ "or", "Oriya" },
{ "om", "Oromo (Afan)" },
{ "ps", "Pashto (Pushto)" },
{ "fa", "Persian" },
{ "pl", "Polish" },
{ "pt", "Portuguese" },
{ "pa", "Punjabi" },
{ "qu", "Quechua" },
{ "rm", "Rhaeto-Romance" },
{ "ro", "Romanian" },
{ "ru", "Russian" },
{ "sm", "Samoan" },
{ "sg", "Sangro" },
{ "sa", "Sanskrit" },
{ "gd", "Scots Gaelic" },
{ "sr", "Serbian" },
{ "sh", "Serbo-Croatian" },
{ "st", "Sesotho" },
{ "tn", "Setswana" },
{ "sn", "Shona" },
{ "sd", "Sindhi" },
{ "si", "Singhalese" },
{ "ss", "Siswati" },
{ "sk", "Slovak" },
{ "sl", "Slovenian" },
{ "so", "Somali" },
{ "es", "Spanish" },
{ "su", "Sundanese" },
{ "sw", "Swahili" },
{ "sv", "Swedish" },
{ "tl", "Tagalog" },
{ "tg", "Tajik" },
{ "ta", "Tamil" },
{ "tt", "Tatar" },
{ "te", "Telugu" },
{ "th", "Thai" },
{ "bo", "Tibetan" },
{ "ti", "Tigrinya" },
{ "to", "Tonga" },
{ "ts", "Tsonga" },
{ "tr", "Turkish" },
{ "tk", "Turkmen" },
{ "tw", "Twi" },
{ "uk", "Ukrainian" },
{ "ur", "Urdu" },
{ "uz", "Uzbek" },
{ "vi", "Vietnamese" },
{ "vo", "Volapuk" },
{ "cy", "Welsh" },
{ "wo", "Wolof" },
{ "xh", "Xhosa" },
{ "ji", "Yiddish" },
{ "yo", "Yoruba" },
{ "zu", "Zulu" }
}
},
{ "Countries", // country names
new String[][] {
{ "AF", "Afghanistan" },
{ "AL", "Albania" },
{ "DZ", "Algeria" },
{ "AD", "Andorra" },
{ "AO", "Angola" },
{ "AI", "Anguilla" },
{ "AR", "Argentina" },
{ "AM", "Armenia" },
{ "AW", "Aruba" },
{ "AU", "Australia" },
{ "AT", "Austria" },
{ "AZ", "Azerbaijan" },
{ "BS", "Bahamas" },
{ "BH", "Bahrain" },
{ "BD", "Bangladesh" },
{ "BB", "Barbados" },
{ "BY", "Belarus" },
{ "BE", "Belgium" },
{ "BZ", "Belize" },
{ "BJ", "Benin" },
{ "BM", "Bermuda" },
{ "BT", "Bhutan" },
{ "BO", "Bolivia" },
{ "BA", "Bosnia and Herzegovina" },
{ "BW", "Botswana" },
{ "BR", "Brazil" },
{ "BN", "Brunei Darussalam" },
{ "BG", "Bulgaria" },
{ "BF", "Burkina Faso" },
{ "BI", "Burundi" },
{ "KH", "Cambodia" },
{ "CM", "Cameroon" },
{ "CA", "Canada" },
{ "CV", "Cape Verde" },
{ "CF", "Central African Republic" },
{ "TD", "Chad" },
{ "CL", "Chile" },
{ "CN", "China" },
{ "CO", "Colombia" },
{ "KM", "Comoros" },
{ "CG", "Congo" },
{ "CR", "Costa Rica" },
{ "CI", "Cote D'ivoire" },
{ "HR", "Croatia" },
{ "CU", "Cuba" },
{ "CY", "Cyprus" },
{ "CZ", "Czech Republic" },
{ "DK", "Denmark" },
{ "DJ", "Djibouti" },
{ "DM", "Dominica" },
{ "DO", "Dominican Republic" },
{ "TP", "East Timor" },
{ "EC", "Ecuador" },
{ "EG", "Egypt" },
{ "SV", "El Salvador" },
{ "GQ", "Equatorial Guinea" },
{ "ER", "Eritrea" },
{ "EE", "Estonia" },
{ "ET", "Ethiopia" },
{ "FJ", "Fiji" },
{ "FI", "Finland" },
{ "FR", "France" },
{ "GF", "French Guiana" },
{ "PF", "French Polynesia" },
{ "TF", "French Southern Territories" },
{ "GA", "Gabon" },
{ "GM", "Gambia" },
{ "GE", "Georgia" },
{ "DE", "Germany" },
{ "GH", "Ghana" },
{ "GR", "Greece" },
{ "GP", "Guadeloupe" },
{ "GT", "Guatemala" },
{ "GN", "Guinea" },
{ "GW", "Guinea-Bissau" },
{ "GY", "Guyana" },
{ "HT", "Haiti" },
{ "HN", "Honduras" },
{ "HK", "Hong Kong" },
{ "HU", "Hungary" },
{ "IS", "Iceland" },
{ "IN", "India" },
{ "ID", "Indonesia" },
{ "IR", "Iran" },
{ "IQ", "Iraq" },
{ "IE", "Ireland" },
{ "IL", "Israel" },
{ "IT", "Italy" },
{ "JM", "Jamaica" },
{ "JP", "Japan" },
{ "JO", "Jordan" },
{ "KZ", "Kazakhstan" },
{ "KE", "Kenya" },
{ "KI", "Kiribati" },
{ "KP", "North Korea" },
{ "KR", "South Korea" },
{ "KW", "Kuwait" },
{ "KG", "Kyrgyzstan" },
{ "LA", "Laos" },
{ "LV", "Latvia" },
{ "LB", "Lebanon" },
{ "LS", "Lesotho" },
{ "LR", "Liberia" },
{ "LY", "Libyan Arab Jamahiriya" },
{ "LI", "Liechtenstein" },
{ "LT", "Lithuania" },
{ "LU", "Luxembourg" },
{ "MK", "Macedonia" },
{ "MG", "Madagascar" },
{ "MY", "Malaysia" },
{ "ML", "Mali" },
{ "MT", "Malta" },
{ "MQ", "Martinique" },
{ "MR", "Mauritania" },
{ "MU", "Mauritius" },
{ "YT", "Mayotte" },
{ "MX", "Mexico" },
{ "FM", "Micronesia" },
{ "MD", "Moldova" },
{ "MC", "Monaco" },
{ "MN", "Mongolia" },
{ "MS", "Montserrat" },
{ "MA", "Morocco" },
{ "MZ", "Mozambique" },
{ "MM", "Myanmar" },
{ "NA", "Namibia" },
{ "NP", "Nepal" },
{ "NL", "Netherlands" },
{ "AN", "Netherlands Antilles" },
{ "NC", "New Caledonia" },
{ "NZ", "New Zealand" },
{ "NI", "Nicaragua" },
{ "NE", "Niger" },
{ "NG", "Nigeria" },
{ "NU", "Niue" },
{ "NO", "Norway" },
{ "OM", "Oman" },
{ "PK", "Pakistan" },
{ "PA", "Panama" },
{ "PG", "Papua New Guinea" },
{ "PY", "Paraguay" },
{ "PE", "Peru" },
{ "PH", "Philippines" },
{ "PL", "Poland" },
{ "PT", "Portugal" },
{ "PR", "Puerto Rico" },
{ "QA", "Qatar" },
{ "RO", "Romania" },
{ "RU", "Russian Federation" },
{ "RW", "Rwanda" },
{ "SA", "Saudi Arabia" },
{ "SN", "Senegal" },
{ "SP", "Serbia" },
{ "SC", "Seychelles" },
{ "SL", "Sierra Leone" },
{ "SG", "Singapore" },
{ "SK", "Slovakia" },
{ "SI", "Slovenia" },
{ "SO", "Somalia" },
{ "ZA", "South Africa" },
{ "ES", "Spain" },
{ "LK", "Sri Lanka" },
{ "SD", "Sudan" },
{ "SR", "Suriname" },
{ "SZ", "Swaziland" },
{ "SE", "Sweden" },
{ "CH", "Switzerland" },
{ "SY", "Syria" },
{ "TW", "Taiwan" },
{ "TJ", "Tajikistan" },
{ "TZ", "Tanzania" },
{ "TH", "Thailand" },
{ "TG", "Togo" },
{ "TK", "Tokelau" },
{ "TO", "Tonga" },
{ "TT", "Trinidad and Tobago" },
{ "TN", "Tunisia" },
{ "TR", "Turkey" },
{ "TM", "Turkmenistan" },
{ "UG", "Uganda" },
{ "UA", "Ukraine" },
{ "AE", "United Arab Emirates" },
{ "GB", "United Kingdom" },
{ "US", "United States" },
{ "UY", "Uruguay" },
{ "UZ", "Uzbekistan" },
{ "VU", "Vanuatu" },
{ "VA", "Vatican" },
{ "VE", "Venezuela" },
{ "VN", "Viet Nam" },
{ "VG", "British Virgin Islands" },
{ "VI", "U.S. Virgin Islands" },
{ "EH", "Western Sahara" },
{ "YE", "Yemen" },
{ "YU", "Yugoslavia" },
{ "ZR", "Zaire" },
{ "ZM", "Zambia" },
{ "ZW", "Zimbabwe" }
}
},
{ "%%EURO", "Euro" }, // Euro variant display name
{ "LocaleNamePatterns",
/* Formats for the display name of a locale, for a list of
* items, and for composing two items in a list into one item.
* The list patterns are used in the variant name and in the
* full display name.
*/
new String[] {
"{0,choice,0#|1#{1}|2#{1} ({2})}", // Display name
"{0,choice,0#|1#{1}|2#{1},{2}|3#{1},{2},{3}}", // List
"{0},{1}" // List composition
}
},
{ "MonthNames",
new String[] {
"January", // january
"February", // february
"March", // march
"April", // april
"May", // may
"June", // june
"July", // july
"August", // august
"September", // september
"October", // october
"November", // november
"December", // december
"" // month 13 if applicable
}
},
{ "MonthAbbreviations",
new String[] {
"Jan", // abb january
"Feb", // abb february
"Mar", // abb march
"Apr", // abb april
"May", // abb may
"Jun", // abb june
"Jul", // abb july
"Aug", // abb august
"Sep", // abb september
"Oct", // abb october
"Nov", // abb november
"Dec", // abb december
"" // abb month 13 if applicable
}
},
{ "DayNames",
new String[] {
"Sunday", // Sunday
"Monday", // Monday
"Tuesday", // Tuesday
"Wednesday", // Wednesday
"Thursday", // Thursday
"Friday", // Friday
"Saturday" // Saturday
}
},
{ "DayAbbreviations",
new String[] {
"Sun", // abb Sunday
"Mon", // abb Monday
"Tue", // abb Tuesday
"Wed", // abb Wednesday
"Thu", // abb Thursday
"Fri", // abb Friday
"Sat" // abb Saturday
}
},
{ "AmPmMarkers",
new String[] {
"AM", // am marker
"PM" // pm marker
}
},
{ "Eras",
new String[] { // era strings
"BC",
"AD"
}
},
{ "NumberPatterns",
new String[] {
"#,##0.###;-#,##0.###", // decimal pattern
"$#,##0.00;($#,##0.00)", // currency pattern
"#,##0%" // percent pattern
}
},
{ "NumberElements",
new String[] {
".", // decimal separator
",", // group (thousands) separator
";", // list separator
"%", // percent sign
"0", // native 0 digit
"#", // pattern digit
"-", // minus sign
"E", // exponential
"\u2030", // per mille
"\u221e", // infinity
"\ufffd" // NaN
}
},
{ "CurrencyElements",
new String[] {
"$", // local currency symbol
"USD", // intl currency symbol
"." // monetary decimal separator
}
},
{ "DateTimePatterns",
new String[] {
"h:mm:ss 'o''''clock' a z", // full time pattern
"h:mm:ss a z", // long time pattern
"h:mm:ss a", // medium time pattern
"h:mm a", // short time pattern
"EEEE, MMMM d, yyyy", // full date pattern
"MMMM d, yyyy", // long date pattern
"dd-MMM-yy", // medium date pattern
"M/d/yy", // short date pattern
"{1} {0}" // date-time pattern
}
},
{ "DateTimeElements",
new String[] {
"1", // first day of week
"1" // min days in first week
}
},
{ "CollationElements",new String[][]{
{"Version","1.0"},
{"Overide","false"},
{"Sequence",""}
}
},
{ "Measurement" ,""},
{ "CountryNumber" , ""},
{ "CountryISBNNumber" , ""},
{ "LanguageLibraryUse" , ""},
{ "PaperSize", new String[][]{
{"Hieght",""},
{"Width",""},
{"Units", ""}
}
},
{ "Messages" , new String[][] {
{"yesExpression",""}, /* yes expression */
{"noExpression",""} /* no expression */
}
},
{ "AddressFormat", new String[][]{
{"PostalFormat",""},
}
},
{"NameFormat", new String[][]{
{"NamePattern",""},
{"GeneralSalutaion", ""},
{"ShortSalutationMr", ""},
{"ShortSalutationMiss",""},
{"ShortSalutationMrs",""},
{"LongSalutationMr",""},
{"LongSalutationMiss",""},
{"LongSalutationMrs",""}
}
},
{ "Identification", new String[][]{
{"Title",""},
{"Source",""},
{"Address",""},
{"Contact",""},
{"Email",""},
{"Telephone", ""},
{"Fax", ""},
{"Language",""},
{"Territory",""},
{"Audience", ""},
{"Application", ""},
{"Abbreviation", ""},
{"Revision", ""},
{"Date",""}
}
},
{ "TelephoneFormat", new String[][]{
{"InternationalFormat",""},
{"DomesticFormat",""},
{"InternationalDialCode",""},
{"InternationalPrefix",""}
}
}
};
}
}