Patch for zone ordering and separators in JavaGenerator
[email protected] Mon, 31 Jan 2005 02:35:34 +0000
| Newsgroups | gmane.comp.java.classpath.tools.cvs |
|---|---|
| Message-ID | <[email protected]> |
I'm committing the attached patch which fixes two issues in JavaGenerator: * The ordering of zone strings is wrong, as pointed out by Ito on the Classpath list. This patch ensures that the ID is first not last. * In addition, the zone string parsing now ignores zones which produce an ID and a series of empty strings (as the XML data only contains the localized examplar city name). If a full set of these is found, no zone data is added. * The separator added by Mark has been changed from | to \u00A6 (the same character, with a break in the center). This allows root.xml to again be parsed. Changelog: 2005-01-31 Andrew John Hughes <[email protected]> * src/gnu/localegen/JavaGenerator.java: (JavaGenerator.JavaContent.isUsable()): New method to check for usability of parsed content. Implementations returning true are added to all but the implementation below. (JavaGenerator.TimeZoneContent.isUsable()): Returns the value of the usability variable, which may be set true during generation. (JavaGenerator.TimeZoneContent.generateContent(java.io.PrintWriter)): Content is now written to a pair of buffers, one for each individual set of data, and one for the whole block. These are only printed if usable data is found. The ID is also now used first. (JavaGenerator.HashtableContent.generateContent(java.io.PrintWriter)): \u00A6 is now used as the separator character to avoid conflicts. -- Andrew :-) Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments. See http://www.fsf.org/philosophy/no-word-attachments.html No software patents in Europe -- http://nosoftwarepatents.com "Value your freedom, or you will lose it, teaches history. `Don't bother us with politics' respond those who don't want to learn." -- Richard Stallman "We've all been part of the biggest beta test the world has ever known -- Windows" -- Victor Wheatman, Gartner _______________________________________________ Cp-tools-commit mailing list [email protected] http://lists.gnu.org/mailman/listinfo/cp-tools-commit
zones_and_sep.diff
(text/plain, 6.6 KB)
Index: src/gnu/localegen/JavaGenerator.java
===================================================================
RCS file: /cvsroot/classpath/cp-tools/src/gnu/localegen/JavaGenerator.java,v
retrieving revision 1.24
diff -u -3 -p -u -r1.24 JavaGenerator.java
--- src/gnu/localegen/JavaGenerator.java 30 Jan 2005 02:33:09 -0000 1.24
+++ src/gnu/localegen/JavaGenerator.java 31 Jan 2005 01:39:32 -0000
@@ -68,6 +68,8 @@ public class JavaGenerator
boolean isPackage();
void generateContent(PrintWriter o);
+
+ boolean isUsable();
}
/*
@@ -137,6 +139,11 @@ public class JavaGenerator
public void generateContent(PrintWriter o)
{
}
+
+ public boolean isUsable()
+ {
+ return true;
+ }
}
/*
@@ -194,6 +201,11 @@ public class JavaGenerator
}
o.println("\";");
}
+
+ public boolean isUsable()
+ {
+ return true;
+ }
}
/*
@@ -238,6 +250,11 @@ public class JavaGenerator
}
o.println(" };");
}
+
+ public boolean isUsable()
+ {
+ return true;
+ }
}
/*
@@ -298,15 +315,22 @@ public class JavaGenerator
o.println(" null,");
o.println(" };");
}
+
+ public boolean isUsable()
+ {
+ return true;
+ }
}
class TimeZoneContent implements JavaContent
{
ListDataElement listElt;
+ boolean usable;
public TimeZoneContent(ListDataElement elt)
{
this.listElt = elt;
+ usable = false;
}
public boolean isPackage()
@@ -327,28 +351,56 @@ public class JavaGenerator
public void generateContent(PrintWriter o)
{
Enumeration keys = listElt.listData.keys();
- o.println(" private static final String[][] zoneStrings =");
- o.println(" {");
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append(" private static final String[][] zoneStrings =\n");
+ buffer.append(" {\n");
+
while (keys.hasMoreElements())
- {
- String zoneName = (String) keys.nextElement();
- Hashtable zoneTable;
- Iterator allValues;
- DataElement zoneData;
- o.print(" { ");
- zoneTable = listElt.flattenLeaf(zoneName);
- for (int j = 0; j < classpathZoneOrder.length; j++)
- {
- zoneData = (DataElement) zoneTable.get(classpathZoneOrder[j]);
- if (zoneData != null)
- o.print("\"" + convertToJavaString(zoneData.data) + "\", ");
- else
- /* TODO: Emit a warning here "Insufficient data" */
- o.print("\"\", ");
- }
- o.println(" \"" + zoneName + "\" },");
- }
- o.println(" };");
+ {
+ String zoneName = (String)keys.nextElement();
+ Hashtable zoneTable;
+ Iterator allValues;
+ DataElement zoneData;
+ StringBuffer buffer2 = new StringBuffer();
+ boolean zoneDataFound = false;
+
+ buffer2.append(" { ");
+
+ buffer2.append(" \"" + zoneName + "\", ");
+
+ zoneTable = listElt.flattenLeaf(zoneName);
+ for (int j = 0; j < classpathZoneOrder.length; j++)
+ {
+ zoneData = (DataElement)zoneTable.get(classpathZoneOrder[j]);
+ if (zoneData != null)
+ {
+ buffer2.append("\"");
+ buffer2.append(convertToJavaString(zoneData.data));
+ buffer2.append("\", ");
+ zoneDataFound = true;
+ }
+ else
+ /* TODO: Emit a warning here "Insufficient data" */
+ buffer2.append("\"\", ");
+ }
+ if (zoneDataFound)
+ {
+ buffer.append(buffer2.substring(0, buffer2.length() - 2));
+ buffer.append("},\n");
+ usable = true;
+ }
+ }
+ if (usable)
+ {
+ o.print(buffer);
+ o.println(" };");
+ }
+ }
+
+ public boolean isUsable()
+ {
+ return usable;
}
}
@@ -386,15 +438,15 @@ public class JavaGenerator
while (more)
{
String key = (String) keys.nextElement();
- if (key.indexOf("|") != -1)
+ if (key.indexOf("\u00A6") != -1)
{
- System.err.println(name + " key: '" + key + "' contains |");
+ System.err.println(name + " key: '" + key + "' contains \u00A6");
System.exit(-1);
}
o.print(key);
more = keys.hasMoreElements();
if (more)
- o.print('|');
+ o.print("\\u00A6");
}
o.println("\";");
o.println();
@@ -406,15 +458,15 @@ public class JavaGenerator
String key = (String) keys.nextElement();
String value = (String) table.get(key);
value = convertToJavaString(value);
- if (value.indexOf("|") != -1)
+ if (value.indexOf("\u00A6") != -1)
{
- System.err.println(name + " value: '" + value + "' contains |");
+ System.err.println(name + " value: '" + value + "' contains \u00A6");
System.exit(-1);
}
o.print(value);
more = keys.hasMoreElements();
if (more)
- o.print('|');
+ o.print("\\u00A6");
}
o.println("\";");
o.println();
@@ -423,9 +475,9 @@ public class JavaGenerator
o.println(" {");
o.println(" " + name + " = new Hashtable();");
o.println(" Enumeration keys = new StringTokenizer(" + name
- + "Keys, \"|\");");
+ + "Keys, \"\\u00A6\");");
o.println(" Enumeration values = new StringTokenizer(" + name
- + "Values, \"|\");");
+ + "Values, \"\\u00A6\");");
o.println(" while (keys.hasMoreElements())");
o.println(" {");
o.println(" String key = (String) keys.nextElement();");
@@ -434,6 +486,11 @@ public class JavaGenerator
o.println(" }");
o.println(" }");
}
+
+ public boolean isUsable()
+ {
+ return true;
+ }
}
/*
@@ -742,13 +799,16 @@ public class JavaGenerator
for (int i = 0; i < localeContents.size(); i++)
{
JavaContent content = (JavaContent) localeContents.get(i);
- if (content.isPackage())
- o.print(" { \"" + content.getName() + "\", " + content.getName()
- + " }");
- else
- o.print(" { \"" + content.getName() + "\", \""
- + convertToJavaString(content.getData()) + "\" }");
- o.println(",");
+ if (content.isUsable())
+ {
+ if (content.isPackage())
+ o.print(" { \"" + content.getName() + "\", " + content.getName()
+ + " }");
+ else
+ o.print(" { \"" + content.getName() + "\", \""
+ + convertToJavaString(content.getData()) + "\" }");
+ o.println(",");
+ }
}
o.println(" };");
o.println();
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFB/Zl2u+fW6pI0dq4RArb+AJ92n6PXHRRUKozc+yqESAhbQGMn1wCdFyPL P+14j1CxujhDL8E/xz51E6E= =fKk7 -----END PGP SIGNATURE-----