[kaffe] CVS kaffe (robilad): small fixlet for locale system property initialization

Kaffe CVS cvs-commits at kaffe.org
Sun Feb 12 13:46:46 PST 2006


PatchSet 7130 
Date: 2006/02/12 21:34:21
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
small fixlet for locale system property initialization

2006-02-12  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java:
        Made locale check more robust.

        Reported by:  Guilhem Lavaux  <guilhem at kaffe.org>

Members: 
	ChangeLog:1.4648->1.4649 
	libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java:1.3->1.4 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4648 kaffe/ChangeLog:1.4649
--- kaffe/ChangeLog:1.4648	Sun Feb 12 19:38:30 2006
+++ kaffe/ChangeLog	Sun Feb 12 21:34:21 2006
@@ -1,5 +1,12 @@
 2006-02-12  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java:
+	Made locale check more robust.
+
+	Reported by:  Guilhem Lavaux  <guilhem at kaffe.org>
+
+2006-02-12  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/external/classpath/gnu/java/net/protocol/file/Connection.java
 	(unquote) Use System.arraycopy rather than copying UTF-8 bytes one by one.
 	Fixed comment.
Index: kaffe/libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java
diff -u kaffe/libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java:1.3 kaffe/libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java:1.4
--- kaffe/libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java:1.3	Thu Feb  9 21:44:18 2006
+++ kaffe/libraries/javalib/vmspecific/gnu/classpath/VMSystemProperties.java	Sun Feb 12 21:34:25 2006
@@ -173,24 +173,42 @@
       final String SUN_BOOT_CLASS_PATH = getSunBootClassPath();
       properties.setProperty("sun.boot.class.path", SUN_BOOT_CLASS_PATH);
 
+
+      // use en_US locale by default unless something is set.
+      properties.setProperty("user.language", "en");
+      properties.setProperty("user.region", "US");
+
       final String LOCALE = getLocale();
-      if (LOCALE != null && LOCALE.length() > 2)
+      if (LOCALE != null)
 	{
-	  properties.setProperty("user.language", LOCALE.substring(0, 2));
-	  if (LOCALE.charAt(2) == '_')
-	    {
-	      properties.setProperty("user.region", LOCALE.substring(3, 5));
-	    }
-	  if (LOCALE.charAt(5) == '.')
-	    {
-	      properties.setProperty("file.encoding", LOCALE.substring(6));
-	    }
-	}
-      else 
-	{
-	  // if no locale set, use en_US
-	  properties.setProperty("user.language", "en");
-	  properties.setProperty("user.region", "US");
+	    final char LANGUAGE_DELIMITER = '_';
+	    final int END_OF_LANGUAGE_NAME = LOCALE.indexOf(LANGUAGE_DELIMITER);
+
+	    if (-1 == END_OF_LANGUAGE_NAME)
+		properties.setProperty("user.language", LOCALE);
+	    else
+		{
+		    final String LANGUAGE = LOCALE.substring(0, END_OF_LANGUAGE_NAME);
+		    properties.setProperty("user.language", LANGUAGE);
+
+		    final char REGION_DELIMITER = '.';
+		    final int END_OF_REGION_NAME = LOCALE.indexOf(REGION_DELIMITER);		    
+		    if (-1 == END_OF_REGION_NAME)
+			{
+			    final String REGION = LOCALE.substring(END_OF_LANGUAGE_NAME + 1);
+			    properties.setProperty("user.region", REGION);
+			}
+		    else
+			{
+			    final String REGION = LOCALE.substring(END_OF_LANGUAGE_NAME + 1,
+								   END_OF_REGION_NAME);
+			    properties.setProperty("user.region", REGION);
+
+			    final String ENCODING = LOCALE.substring(END_OF_REGION_NAME + 1);
+			    properties.setProperty("file.encoding", 
+						   LOCALE.substring(END_OF_REGION_NAME + 1));
+			}
+		}
 	}
 
       // Add GNU Classpath specific properties




More information about the kaffe mailing list