Mercurial > projects > dwt-win
comparison 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 |
comparison
equal
deleted
inserted
replaced
196:1e7701c27c03 | 197:184ab53b7785 |
---|---|
4 module dwt.dwthelper.ResourceBundle; | 4 module dwt.dwthelper.ResourceBundle; |
5 | 5 |
6 import tango.text.Util; | 6 import tango.text.Util; |
7 import tango.io.Stdout; | 7 import tango.io.Stdout; |
8 | 8 |
9 import dwt.DWT; | |
10 import dwt.dwthelper.utils; | |
9 | 11 |
10 class ResourceBundle { | 12 class ResourceBundle { |
11 | 13 |
12 char[][ char[] ] map; | 14 char[][ char[] ] map; |
13 | 15 |
32 char[] value; | 34 char[] value; |
33 nextline: | 35 nextline: |
34 while( dataIndex < data.length ){ | 36 while( dataIndex < data.length ){ |
35 //tango.io.Stdout.Stdout.formatln( "properties put {} startline", __LINE__ ); | 37 //tango.io.Stdout.Stdout.formatln( "properties put {} startline", __LINE__ ); |
36 readLine(); | 38 readLine(); |
37 line = line.trim(); | 39 line = dwt.dwthelper.utils.trim(line); |
38 if( line.length is 0 ){ | 40 if( line.length is 0 ){ |
39 //tango.io.Stdout.Stdout.formatln( "properties put {} was 0 length", __LINE__ ); | 41 //tango.io.Stdout.Stdout.formatln( "properties put {} was 0 length", __LINE__ ); |
40 continue; | 42 continue; |
41 } | 43 } |
42 if( line[0] == '#' ){ | 44 if( line[0] == '#' ){ |
59 esc = false; | 61 esc = false; |
60 switch( c ){ | 62 switch( c ){ |
61 case 't': c = '\t'; break; | 63 case 't': c = '\t'; break; |
62 case 'n': c = '\n'; break; | 64 case 'n': c = '\n'; break; |
63 case '\\': c = '\\'; break; | 65 case '\\': c = '\\'; break; |
66 case '\"': c = '\"'; break; | |
64 default: break; | 67 default: break; |
65 } | 68 } |
66 } | 69 } |
67 else{ | 70 else{ |
68 if( c == '\\' ){ | 71 if( c == '\\' ){ |
87 else{ | 90 else{ |
88 value ~= c; | 91 value ~= c; |
89 } | 92 } |
90 } | 93 } |
91 if( iskeypart ){ | 94 if( iskeypart ){ |
92 //tango.io.Stdout.Stdout.formatln( "dwt.dwthelper.ResourceBundle ctor cannot find '='." ); | 95 // Cannot find '=' in record |
96 DWT.error( __FILE__, __LINE__, DWT.ERROR_INVALID_ARGUMENT ); | |
93 continue; | 97 continue; |
94 } | 98 } |
95 key = key.trim(); | 99 key = dwt.dwthelper.utils.trim(key); |
96 value = value.trim(); | 100 value = dwt.dwthelper.utils.trim(value); |
97 //tango.io.Stdout.Stdout.formatln( "properties put {}=>{}", key, value ); | 101 //tango.io.Stdout.Stdout.formatln( "properties put {}=>{}", key, value ); |
98 | 102 |
99 map[ key.dup ] = value.dup; | 103 map[ key.dup ] = value.dup; |
100 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); | 104 //tango.io.Stdout.Stdout.formatln( "properties put {}", __LINE__ ); |
101 } | 105 } |
107 | 111 |
108 public char[] getString( char[] key ){ | 112 public char[] getString( char[] key ){ |
109 if( auto v = key in map ){ | 113 if( auto v = key in map ){ |
110 return (*v).dup; | 114 return (*v).dup; |
111 } | 115 } |
112 return key; | 116 throw new MissingResourceException( "key not found", this.classinfo.name, key ); |
117 } | |
118 | |
119 public char[][] getKeys(){ | |
120 return map.keys; | |
113 } | 121 } |
114 | 122 |
115 public static ResourceBundle getBundle( char[] name ){ | 123 public static ResourceBundle getBundle( char[] name ){ |
116 return new ResourceBundle( null ); | 124 return new ResourceBundle( null ); |
117 } | 125 } |