changeset 305:a401002c3a1f

Sync with dwt-linux
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 01:43:08 +0200
parents 4e8e11ccfa60
children 745001b1a52c
files dwt/dwthelper/System.d dwt/dwthelper/utils.d
diffstat 2 files changed, 257 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dwthelper/System.d	Sat Aug 30 13:59:13 2008 +0200
+++ b/dwt/dwthelper/System.d	Mon Sep 08 01:43:08 2008 +0200
@@ -5,7 +5,9 @@
 
 import dwt.dwthelper.utils;
 
+import tango.sys.Environment;
 import tango.core.Exception;
+import tango.io.model.IFile : FileConst;
 import tango.time.Clock;
 import tango.stdc.stdlib : exit;
 
@@ -144,12 +146,64 @@
         return (*cast(Object *)&x).toHash();
     }
 
+    public static String getProperty( String key, String defval ){
+        String res = getProperty(key);
+        if( res ){
+            return res;
+        }
+        return defval;
+    }
     public static String getProperty( String key ){
-        switch( key ){
-        case "os.name": return "linux";
-        case "file.separator" : return ".";
-        default: return null;
+        /* Get values for local dwt specific keys */
+        String* p;
+        if (key[0..3] == "dwt") {
+            return ((p = key in localProperties) != null) ? *p : null;
+        /* else get values for global system keys (environment) */
+        } else {
+            switch( key ){
+                case "os.name": return "linux";
+                case "user.name": return "";
+                case "user.home": return "";
+                case "user.dir" : return "";
+                case "file.separator" : return FileConst.PathSeparatorString ;
+                default: return null;
+            }
         }
     }
+
+    public static void setProperty ( String key, String value ) {
+        /* set property for local dwt keys */
+        if (key[0..3] == "dwt") {
+            if (key !is null && value !is null)
+                localProperties[ key ] = value;
+        /* else set properties for global system keys (environment) */
+        } else {
+
+        }
+
+    }
+
+    static class Output {
+        public void println( String str ){
+            implMissing( __FILE__, __LINE__ );
+        }
+    }
+
+    private static Output err__;
+    public static Output err(){
+        if( err__ is null ){
+            err__ = new Output();
+        }
+        return err__;
+    }
+    private static Output out__;
+    public static Output out_(){
+        if( out__ is null ){
+            out__ = new Output();
+        }
+        return out__;
+    }
+
+    private static String[String] localProperties;
 }
 
--- a/dwt/dwthelper/utils.d	Sat Aug 30 13:59:13 2008 +0200
+++ b/dwt/dwthelper/utils.d	Mon Sep 08 01:43:08 2008 +0200
@@ -4,6 +4,7 @@
 module dwt.dwthelper.utils;
 
 public import dwt.dwthelper.System;
+public import dwt.dwthelper.Runnable;
 public import Math = tango.math.Math;
 
 public import tango.core.Exception : IllegalArgumentException, IOException;
@@ -13,6 +14,7 @@
 static import tango.stdc.stringz;
 static import tango.text.Util;
 static import tango.text.Text;
+static import tango.text.Ascii;
 import tango.text.Unicode;
 import tango.text.convert.Utf;
 import tango.core.Exception;
@@ -20,11 +22,12 @@
 
 import tango.util.log.Trace;
 import tango.text.UnicodeData;
-static import tango.util.collection.model.Seq;
 
 alias char[] String;
 alias tango.text.Text.Text!(char) StringBuffer;
 
+alias ArrayBoundsException ArrayIndexOutOfBoundsException;
+
 void implMissing( String file, uint line ){
     Stderr.formatln( "implementation missing in file {} line {}", file, line );
     Stderr.formatln( "exiting ..." );
@@ -124,6 +127,9 @@
     public static Boolean valueOf( bool b ){
         return b ? TRUE : FALSE;
     }
+    public static bool getBoolean(String name){
+        return tango.text.Ascii.icompare(System.getProperty(name, "false"), "true" ) is 0;
+    }
 }
 
 alias Boolean    ValueWrapperBool;
@@ -145,6 +151,11 @@
     this( byte value ){
         super( value );
     }
+
+    public static String toString( byte i ){
+        return tango.text.convert.Integer.toString(i);
+    }
+
 }
 alias Byte ValueWrapperByte;
 
@@ -277,6 +288,10 @@
         implMissing( __FILE__, __LINE__ );
         return null;
     }
+    public static double parseDouble(String s){
+        implMissing( __FILE__, __LINE__ );
+        return 0.0;
+    }
 }
 
 class Float : ValueWrapperT!(float) {
@@ -560,6 +575,10 @@
     }
     return i;
 }
+dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp ){
+    int dummy;
+    return getRelativeCodePoint( str, startIndex, dummy );
+}
 dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){
     relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp );
     int ignore;
@@ -602,6 +621,84 @@
     return res;
 }
 
+class Character {
+    public static bool isUpperCase( dchar c ){
+        implMissing( __FILE__, __LINE__);
+        return false;
+    }
+    public static dchar toUpperCase( dchar c ){
+        dchar[] r = tango.text.Unicode.toUpper( [c] );
+        return r[0];
+    }
+    public static dchar toLowerCase( dchar c ){
+        dchar[] r = tango.text.Unicode.toLower( [c] );
+        return r[0];
+    }
+    public static bool isWhitespace( dchar c ){
+        return tango.text.Unicode.isWhitespace( c );
+    }
+    public static bool isDigit( dchar c ){
+        return tango.text.Unicode.isDigit( c );
+    }
+    public static bool isLetterOrDigit( dchar c ){
+        return isDigit(c) || isLetter(c);
+    }
+    public static bool isUnicodeIdentifierPart(char ch){
+        implMissing( __FILE__, __LINE__);
+        return false;
+    }
+    public static bool isUnicodeIdentifierStart(char ch){
+        implMissing( __FILE__, __LINE__);
+        return false;
+    }
+    public static bool isIdentifierIgnorable(char ch){
+        implMissing( __FILE__, __LINE__);
+        return false;
+    }
+    public static bool isJavaIdentifierPart(char ch){
+        implMissing( __FILE__, __LINE__);
+        return false;
+    }
+
+    this( char c ){
+        // must be correct for container storage
+        implMissing( __FILE__, __LINE__);
+    }
+}
+
+String new_String( String cont, int offset, int len ){
+    return cont[ offset .. offset+len ].dup;
+}
+String new_String( String cont ){
+    return cont.dup;
+}
+String String_valueOf( bool v ){
+    return v ? "true" : "false";
+}
+String String_valueOf( int v ){
+    return tango.text.convert.Integer.toString(v);
+}
+String String_valueOf( long v ){
+    return tango.text.convert.Integer.toString(v);
+}
+String String_valueOf( float v ){
+    return tango.text.convert.Float.toString(v);
+}
+String String_valueOf( double v ){
+    return tango.text.convert.Float.toString(v);
+}
+String String_valueOf( dchar v ){
+    return dcharToString(v);
+}
+String String_valueOf( char[] v ){
+    return v.dup;
+}
+String String_valueOf( char[] v, int offset, int len ){
+    return v[ offset .. offset+len ].dup;
+}
+String String_valueOf( Object v ){
+    return v is null ? "null" : v.toString();
+}
 bool CharacterIsDefined( dchar ch ){
     return (ch in tango.text.UnicodeData.unicodeData) !is null;
 }
@@ -615,7 +712,9 @@
     dchar[] r = tango.text.Unicode.toLower( buf );
     return r[0];
 }
-
+int length( String str ){
+    return str.length;
+}
 dchar CharacterToLower( dchar c ){
     dchar[] r = tango.text.Unicode.toLower( [c] );
     return r[0];
@@ -637,6 +736,11 @@
     return tango.text.Unicode.toUpper( str );
 }
 
+public String replaceFirst( String str, String regex, String replacement ){
+    implMissing(__FILE__,__LINE__);
+    return str;
+}
+
 public int indexOf( String str, char searched ){
     int res = tango.text.Util.locate( str, searched );
     if( res is str.length ) res = -1;
@@ -676,6 +780,10 @@
     return res;
 }
 
+public String replaceAll( String str, String regex, String replacement ){
+    implMissing(__FILE__,__LINE__);
+    return null;
+}
 public String replace( String str, char from, char to ){
     return tango.text.Util.replace( str.dup, from, to );
 }
@@ -704,8 +812,8 @@
     dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ];
 }
 
-public wchar[] toCharArray( String str ){
-    return toString16( str );
+public char[] toCharArray( String str ){
+    return str;
 }
 
 public bool endsWith( String src, String pattern ){
@@ -752,6 +860,10 @@
     return str;
 }
 
+/++
+ + This is like tango.stdc.stringz.toStringz, but in case of an empty input string,
+ + this function returns a pointer to a null value instead of a null ptr.
+ +/
 public char* toStringzValidPtr( String src ){
     if( src ){
         return src.toStringz();
@@ -861,6 +973,11 @@
         super(e);
     }
 }
+class ClassCastException : Exception {
+    this( String e = null ){
+        super(e);
+    }
+}
 
 interface Cloneable{
 }
@@ -926,7 +1043,42 @@
     }
 }
 
-interface Reader{
+class Reader{
+    protected Object   lock;
+    protected this(){
+        implMissing(__FILE__,__LINE__);
+    }
+    protected this(Object lock){
+        implMissing(__FILE__,__LINE__);
+    }
+    abstract  void  close();
+    void mark(int readAheadLimit){
+        implMissing(__FILE__,__LINE__);
+    }
+    bool markSupported(){
+        implMissing(__FILE__,__LINE__);
+        return false;
+    }
+    int read(){
+        implMissing(__FILE__,__LINE__);
+        return 0;
+    }
+    int read(char[] cbuf){
+        implMissing(__FILE__,__LINE__);
+        return 0;
+    }
+    abstract int read(char[] cbuf, int off, int len);
+    bool ready(){
+        implMissing(__FILE__,__LINE__);
+        return false;
+    }
+    void reset(){
+        implMissing(__FILE__,__LINE__);
+    }
+    long skip(long n){
+        implMissing(__FILE__,__LINE__);
+        return 0;
+    }
 }
 interface Writer{
 }
@@ -1044,7 +1196,7 @@
     return true;
 }
 
-int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){
+/+int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){
     int idx;
     foreach( e; s ){
         if( e == src ){
@@ -1053,7 +1205,8 @@
         idx++;
     }
     return -1;
-}
+}+/
+
 int arrayIndexOf(T)( T[] arr, T v ){
     int res = -1;
     int idx = 0;
@@ -1067,18 +1220,18 @@
     return res;
 }
 
-int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){
-    int res = -1;
-    int idx = 0;
-    foreach( p; seq ){
-        if( p == v){
-            res = idx;
-            break;
-        }
-        idx++;
-    }
-    return res;
-}
+// int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){
+//     int res = -1;
+//     int idx = 0;
+//     foreach( p; seq ){
+//         if( p == v){
+//             res = idx;
+//             break;
+//         }
+//         idx++;
+//     }
+//     return res;
+// }
 
 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){
     auto e = new Exception( null );
@@ -1108,3 +1261,30 @@
     const ImportData getImportData = ImportData( import(name), name );
 }
 
+interface CharSequence {
+    char           charAt(int index);
+    int             length();
+    CharSequence    subSequence(int start, int end);
+    String          toString();
+}
+
+class StringCharSequence : CharSequence {
+    private String str;
+    this( String str ){
+        this.str = str;
+    }
+    char           charAt(int index){
+        return str[index];
+    }
+    int             length(){
+        return str.length;
+    }
+    CharSequence    subSequence(int start, int end){
+        return new StringCharSequence( str[ start .. end ]);
+    }
+    String          toString(){
+        return str;
+    }
+}
+
+