Changeset 305:a401002c3a1f
- Timestamp:
- 09/07/08 19:43:08 (4 months ago)
- Files:
-
- dwt/dwthelper/System.d (modified) (2 diffs)
- dwt/dwthelper/utils.d (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/dwthelper/System.d
r280 r305 6 6 import dwt.dwthelper.utils; 7 7 8 import tango.sys.Environment; 8 9 import tango.core.Exception; 10 import tango.io.model.IFile : FileConst; 9 11 import tango.time.Clock; 10 12 import tango.stdc.stdlib : exit; … … 145 147 } 146 148 149 public static String getProperty( String key, String defval ){ 150 String res = getProperty(key); 151 if( res ){ 152 return res; 153 } 154 return defval; 155 } 147 156 public static String getProperty( String key ){ 148 switch( key ){ 149 case "os.name": return "linux"; 150 case "file.separator" : return "."; 151 default: return null; 152 } 153 } 157 /* Get values for local dwt specific keys */ 158 String* p; 159 if (key[0..3] == "dwt") { 160 return ((p = key in localProperties) != null) ? *p : null; 161 /* else get values for global system keys (environment) */ 162 } else { 163 switch( key ){ 164 case "os.name": return "linux"; 165 case "user.name": return ""; 166 case "user.home": return ""; 167 case "user.dir" : return ""; 168 case "file.separator" : return FileConst.PathSeparatorString ; 169 default: return null; 170 } 171 } 172 } 173 174 public static void setProperty ( String key, String value ) { 175 /* set property for local dwt keys */ 176 if (key[0..3] == "dwt") { 177 if (key !is null && value !is null) 178 localProperties[ key ] = value; 179 /* else set properties for global system keys (environment) */ 180 } else { 181 182 } 183 184 } 185 186 static class Output { 187 public void println( String str ){ 188 implMissing( __FILE__, __LINE__ ); 189 } 190 } 191 192 private static Output err__; 193 public static Output err(){ 194 if( err__ is null ){ 195 err__ = new Output(); 196 } 197 return err__; 198 } 199 private static Output out__; 200 public static Output out_(){ 201 if( out__ is null ){ 202 out__ = new Output(); 203 } 204 return out__; 205 } 206 207 private static String[String] localProperties; 154 208 } 155 209 dwt/dwthelper/utils.d
r292 r305 5 5 6 6 public import dwt.dwthelper.System; 7 public import dwt.dwthelper.Runnable; 7 8 public import Math = tango.math.Math; 8 9 … … 14 15 static import tango.text.Util; 15 16 static import tango.text.Text; 17 static import tango.text.Ascii; 16 18 import tango.text.Unicode; 17 19 import tango.text.convert.Utf; … … 21 23 import tango.util.log.Trace; 22 24 import tango.text.UnicodeData; 23 static import tango.util.collection.model.Seq;24 25 25 26 alias char[] String; 26 27 alias tango.text.Text.Text!(char) StringBuffer; 28 29 alias ArrayBoundsException ArrayIndexOutOfBoundsException; 27 30 28 31 void implMissing( String file, uint line ){ … … 125 128 return b ? TRUE : FALSE; 126 129 } 130 public static bool getBoolean(String name){ 131 return tango.text.Ascii.icompare(System.getProperty(name, "false"), "true" ) is 0; 132 } 127 133 } 128 134 … … 146 152 super( value ); 147 153 } 154 155 public static String toString( byte i ){ 156 return tango.text.convert.Integer.toString(i); 157 } 158 148 159 } 149 160 alias Byte ValueWrapperByte; … … 278 289 return null; 279 290 } 291 public static double parseDouble(String s){ 292 implMissing( __FILE__, __LINE__ ); 293 return 0.0; 294 } 280 295 } 281 296 … … 561 576 return i; 562 577 } 578 dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp ){ 579 int dummy; 580 return getRelativeCodePoint( str, startIndex, dummy ); 581 } 563 582 dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){ 564 583 relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp ); … … 603 622 } 604 623 624 class Character { 625 public static bool isUpperCase( dchar c ){ 626 implMissing( __FILE__, __LINE__); 627 return false; 628 } 629 public static dchar toUpperCase( dchar c ){ 630 dchar[] r = tango.text.Unicode.toUpper( [c] ); 631 return r[0]; 632 } 633 public static dchar toLowerCase( dchar c ){ 634 dchar[] r = tango.text.Unicode.toLower( [c] ); 635 return r[0]; 636 } 637 public static bool isWhitespace( dchar c ){ 638 return tango.text.Unicode.isWhitespace( c ); 639 } 640 public static bool isDigit( dchar c ){ 641 return tango.text.Unicode.isDigit( c ); 642 } 643 public static bool isLetterOrDigit( dchar c ){ 644 return isDigit(c) || isLetter(c); 645 } 646 public static bool isUnicodeIdentifierPart(char ch){ 647 implMissing( __FILE__, __LINE__); 648 return false; 649 } 650 public static bool isUnicodeIdentifierStart(char ch){ 651 implMissing( __FILE__, __LINE__); 652 return false; 653 } 654 public static bool isIdentifierIgnorable(char ch){ 655 implMissing( __FILE__, __LINE__); 656 return false; 657 } 658 public static bool isJavaIdentifierPart(char ch){ 659 implMissing( __FILE__, __LINE__); 660 return false; 661 } 662 663 this( char c ){ 664 // must be correct for container storage 665 implMissing( __FILE__, __LINE__); 666 } 667 } 668 669 String new_String( String cont, int offset, int len ){ 670 return cont[ offset .. offset+len ].dup; 671 } 672 String new_String( String cont ){ 673 return cont.dup; 674 } 675 String String_valueOf( bool v ){ 676 return v ? "true" : "false"; 677 } 678 String String_valueOf( int v ){ 679 return tango.text.convert.Integer.toString(v); 680 } 681 String String_valueOf( long v ){ 682 return tango.text.convert.Integer.toString(v); 683 } 684 String String_valueOf( float v ){ 685 return tango.text.convert.Float.toString(v); 686 } 687 String String_valueOf( double v ){ 688 return tango.text.convert.Float.toString(v); 689 } 690 String String_valueOf( dchar v ){ 691 return dcharToString(v); 692 } 693 String String_valueOf( char[] v ){ 694 return v.dup; 695 } 696 String String_valueOf( char[] v, int offset, int len ){ 697 return v[ offset .. offset+len ].dup; 698 } 699 String String_valueOf( Object v ){ 700 return v is null ? "null" : v.toString(); 701 } 605 702 bool CharacterIsDefined( dchar ch ){ 606 703 return (ch in tango.text.UnicodeData.unicodeData) !is null; … … 616 713 return r[0]; 617 714 } 618 715 int length( String str ){ 716 return str.length; 717 } 619 718 dchar CharacterToLower( dchar c ){ 620 719 dchar[] r = tango.text.Unicode.toLower( [c] ); … … 636 735 public String toUpperCase( String str ){ 637 736 return tango.text.Unicode.toUpper( str ); 737 } 738 739 public String replaceFirst( String str, String regex, String replacement ){ 740 implMissing(__FILE__,__LINE__); 741 return str; 638 742 } 639 743 … … 677 781 } 678 782 783 public String replaceAll( String str, String regex, String replacement ){ 784 implMissing(__FILE__,__LINE__); 785 return null; 786 } 679 787 public String replace( String str, char from, char to ){ 680 788 return tango.text.Util.replace( str.dup, from, to ); … … 705 813 } 706 814 707 public wchar[] toCharArray( String str ){708 return toString16( str );815 public char[] toCharArray( String str ){ 816 return str; 709 817 } 710 818 … … 753 861 } 754 862 863 /++ 864 + This is like tango.stdc.stringz.toStringz, but in case of an empty input string, 865 + this function returns a pointer to a null value instead of a null ptr. 866 +/ 755 867 public char* toStringzValidPtr( String src ){ 756 868 if( src ){ … … 862 974 } 863 975 } 976 class ClassCastException : Exception { 977 this( String e = null ){ 978 super(e); 979 } 980 } 864 981 865 982 interface Cloneable{ … … 927 1044 } 928 1045 929 interface Reader{ 1046 class Reader{ 1047 protected Object lock; 1048 protected this(){ 1049 implMissing(__FILE__,__LINE__); 1050 } 1051 protected this(Object lock){ 1052 implMissing(__FILE__,__LINE__); 1053 } 1054 abstract void close(); 1055 void mark(int readAheadLimit){ 1056 implMissing(__FILE__,__LINE__); 1057 } 1058 bool markSupported(){ 1059 implMissing(__FILE__,__LINE__); 1060 return false; 1061 } 1062 int read(){ 1063 implMissing(__FILE__,__LINE__); 1064 return 0; 1065 } 1066 int read(char[] cbuf){ 1067 implMissing(__FILE__,__LINE__); 1068 return 0; 1069 } 1070 abstract int read(char[] cbuf, int off, int len); 1071 bool ready(){ 1072 implMissing(__FILE__,__LINE__); 1073 return false; 1074 } 1075 void reset(){ 1076 implMissing(__FILE__,__LINE__); 1077 } 1078 long skip(long n){ 1079 implMissing(__FILE__,__LINE__); 1080 return 0; 1081 } 930 1082 } 931 1083 interface Writer{ … … 1045 1197 } 1046 1198 1047 int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){1199 /+int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){ 1048 1200 int idx; 1049 1201 foreach( e; s ){ … … 1054 1206 } 1055 1207 return -1; 1056 } 1208 }+/ 1209 1057 1210 int arrayIndexOf(T)( T[] arr, T v ){ 1058 1211 int res = -1; … … 1068 1221 } 1069 1222 1070 int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){1071 int res = -1;1072 int idx = 0;1073 foreach( p; seq ){1074 if( p == v){1075 res = idx;1076 break;1077 }1078 idx++;1079 }1080 return res;1081 }1223 // int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){ 1224 // int res = -1; 1225 // int idx = 0; 1226 // foreach( p; seq ){ 1227 // if( p == v){ 1228 // res = idx; 1229 // break; 1230 // } 1231 // idx++; 1232 // } 1233 // return res; 1234 // } 1082 1235 1083 1236 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ … … 1109 1262 } 1110 1263 1264 interface CharSequence { 1265 char charAt(int index); 1266 int length(); 1267 CharSequence subSequence(int start, int end); 1268 String toString(); 1269 } 1270 1271 class StringCharSequence : CharSequence { 1272 private String str; 1273 this( String str ){ 1274 this.str = str; 1275 } 1276 char charAt(int index){ 1277 return str[index]; 1278 } 1279 int length(){ 1280 return str.length; 1281 } 1282 CharSequence subSequence(int start, int end){ 1283 return new StringCharSequence( str[ start .. end ]); 1284 } 1285 String toString(){ 1286 return str; 1287 } 1288 } 1289 1290
