Mercurial > projects > dwt2
diff java/src/java/util/ResourceBundle.d @ 21:9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 19 Mar 2009 20:38:55 +0100 |
parents | 735224fcc45f |
children |
line wrap: on
line diff
--- a/java/src/java/util/ResourceBundle.d Wed Mar 18 12:10:17 2009 +0100 +++ b/java/src/java/util/ResourceBundle.d Thu Mar 19 20:38:55 2009 +0100 @@ -3,14 +3,17 @@ */ module java.util.ResourceBundle; -import tango.text.Util; - import java.lang.util; import java.lang.Integer; import java.lang.exceptions; import java.util.MissingResourceException; -import tango.io.device.File; -import tango.text.locale.Core; +version(Tango){ + //import tango.text.Util; + import tango.io.device.File; + import tango.text.locale.Core; +} else { // Phobos +} + class ResourceBundle { @@ -20,10 +23,20 @@ + First entry is the default entry if no maching locale is found +/ public this( ImportData[] data ){ - char[] name = Culture.current().name.dup; - if( name.length is 5 && name[2] is '-' ){ - name[2] = '_'; - char[] end = "_" ~ name ~ ".properties"; + version(Tango){ + char[] name = Culture.current().name.dup; + if( name.length is 5 && name[2] is '-' ){ + name[2] = '_'; + char[] end = "_" ~ name ~ ".properties"; + foreach( entry; data ){ + if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){ + //Trace.formatln( "ResourceBundle {}", entry.name ); + initialize( cast(char[])entry.data ); + return; + } + } + } + char[] end = "_" ~ name[0..2] ~ ".properties"; foreach( entry; data ){ if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){ //Trace.formatln( "ResourceBundle {}", entry.name ); @@ -31,20 +44,14 @@ return; } } + //Trace.formatln( "ResourceBundle default" ); + initialize( cast(char[])data[0].data ); + } else { // Phobos + implMissing(__FILE__,__LINE__); } - char[] end = "_" ~ name[0..2] ~ ".properties"; - foreach( entry; data ){ - if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){ - //Trace.formatln( "ResourceBundle {}", entry.name ); - initialize( cast(char[])entry.data ); - return; - } - } - //Trace.formatln( "ResourceBundle default" ); - initialize( cast(char[])data[0].data ); } public this( ImportData data ){ - initialize( cast(char[])data.data ); + initialize( cast(String)data.data ); } public this( String data ){ initialize( data ); @@ -87,24 +94,23 @@ linecontinue = false; } while( pos < line.length ){ - char[] c = line[pos .. pos +1]; + dchar c = line[pos]; if( esc ){ esc = false; - switch( c[0] ){ - case 't' : c[0] = '\t'; break; - case 'n' : c[0] = '\n'; break; - case '\\': c[0] = '\\'; break; - case '\"': c[0] = '\"'; break; - case 'u' : - dchar d = Integer.parseInt( line[ pos+1 .. pos+5 ], 16 ); - c = dcharToString(d); - pos += 4; - break; - default: break; + switch( c ){ + case 't' : c = '\t'; break; + case 'n' : c = '\n'; break; + case '\\': c = '\\'; break; + case '\"': c = '\"'; break; + case 'u' : + dchar d = Integer.parseInt( line[ pos+1 .. pos+5 ], 16 ); + pos += 4; + break; + default: break; } } else{ - if( c == "\\" ){ + if( c == '\\' ){ if( pos == line.length -1 ){ linecontinue = true; goto nextline; @@ -113,7 +119,7 @@ pos++; continue; } - else if( iskeypart && c == "=" ){ + else if( iskeypart && c == '=' ){ pos++; iskeypart = false; continue; @@ -121,10 +127,10 @@ } pos++; if( iskeypart ){ - key ~= c; + key ~= dcharToString(c); } else{ - value ~= c; + value ~= dcharToString(c); } } if( iskeypart ){ @@ -133,7 +139,11 @@ key = java.lang.util.trim(key); value = java.lang.util.trim(value); - map[ key.dup ] = value.dup; + version(D_Version2){ + map[ key.idup ] = value.idup; + } else { + map[ key.dup ] = value.dup; + } } } @@ -143,7 +153,11 @@ public String getString( String key ){ if( auto v = key in map ){ - return (*v).dup; + version(D_Version2){ + return (*v).idup; + } else { + return (*v).dup; + } } throw new MissingResourceException( "key not found", this.classinfo.name, key ); } @@ -160,7 +174,11 @@ } public static ResourceBundle getBundle( String name ){ try{ - return new ResourceBundle( cast(String) File.get(name) ); + version(Tango){ + return new ResourceBundle( cast(String) File.get(name) ); + } else { // Phobos + implMissing(__FILE__,__LINE__); + } } catch( IOException e){ e.msg ~= " file:" ~ name;