Mercurial > projects > dwt-win
comparison dwt/dwthelper/ResourceBundle.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | fef1e3b37378 |
children | 8c656d6b7300 |
comparison
equal
deleted
inserted
replaced
211:ff59aeb96cac | 212:ab60f3309436 |
---|---|
10 import dwt.dwthelper.utils; | 10 import dwt.dwthelper.utils; |
11 import tango.io.File; | 11 import tango.io.File; |
12 | 12 |
13 class ResourceBundle { | 13 class ResourceBundle { |
14 | 14 |
15 char[][ char[] ] map; | 15 String[ String ] map; |
16 | 16 |
17 public this( char[] data ){ | 17 public this( String data ){ |
18 char[] line; | 18 String line; |
19 int dataIndex; | 19 int dataIndex; |
20 | 20 |
21 //tango.io.Stdout.Stdout.formatln( "properties put ..." ); | 21 //tango.io.Stdout.Stdout.formatln( "properties put ..." ); |
22 void readLine(){ | 22 void readLine(){ |
23 line.length = 0; | 23 line.length = 0; |
29 } | 29 } |
30 | 30 |
31 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); | 31 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); |
32 bool linecontinue = false; | 32 bool linecontinue = false; |
33 bool iskeypart = true; | 33 bool iskeypart = true; |
34 char[] key; | 34 String key; |
35 char[] value; | 35 String value; |
36 nextline: | 36 nextline: |
37 while( dataIndex < data.length ){ | 37 while( dataIndex < data.length ){ |
38 //tango.io.Stdout.Stdout.formatln( "properties put {} startline", __LINE__ ); | 38 //tango.io.Stdout.Stdout.formatln( "properties put {} startline", __LINE__ ); |
39 readLine(); | 39 readLine(); |
40 line = dwt.dwthelper.utils.trim(line); | 40 line = dwt.dwthelper.utils.trim(line); |
105 map[ key.dup ] = value.dup; | 105 map[ key.dup ] = value.dup; |
106 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); | 106 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 public bool hasString( char[] key ){ | 110 public bool hasString( String key ){ |
111 return ( key in map ) !is null; | 111 return ( key in map ) !is null; |
112 } | 112 } |
113 | 113 |
114 public char[] getString( char[] key ){ | 114 public String getString( String key ){ |
115 if( auto v = key in map ){ | 115 if( auto v = key in map ){ |
116 return (*v).dup; | 116 return (*v).dup; |
117 } | 117 } |
118 throw new MissingResourceException( "key not found", this.classinfo.name, key ); | 118 throw new MissingResourceException( "key not found", this.classinfo.name, key ); |
119 } | 119 } |
120 | 120 |
121 public char[][] getKeys(){ | 121 public String[] getKeys(){ |
122 return map.keys; | 122 return map.keys; |
123 } | 123 } |
124 | 124 |
125 public static ResourceBundle getBundle( ImportData data ){ | 125 public static ResourceBundle getBundle( ImportData data ){ |
126 return new ResourceBundle( cast(char[]) data.data ); | 126 return new ResourceBundle( cast(String) data.data ); |
127 } | 127 } |
128 public static ResourceBundle getBundle( char[] name ){ | 128 public static ResourceBundle getBundle( String name ){ |
129 try{ | 129 try{ |
130 scope f = new File(name); | 130 scope f = new File(name); |
131 return new ResourceBundle( cast(char[]) f.read() ); | 131 return new ResourceBundle( cast(String) f.read() ); |
132 } | 132 } |
133 catch( IOException e){ | 133 catch( IOException e){ |
134 e.msg ~= " file:" ~ name; | 134 e.msg ~= " file:" ~ name; |
135 throw e; | 135 throw e; |
136 } | 136 } |
137 } | 137 } |
138 public static ResourceBundle getBundleFromData( char[] data ){ | 138 public static ResourceBundle getBundleFromData( String data ){ |
139 return new ResourceBundle( data ); | 139 return new ResourceBundle( data ); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 | 143 |