Changeset 305:a401002c3a1f

Show
Ignore:
Timestamp:
09/07/08 19:43:08 (4 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Sync with dwt-linux

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/dwthelper/System.d

    r280 r305  
    66import dwt.dwthelper.utils; 
    77 
     8import tango.sys.Environment; 
    89import tango.core.Exception; 
     10import tango.io.model.IFile : FileConst; 
    911import tango.time.Clock; 
    1012import tango.stdc.stdlib : exit; 
     
    145147    } 
    146148 
     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    } 
    147156    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; 
    154208} 
    155209 
  • dwt/dwthelper/utils.d

    r292 r305  
    55 
    66public import dwt.dwthelper.System; 
     7public import dwt.dwthelper.Runnable; 
    78public import Math = tango.math.Math; 
    89 
     
    1415static import tango.text.Util; 
    1516static import tango.text.Text; 
     17static import tango.text.Ascii; 
    1618import tango.text.Unicode; 
    1719import tango.text.convert.Utf; 
     
    2123import tango.util.log.Trace; 
    2224import tango.text.UnicodeData; 
    23 static import tango.util.collection.model.Seq; 
    2425 
    2526alias char[] String; 
    2627alias tango.text.Text.Text!(char) StringBuffer; 
     28 
     29alias ArrayBoundsException ArrayIndexOutOfBoundsException; 
    2730 
    2831void implMissing( String file, uint line ){ 
     
    125128        return b ? TRUE : FALSE; 
    126129    } 
     130    public static bool getBoolean(String name){ 
     131        return tango.text.Ascii.icompare(System.getProperty(name, "false"), "true" ) is 0; 
     132    } 
    127133} 
    128134 
     
    146152        super( value ); 
    147153    } 
     154 
     155    public static String toString( byte i ){ 
     156        return tango.text.convert.Integer.toString(i); 
     157    } 
     158 
    148159} 
    149160alias Byte ValueWrapperByte; 
     
    278289        return null; 
    279290    } 
     291    public static double parseDouble(String s){ 
     292        implMissing( __FILE__, __LINE__ ); 
     293        return 0.0; 
     294    } 
    280295} 
    281296 
     
    561576    return i; 
    562577} 
     578dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp ){ 
     579    int dummy; 
     580    return getRelativeCodePoint( str, startIndex, dummy ); 
     581} 
    563582dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){ 
    564583    relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp ); 
     
    603622} 
    604623 
     624class 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 
     669String new_String( String cont, int offset, int len ){ 
     670    return cont[ offset .. offset+len ].dup; 
     671} 
     672String new_String( String cont ){ 
     673    return cont.dup; 
     674} 
     675String String_valueOf( bool v ){ 
     676    return v ? "true" : "false"; 
     677} 
     678String String_valueOf( int v ){ 
     679    return tango.text.convert.Integer.toString(v); 
     680} 
     681String String_valueOf( long v ){ 
     682    return tango.text.convert.Integer.toString(v); 
     683} 
     684String String_valueOf( float v ){ 
     685    return tango.text.convert.Float.toString(v); 
     686} 
     687String String_valueOf( double v ){ 
     688    return tango.text.convert.Float.toString(v); 
     689} 
     690String String_valueOf( dchar v ){ 
     691    return dcharToString(v); 
     692} 
     693String String_valueOf( char[] v ){ 
     694    return v.dup; 
     695} 
     696String String_valueOf( char[] v, int offset, int len ){ 
     697    return v[ offset .. offset+len ].dup; 
     698} 
     699String String_valueOf( Object v ){ 
     700    return v is null ? "null" : v.toString(); 
     701} 
    605702bool CharacterIsDefined( dchar ch ){ 
    606703    return (ch in tango.text.UnicodeData.unicodeData) !is null; 
     
    616713    return r[0]; 
    617714} 
    618  
     715int length( String str ){ 
     716    return str.length; 
     717
    619718dchar CharacterToLower( dchar c ){ 
    620719    dchar[] r = tango.text.Unicode.toLower( [c] ); 
     
    636735public String toUpperCase( String str ){ 
    637736    return tango.text.Unicode.toUpper( str ); 
     737} 
     738 
     739public String replaceFirst( String str, String regex, String replacement ){ 
     740    implMissing(__FILE__,__LINE__); 
     741    return str; 
    638742} 
    639743 
     
    677781} 
    678782 
     783public String replaceAll( String str, String regex, String replacement ){ 
     784    implMissing(__FILE__,__LINE__); 
     785    return null; 
     786} 
    679787public String replace( String str, char from, char to ){ 
    680788    return tango.text.Util.replace( str.dup, from, to ); 
     
    705813} 
    706814 
    707 public wchar[] toCharArray( String str ){ 
    708     return toString16( str )
     815public char[] toCharArray( String str ){ 
     816    return str
    709817} 
    710818 
     
    753861} 
    754862 
     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 +/ 
    755867public char* toStringzValidPtr( String src ){ 
    756868    if( src ){ 
     
    862974    } 
    863975} 
     976class ClassCastException : Exception { 
     977    this( String e = null ){ 
     978        super(e); 
     979    } 
     980} 
    864981 
    865982interface Cloneable{ 
     
    9271044} 
    9281045 
    929 interface Reader{ 
     1046class 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    } 
    9301082} 
    9311083interface Writer{ 
     
    10451197} 
    10461198 
    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 ){ 
    10481200    int idx; 
    10491201    foreach( e; s ){ 
     
    10541206    } 
    10551207    return -1; 
    1056 
     1208}+/ 
     1209 
    10571210int arrayIndexOf(T)( T[] arr, T v ){ 
    10581211    int res = -1; 
     
    10681221} 
    10691222 
    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//
    10821235 
    10831236void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ 
     
    11091262} 
    11101263 
     1264interface CharSequence { 
     1265    char           charAt(int index); 
     1266    int             length(); 
     1267    CharSequence    subSequence(int start, int end); 
     1268    String          toString(); 
     1269} 
     1270 
     1271class 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