annotate base/src/java/lang/StringBuffer.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 fcf926c91ca4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 module java.lang.StringBuffer;
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 import java.lang.util;
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
4 import java.lang.exceptions;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
5 import java.lang.String;
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
7 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
8 static import tango.text.Text;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
9 static import tango.text.convert.Utf;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
10 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
11 static import std.outbuffer;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
12 static import std.utf;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
13 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 class StringBuffer : CharSequence {
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
16 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
17 alias tango.text.Text.Text!(char) TBuf;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
18 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
19 alias std.outbuffer.OutBuffer TBuf;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
20 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
21 private TBuf buffer;
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 public this(){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
24 buffer = new TBuf();
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 public this( int cap ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
28 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
29 buffer = new TBuf(cap);
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
30 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
31 buffer = new TBuf();
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
32 buffer.reserve(cap);
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
33 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
36 public this( String content ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
37 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
38 buffer = new TBuf( content );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
39 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
40 buffer = new TBuf();
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
41 append(content);
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
42 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 char charAt(int index){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
46 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
47 return buffer.slice()[ index ];
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
48 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
49 return buffer.toBytes()[ index ];
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
50 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 int length(){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
54 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
55 return buffer.length();
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
56 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
57 return buffer.offset;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
58 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 CharSequence subSequence(int start, int end){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
62 return new StringCharSequence( substring(start, end) );
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 String toString(){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
66 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
67 return buffer.slice().dup;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
68 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
69 return buffer.toString();
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
70 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
73 StringBuffer append( in char[] s ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
74 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
75 buffer.append( s );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
76 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
77 buffer.write( s );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
78 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 return this;
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
82 StringBuffer append( in char[] s, int offset, int len ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
83 return append( s[ offset .. offset+len ] );
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
86 StringBuffer append( StringBuffer other ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
87 return append( other.slice() );
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
88 }
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
89
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
90 StringBuffer append( Object obj ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
91 return append( obj.toString() );
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
92 }
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
93
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 StringBuffer append( char c ){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
95 version(Tango){
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
96 char[1] src = c;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
97 return append( src );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
98 } else { // Phobos
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
99 buffer.write(c);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
100 return this;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
101 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 StringBuffer append( wchar c ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
105 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
106 wchar[1] src = c;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
107 char[1 * 2 + 3] trg; // or Tango will reallocate output to input.length * 2 + 3
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
108 auto arr = tango.text.convert.Utf.toString( src, trg );
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
109 return append( arr );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
110 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
111 char[4] trg;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
112 return append( trg[0 .. std.utf.encode(trg, c)] );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
113 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
114 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
115
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
116 StringBuffer append( dchar c ){
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
117 version(Tango){
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
118 dchar[1] src = c;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
119 char[1 * 2 + 4] trg; // or Tango will reallocate output to input.length * 2 + 4
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
120 auto arr = tango.text.convert.Utf.toString( src, trg );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
121 return append( arr );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
122 } else { // Phobos
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
123 char[4] trg;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
124 return append( trg[0 .. std.utf.encode(trg, c)] );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
125 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127
84
fcf926c91ca4 Added base classes
Frank Benoit <benoit@tionex.de>
parents: 43
diff changeset
128 StringBuffer append( bool i ){
fcf926c91ca4 Added base classes
Frank Benoit <benoit@tionex.de>
parents: 43
diff changeset
129 return append( String_valueOf(i) );
fcf926c91ca4 Added base classes
Frank Benoit <benoit@tionex.de>
parents: 43
diff changeset
130 }
fcf926c91ca4 Added base classes
Frank Benoit <benoit@tionex.de>
parents: 43
diff changeset
131
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132 StringBuffer append( int i ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
133 return append( String_valueOf(i) );
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135
15
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
136 StringBuffer append( long i ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
137 return append( String_valueOf(i) );
15
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
138 }
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
139
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
140 StringBuffer replace(int start, int end, in char[] str) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
141 if(start < 0 || start > length() || start > end)
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
142 throw new StringIndexOutOfBoundsException("start is negative, greater than length(), or greater than end");
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
143
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
144 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
145 buffer.select(start, end-start);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
146 buffer.replace(str);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
147 buffer.select();
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
148 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
149 if(end >= length()) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
150 buffer.offset = start;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
151 return append(str);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
152 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
153 int strEnd = start + str.length, incr = strEnd - end;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
154
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
155 if( incr > 0 ) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
156 buffer.spread(end, incr);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
157 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
158 else if( incr < 0 ) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
159 auto bytes = buffer.toBytes();
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
160 bytes[ start .. strEnd ] = cast(ubyte[])str;
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
161 foreach (i, b; bytes[ end .. $ ]) {
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
162 bytes[strEnd + i] = bytes[end + i];
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
163 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
164 buffer.offset += incr;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
165 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
166 buffer.toBytes()[ start .. strEnd ] = cast(ubyte[])str;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
167 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
168 return this;
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169 }
15
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
170
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
171 StringBuffer insert(int offset, in char[] str){
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
172 return replace( offset, offset, str );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
173 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
174
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
175 StringBuffer insert(int offset, int i){
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
176 return insert( offset, String_valueOf(i) );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
177 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
178
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
179 StringBuffer insert(int offset, StringBuffer other){
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
180 return insert( offset, other.slice() );
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
181 }
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
182
15
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
183 void setLength( int newLength ){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
184 if(newLength < 0)
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
185 throw new IndexOutOfBoundsException("the newLength argument is negative");
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
186
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
187 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
188 buffer.truncate( newLength );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
189 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
190 immutable d = newLength - length();
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
191 if( d > 0 )
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
192 buffer.reserve(d);
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
193 else
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
194 buffer.offset += d;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
195 }
15
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
196 }
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
197
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
198 String substring( int start, int end ){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
199 if(start < 0 || end < 0 || end > length() || start > end)
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
200 throw new StringIndexOutOfBoundsException("start or end are negative, if end is greater than length(), or if start is greater than end");
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
201
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
202 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
203 return buffer.slice()[ start .. end ].dup;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
204 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
205 return (cast(char[]) buffer.toBytes()[ start .. end ]).idup;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
206 }
15
c4b1a29263fc Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents: 3
diff changeset
207 }
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
208
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
209 void delete_( int start, int end ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
210 replace( start, end, "" );
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
211 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
212
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
213 TryConst!(char)[] slice(){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
214 version(Tango){
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
215 return buffer.slice();
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
216 } else { // Phobos
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
217 return cast(TryConst!(char)[]) buffer.toBytes();
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
218 }
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
219 }
120
536e43f63c81 Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents: 84
diff changeset
220
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
221 void truncate( int start ){
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 16
diff changeset
222 setLength( start );
16
dbfb303e8fb0 first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents: 15
diff changeset
223 }
3
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224 }
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
225
4c0057e71936 Made a class for StringBuffer
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226