This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
Patch: aliases for encoding names
- To: Java Patch List <java-patches at sourceware dot cygnus dot com>
- Subject: Patch: aliases for encoding names
- From: Tom Tromey <tromey at cygnus dot com>
- Date: 02 Aug 2000 14:07:55 -0600
- Reply-To: tromey at cygnus dot com
I'm checking this in. This adds an aliasing capability to our
encoders and decoders. Most of the aliases are generated from the
IANA table; I've included a script to download and regenerate that
code.
2000-08-02 Tom Tromey <tromey@cygnus.com>
* scripts/encodings.pl: New file.
* Makefile.in: Rebuilt.
* Makefile.am (convert_source_files): Added IOConverter.java.
* gnu/gcj/convert/UnicodeToBytes.java (UnicodeToBytes): Extend
IOConverter.
(getDefaultDecodingClass): Canonicalize default encoding name.
(getEncoder): Likewise.
* gnu/gcj/convert/BytesToUnicode.java (BytesToUnicode): Extend
IOConverter.
(getDefaultDecodingClass): Canonicalize default encoding name.
(getDecoder): Likewise.
* gnu/gcj/convert/IOConverter.java: New file.
Tom
Index: Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.am,v
retrieving revision 1.73
diff -u -r1.73 Makefile.am
--- Makefile.am 2000/08/02 03:25:12 1.73
+++ Makefile.am 2000/08/02 19:53:32
@@ -473,6 +473,7 @@
gnu/gcj/convert/Input_SJIS.java \
gnu/gcj/convert/Input_UTF8.java \
gnu/gcj/convert/Input_iconv.java \
+gnu/gcj/convert/IOConverter.java \
gnu/gcj/convert/Output_8859_1.java \
gnu/gcj/convert/Output_EUCJIS.java \
gnu/gcj/convert/Output_JavaSrc.java \
@@ -494,8 +495,8 @@
java/awt/AWTException.java \
java/awt/ActiveEvent.java \
java/awt/Adjustable.java \
-java/awt/Button.java \
java/awt/BorderLayout.java \
+java/awt/Button.java \
java/awt/CheckboxGroup.java \
java/awt/Color.java \
java/awt/Component.java \
Index: gnu/gcj/convert/BytesToUnicode.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/gnu/gcj/convert/BytesToUnicode.java,v
retrieving revision 1.6
diff -u -r1.6 BytesToUnicode.java
--- BytesToUnicode.java 2000/03/07 19:55:24 1.6
+++ BytesToUnicode.java 2000/08/02 19:53:34
@@ -8,7 +8,7 @@
package gnu.gcj.convert;
-public abstract class BytesToUnicode
+public abstract class BytesToUnicode extends IOConverter
{
/** Buffer to read bytes from.
* The characters inbuffer[inpos] ... inbuffer[inlength-1] are available. */
@@ -25,7 +25,7 @@
// Test (defaultDecodingClass == null) again in case of race condition.
if (defaultDecodingClass == null)
{
- String encoding = System.getProperty("file.encoding");
+ String encoding = canonicalize (System.getProperty("file.encoding"));
String className = "gnu.gcj.convert.Input_"+encoding;
try
{
@@ -60,7 +60,7 @@
public static BytesToUnicode getDecoder (String encoding)
throws java.io.UnsupportedEncodingException
{
- String className = "gnu.gcj.convert.Input_"+encoding;
+ String className = "gnu.gcj.convert.Input_" + canonicalize (encoding);
Class decodingClass;
try
{
@@ -71,6 +71,8 @@
{
try
{
+ // We pass the original name to iconv and let it handle
+ // its own aliasing.
return new Input_iconv (encoding);
}
catch (Throwable _)
Index: gnu/gcj/convert/IOConverter.java
===================================================================
RCS file: IOConverter.java
diff -N IOConverter.java
--- /dev/null Tue May 5 13:32:27 1998
+++ IOConverter.java Wed Aug 2 12:53:34 2000
@@ -0,0 +1,52 @@
+/* Copyright (C) 2000 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+/* This is a base class that handles aliasing issues for
+ UnicodeToBytes to BytesToUnicode. */
+
+package gnu.gcj.convert;
+
+import java.util.Hashtable;
+
+public abstract class IOConverter
+{
+ // Map encoding aliases to our canonical form.
+ static private Hashtable hash = new Hashtable ();
+
+ static
+ {
+ // Manually maintained aliases. Note that the value must be our
+ // canonical name.
+ hash.put ("ISO-Latin-1", "8859_1");
+ // All aliases after this point are automatically generated by the
+ // `encodings.pl' script. Run it to make any corrections.
+ hash.put ("ISO_8859-1:1987", "8859_1");
+ hash.put ("iso-ir-100", "8859_1");
+ hash.put ("ISO_8859-1", "8859_1");
+ hash.put ("ISO-8859-1", "8859_1");
+ hash.put ("latin1", "8859_1");
+ hash.put ("l1", "8859_1");
+ hash.put ("IBM819", "8859_1");
+ hash.put ("CP819", "8859_1");
+ hash.put ("csISOLatin1", "8859_1");
+ hash.put ("UTF-8", "UTF8");
+ hash.put ("Shift_JIS", "SJIS");
+ hash.put ("MS_Kanji", "SJIS");
+ hash.put ("csShiftJIS", "SJIS");
+ hash.put ("Extended_UNIX_Code_Packed_Format_for_Japanese", "EUCJIS");
+ hash.put ("csEUCPkdFmtJapanese", "EUCJIS");
+ hash.put ("EUC-JP", "EUCJIS");
+ }
+
+ // Turn an alias into the canonical form.
+ protected static final String canonicalize (String name)
+ {
+ String c = (String) hash.get (name);
+ return c == null ? name : c;
+ }
+}
Index: gnu/gcj/convert/UnicodeToBytes.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/gnu/gcj/convert/UnicodeToBytes.java,v
retrieving revision 1.5
diff -u -r1.5 UnicodeToBytes.java
--- UnicodeToBytes.java 2000/03/07 19:55:24 1.5
+++ UnicodeToBytes.java 2000/08/02 19:53:34
@@ -8,7 +8,7 @@
package gnu.gcj.convert;
-public abstract class UnicodeToBytes
+public abstract class UnicodeToBytes extends IOConverter
{
/** Buffer to emit bytes to.
* The locations buf[count] ... buf[buf.length-1] are available. */
@@ -22,7 +22,7 @@
// Test (defaultEncodingClass == null) again in case of race condition.
if (defaultEncodingClass == null)
{
- String encoding = System.getProperty("file.encoding");
+ String encoding = canonicalize (System.getProperty("file.encoding"));
String className = "gnu.gcj.convert.Output_"+encoding;
try
{
@@ -58,7 +58,7 @@
public static UnicodeToBytes getEncoder (String encoding)
throws java.io.UnsupportedEncodingException
{
- String className = "gnu.gcj.convert.Output_"+encoding;
+ String className = "gnu.gcj.convert.Output_" + canonicalize (encoding);
Class encodingClass;
try
{
@@ -69,6 +69,8 @@
{
try
{
+ // We pass the original name to iconv and let it handle
+ // its own aliasing.
return new Output_iconv (encoding);
}
catch (Throwable _)
Index: scripts/encodings.pl
===================================================================
RCS file: encodings.pl
diff -N encodings.pl
--- /dev/null Tue May 5 13:32:27 1998
+++ encodings.pl Wed Aug 2 12:53:34 2000
@@ -0,0 +1,62 @@
+# encodings.pl - Download IANA text and compute alias list.
+# Assumes you are running this program from gnu/gcj/convert/.
+# Output suitable for direct inclusion in IOConverter.java.
+
+# Map IANA canonical names onto our canonical names.
+%map = (
+ 'ISO_8859-1:1987' => '8859_1',
+ 'UTF-8' => 'UTF8',
+ 'Shift_JIS' => 'SJIS',
+ 'Extended_UNIX_Code_Packed_Format_for_Japanese' => 'EUCJIS'
+ );
+
+if ($ARGV[0] eq '')
+{
+ $file = 'character-sets';
+ if (! -f $file)
+ {
+ # Too painful to figure out how to get Perl to do it.
+ system 'wget -o .wget-log http://www.isi.edu/in-notes/iana/assignments/character-sets';
+ }
+}
+else
+{
+ $file = $ARGV[0];
+}
+
+open (INPUT, "< $file") || die "couldn't open $file: $!";
+
+$body = 0;
+$current = '';
+while (<INPUT>)
+{
+ chop;
+ $body = 1 if /^Name:/;
+ next unless $body;
+
+ if (/^$/)
+ {
+ $current = '';
+ next;
+ }
+
+ ($type, $name) = split (/\s+/);
+ if ($type eq 'Name:')
+ {
+ $current = $map{$name};
+ if ($current)
+ {
+ print " hash.put (\"$name\", \"$current\");\n";
+ }
+ }
+ elsif ($type eq 'Alias:')
+ {
+ # The IANA list has some ugliness.
+ if ($name ne '' && $name ne 'NONE' && $current)
+ {
+ print " hash.put (\"$name\", \"$current\");\n";
+ }
+ }
+}
+
+close (INPUT);