Mercurial > projects > dwt2
comparison base/src/java/lang/Integer.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 | 46539f5c5993 |
children |
comparison
equal
deleted
inserted
replaced
119:d00e8db0a568 | 120:536e43f63c81 |
---|---|
2 | 2 |
3 import java.lang.util; | 3 import java.lang.util; |
4 import java.lang.exceptions; | 4 import java.lang.exceptions; |
5 import java.lang.Number; | 5 import java.lang.Number; |
6 import java.lang.Class; | 6 import java.lang.Class; |
7 import java.lang.Character; | |
7 import java.lang.String; | 8 import java.lang.String; |
8 | 9 |
9 version(Tango){ | 10 version(Tango){ |
11 static import tango.text.convert.Integer; | |
10 } else { // Phobos | 12 } else { // Phobos |
11 static import std.conv; | 13 static import std.conv; |
12 static import std.string; | 14 static import std.string; |
13 } | |
14 | |
15 version(Tango){ | |
16 } else { // Phobos | |
17 } | 15 } |
18 | 16 |
19 | 17 |
20 class Integer : Number { | 18 class Integer : Number { |
21 | 19 |
37 super(); | 35 super(); |
38 this.value = parseInt(s); | 36 this.value = parseInt(s); |
39 } | 37 } |
40 | 38 |
41 public static String toString( int i, int radix ){ | 39 public static String toString( int i, int radix ){ |
42 switch( radix ){ | 40 if(radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) |
43 case 2: | 41 radix = 10; |
44 return toBinaryString(i); | 42 version(Tango){ |
45 case 8: | 43 switch( radix ){ |
46 return toOctalString(i); | 44 case 10: |
47 case 10: | 45 return tango.text.convert.Integer.toString(i); |
48 return toString(i); | 46 case 16: |
49 case 16: | 47 return tango.text.convert.Integer.toString(i, "x" ); |
50 return toHexString(i); | 48 case 2: |
51 default: | 49 return tango.text.convert.Integer.toString(i, "b" ); |
52 implMissing( __FILE__, __LINE__ ); | 50 case 8: |
53 return null; | 51 return tango.text.convert.Integer.toString(i, "o" ); |
52 default: | |
53 implMissingInTango( __FILE__, __LINE__ ); | |
54 return null; | |
55 } | |
56 } else { // Phobos | |
57 return std.conv.to!(String)(i, radix); | |
54 } | 58 } |
55 } | 59 } |
56 | 60 |
57 public static String toHexString( int i ){ | 61 public static String toHexString( int i ){ |
58 version(Tango){ | 62 return toString(i, 16); |
59 return tango.text.convert.Integer.toString(i, "x" ); | |
60 } else { // Phobos | |
61 return std.string.format("%x", i); | |
62 } | |
63 } | 63 } |
64 | 64 |
65 public static String toOctalString( int i ){ | 65 public static String toOctalString( int i ){ |
66 version(Tango){ | 66 return toString(i, 8); |
67 return tango.text.convert.Integer.toString(i, "o" ); | |
68 } else { // Phobos | |
69 return std.string.format("%o", i); | |
70 } | |
71 } | 67 } |
72 | 68 |
73 public static String toBinaryString( int i ){ | 69 public static String toBinaryString( int i ){ |
74 version(Tango){ | 70 return toString(i, 2); |
75 return tango.text.convert.Integer.toString(i, "b" ); | |
76 } else { // Phobos | |
77 return std.string.format("%b", i); | |
78 } | |
79 } | 71 } |
80 | 72 |
81 public static String toString( int i ){ | 73 public static String toString( int i ){ |
82 version(Tango){ | 74 return String_valueOf(i); |
83 return tango.text.convert.Integer.toString(i); | |
84 } else { // Phobos | |
85 return std.conv.to!(string)( i ); | |
86 } | |
87 } | 75 } |
88 | 76 |
89 public static int parseInt( String s, int radix ){ | 77 public static int parseInt( String s, int radix ){ |
78 if(radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) | |
79 throw new NumberFormatException("The radix is out of range"); | |
90 version(Tango){ | 80 version(Tango){ |
91 try{ | 81 try{ |
92 return tango.text.convert.Integer.toLong( s, radix ); | 82 return tango.text.convert.Integer.toInt( s, radix ); |
93 } | 83 } |
94 catch( IllegalArgumentException e ){ | 84 catch( IllegalArgumentException e ){ |
95 throw new NumberFormatException( e ); | 85 throw new NumberFormatException( e ); |
96 } | 86 } |
97 } else { // Phobos | 87 } else { // Phobos |
98 try{ | 88 try{ |
99 return std.conv.parse!(int)( s, radix ); | 89 immutable res = std.conv.parse!(int)( s, radix ); |
90 if(s.length) | |
91 throw new NumberFormatException("String has invalid characters: " ~ s); | |
92 return res; | |
100 } | 93 } |
101 catch( std.conv.ConvException e ){ | 94 catch( std.conv.ConvException e ){ |
102 throw new NumberFormatException( e ); | 95 throw new NumberFormatException( e ); |
103 } | 96 } |
104 } | 97 } |
111 public static Integer valueOf( String s, int radix ){ | 104 public static Integer valueOf( String s, int radix ){ |
112 return new Integer( parseInt( s, radix )); | 105 return new Integer( parseInt( s, radix )); |
113 } | 106 } |
114 | 107 |
115 public static Integer valueOf( String s ){ | 108 public static Integer valueOf( String s ){ |
116 return valueOf( parseInt(s)); | 109 return valueOf(parseInt(s)); |
117 } | 110 } |
118 | 111 |
119 public static Integer valueOf( int i ){ | 112 public static Integer valueOf( int i ){ |
120 return new Integer(i); | 113 return new Integer(i); |
121 } | 114 } |
147 public override hash_t toHash(){ | 140 public override hash_t toHash(){ |
148 return intValue(); | 141 return intValue(); |
149 } | 142 } |
150 | 143 |
151 public override String toString(){ | 144 public override String toString(){ |
152 version(Tango){ | 145 return toString(value); |
153 return tango.text.convert.Integer.toString( value ); | |
154 } else { // Phobos | |
155 return std.conv.to!(string)(value); | |
156 } | |
157 } | 146 } |
158 | 147 |
159 private static Class TYPE_; | 148 private static Class TYPE_; |
160 public static Class TYPE(){ | 149 public static Class TYPE(){ |
161 if( TYPE_ is null ){ | 150 if( TYPE_ is null ){ |