Mercurial > projects > dwt2
view base/src/java/lang/System.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | 9f4c18c268b2 |
children |
line wrap: on
line source
/** * Authors: Frank Benoit <keinfarbton@googlemail.com> */ module java.lang.System; import java.lang.util; import java.lang.exceptions; import java.io.PrintStream; version(Tango){ static import tango.sys.Environment; static import tango.core.Exception; static import tango.io.model.IFile; static import tango.time.Clock; static import tango.stdc.stdlib; } else { // Phobos static import std.c.stdlib; static import std.datetime; static import std.path; } template SimpleType(T) { debug{ static void validCheck(uint SrcLen, uint DestLen, uint copyLen){ if(SrcLen < copyLen || DestLen < copyLen|| SrcLen < 0 || DestLen < 0){ //Util.trace("Error : SimpleType.arraycopy(), out of bounds."); assert(0); } } } static void remove(ref T[] items, int index) { if(items.length == 0) return; if(index < 0 || index >= items.length){ throw new ArrayIndexOutOfBoundsException(__FILE__, __LINE__); } T element = items[index]; int length = items.length; if(length == 1){ items.length = 0; return;// element; } if(index == 0) items = items[1 .. $]; else if(index == length - 1) items = items[0 .. index]; else items = items[0 .. index] ~ items[index + 1 .. $]; } static void insert(ref T[] items, T item, int index = -1) { if(index == -1) index = items.length; if(index < 0 || index > items.length ){ throw new ArrayIndexOutOfBoundsException(__FILE__, __LINE__); } if(index == items.length){ items ~= item; }else if(index == 0){ T[] newVect; newVect ~= item; items = newVect ~ items; }else if(index < items.length ){ T[] arr1 = items[0 .. index]; T[] arr2 = items[index .. $]; // Important : if you write like the following commented, // you get wrong data // code: T[] arr1 = items[0..index]; // T[] arr2 = items[index..$]; // items = arr1 ~ item; // error, !!! // items ~= arr2; // item replace the arrr2[0] here items = arr1 ~ item ~ arr2; } } static void arraycopy(in T[] src, uint srcPos, T[] dest, uint destPos, uint len) { if(len == 0) return; assert(src); assert(dest); debug{validCheck(src.length - srcPos, dest.length - destPos, len);} // overlapping? if((src.ptr <= dest.ptr && src.ptr + len > dest.ptr) ||(src.ptr >= dest.ptr && src.ptr < dest.ptr + len)){ if( destPos < srcPos ){ for(int i=0; i<len; ++i){ dest[destPos+i] = cast(T)src[srcPos+i]; } } else{ for(int i=len-1; i>=0; --i){ dest[destPos+i] = cast(T)src[srcPos+i]; } } }else{ dest[destPos..(len+destPos)] = cast(T[])src[srcPos..(len+srcPos)]; } } } class System { static void arraycopyT(T)(T[] src, uint srcPos, T[] dest, uint destPos, uint len) { if(len == 0) return; assert(src); assert(dest); debug{validCheck(src.length - srcPos, dest.length - destPos, len);} // overlapping? if((src.ptr <= dest.ptr && src.ptr + len > dest.ptr) ||(src.ptr >= dest.ptr && src.ptr < dest.ptr + len)){ if( destPos < srcPos ){ for(int i=0; i<len; ++i){ dest[destPos+i] = cast(T)src[srcPos+i]; } } else{ for(int i=len-1; i>=0; --i){ dest[destPos+i] = cast(T)src[srcPos+i]; } } }else{ dest[destPos..(len+destPos)] = cast(T[])src[srcPos..(len+srcPos)]; } } alias SimpleType!(int).arraycopy arraycopy; alias SimpleType!(byte).arraycopy arraycopy; alias SimpleType!(double).arraycopy arraycopy; alias SimpleType!(float).arraycopy arraycopy; alias SimpleType!(short).arraycopy arraycopy; alias SimpleType!(long).arraycopy arraycopy; alias SimpleType!(uint).arraycopy arraycopy; alias SimpleType!(ushort).arraycopy arraycopy; alias SimpleType!(ubyte).arraycopy arraycopy; alias SimpleType!(ulong).arraycopy arraycopy; alias SimpleType!(char).arraycopy arraycopy; alias SimpleType!(wchar).arraycopy arraycopy; alias SimpleType!(Object).arraycopy arraycopy; alias SimpleType!(void*).arraycopy arraycopy; alias SimpleType!(int[]).arraycopy arraycopy; alias SimpleType!(byte[]).arraycopy arraycopy; alias SimpleType!(double[]).arraycopy arraycopy; alias SimpleType!(float[]).arraycopy arraycopy; alias SimpleType!(short[]).arraycopy arraycopy; alias SimpleType!(long[]).arraycopy arraycopy; alias SimpleType!(uint[]).arraycopy arraycopy; alias SimpleType!(ushort[]).arraycopy arraycopy; alias SimpleType!(ubyte[]).arraycopy arraycopy; alias SimpleType!(ulong[]).arraycopy arraycopy; alias SimpleType!(String).arraycopy arraycopy; alias SimpleType!(wchar[]).arraycopy arraycopy; alias SimpleType!(Object[]).arraycopy arraycopy; alias SimpleType!(void*[]).arraycopy arraycopy; alias SimpleType!(void*[]).arraycopy arraycopy; static long currentTimeMillis(){ version(Tango) return tango.time.Clock.Clock.now().ticks() / 10000; else return std.datetime.Clock.currStdTime(); } static void exit( int code ){ version(Tango) tango.stdc.stdlib.exit(code); else std.c.stdlib.exit(code); } public static int identityHashCode(Object x){ if( x is null ){ return 0; } 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 ){ /* Get values for local org.eclipse.swt specific keys */ String* p; if (key[0..3] == "org.eclipse.swt") { 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" : version(Tango) return tango.io.model.IFile.FileConst.PathSeparatorString ; else return std.path.sep; default: return null; } } } public static void setProperty ( String key, String value ) { /* set property for local org.eclipse.swt keys */ if (key[0..3] == "org.eclipse.swt") { if (key !is null && value !is null) localProperties[ key ] = value; /* else set properties for global system keys (environment) */ } else { } } private static PrintStream err__; public static PrintStream err(){ if( err__ is null ){ err__ = new PrintStream(null); } return err__; } private static PrintStream out__; public static PrintStream out_(){ if( out__ is null ){ out__ = new PrintStream(null); } return out__; } private static String[String] localProperties; }