Mercurial > projects > dwt-win
annotate dwt/dwthelper/ResourceBundle.d @ 197:184ab53b7785
Changes and fixes for jface
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 10 Apr 2008 11:19:49 +0200 |
parents | 1da8c82b1c84 |
children | fef1e3b37378 |
rev | line source |
---|---|
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
1 /** |
0 | 2 * Authors: Frank Benoit <keinfarbton@googlemail.com> |
3 */ | |
4 module dwt.dwthelper.ResourceBundle; | |
5 | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
6 import tango.text.Util; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
7 import tango.io.Stdout; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
8 |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
9 import dwt.DWT; |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
10 import dwt.dwthelper.utils; |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
11 |
0 | 12 class ResourceBundle { |
13 | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
14 char[][ char[] ] map; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
15 |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
16 public this( char[] data ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
17 char[] line; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
18 int dataIndex; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
19 |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
20 //tango.io.Stdout.Stdout.formatln( "properties put ..." ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
21 void readLine(){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
22 line.length = 0; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
23 char i = data[ dataIndex++ ]; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
24 while( dataIndex < data.length && i !is '\n' && i !is '\r' ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
25 line ~= i; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
26 i = data[ dataIndex++ ]; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
27 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
28 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
29 |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
30 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
31 bool linecontinue = false; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
32 bool iskeypart = true; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
33 char[] key; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
34 char[] value; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
35 nextline: |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
36 while( dataIndex < data.length ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
37 //tango.io.Stdout.Stdout.formatln( "properties put {} startline", __LINE__ ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
38 readLine(); |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
39 line = dwt.dwthelper.utils.trim(line); |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
40 if( line.length is 0 ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
41 //tango.io.Stdout.Stdout.formatln( "properties put {} was 0 length", __LINE__ ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
42 continue; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
43 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
44 if( line[0] == '#' ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
45 //tango.io.Stdout.Stdout.formatln( "properties put {} was comment", __LINE__ ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
46 continue; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
47 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
48 int pos = 0; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
49 bool esc = false; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
50 if( !linecontinue ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
51 iskeypart = true; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
52 key = null; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
53 value = null; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
54 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
55 else{ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
56 linecontinue = false; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
57 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
58 while( pos < line.length ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
59 char c = line[pos]; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
60 if( esc ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
61 esc = false; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
62 switch( c ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
63 case 't': c = '\t'; break; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
64 case 'n': c = '\n'; break; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
65 case '\\': c = '\\'; break; |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
66 case '\"': c = '\"'; break; |
124
1da8c82b1c84
Add: hasString for ResourceBundle to indicate if the string has length 0 or is not present
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
67 default: break; |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
68 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
69 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
70 else{ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
71 if( c == '\\' ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
72 if( pos == line.length -1 ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
73 linecontinue = true; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
74 goto nextline; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
75 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
76 esc = true; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
77 pos++; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
78 continue; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
79 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
80 else if( iskeypart && c == '=' ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
81 pos++; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
82 iskeypart = false; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
83 continue; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
84 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
85 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
86 pos++; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
87 if( iskeypart ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
88 key ~= c; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
89 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
90 else{ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
91 value ~= c; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
92 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
93 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
94 if( iskeypart ){ |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
95 // Cannot find '=' in record |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
96 DWT.error( __FILE__, __LINE__, DWT.ERROR_INVALID_ARGUMENT ); |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
97 continue; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
98 } |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
99 key = dwt.dwthelper.utils.trim(key); |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
100 value = dwt.dwthelper.utils.trim(value); |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
101 //tango.io.Stdout.Stdout.formatln( "properties put {}=>{}", key, value ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
102 |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
103 map[ key.dup ] = value.dup; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
104 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
105 } |
0 | 106 } |
107 | |
124
1da8c82b1c84
Add: hasString for ResourceBundle to indicate if the string has length 0 or is not present
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
108 public bool hasString( char[] key ){ |
1da8c82b1c84
Add: hasString for ResourceBundle to indicate if the string has length 0 or is not present
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
109 return ( key in map ) !is null; |
1da8c82b1c84
Add: hasString for ResourceBundle to indicate if the string has length 0 or is not present
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
110 } |
1da8c82b1c84
Add: hasString for ResourceBundle to indicate if the string has length 0 or is not present
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
111 |
0 | 112 public char[] getString( char[] key ){ |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
113 if( auto v = key in map ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
114 return (*v).dup; |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
115 } |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
116 throw new MissingResourceException( "key not found", this.classinfo.name, key ); |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
117 } |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
118 |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
119 public char[][] getKeys(){ |
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
124
diff
changeset
|
120 return map.keys; |
0 | 121 } |
122 | |
123 public static ResourceBundle getBundle( char[] name ){ | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
124 return new ResourceBundle( null ); |
0 | 125 } |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
126 public static ResourceBundle getBundleFromData( char[] data ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
127 return new ResourceBundle( data ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
128 } |
0 | 129 } |
130 | |
131 |