Mercurial > projects > dwt2
annotate base/src/java/lang/StringBuffer.d @ 43:b98647bc0aef
swt win compiles for d2+phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 25 Mar 2009 17:08:05 +0100 |
parents | 1bf55a6eb092 |
children | fcf926c91ca4 |
rev | line source |
---|---|
3 | 1 module java.lang.StringBuffer; |
2 | |
3 import java.lang.util; | |
4 | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
5 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
6 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
|
7 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
|
8 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
9 static import std.uni; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
10 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
|
11 } |
3 | 12 |
13 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
|
14 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
15 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
|
16 TBuf buf; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
17 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
18 const int STDINCR = 128; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
19 char[] buf; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
20 int used; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
21 } |
3 | 22 |
23 public this(){ | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
24 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
25 buf = new TBuf(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
26 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
27 } |
3 | 28 } |
29 | |
30 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
|
31 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
32 buf = new TBuf(cap); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
33 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
34 buf.length = cap; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
35 } |
3 | 36 } |
37 | |
43
b98647bc0aef
swt win compiles for d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
27
diff
changeset
|
38 public this( CString content ){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
39 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
40 buf = new TBuf( content ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
41 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
42 buf.length = content.length + STDINCR; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
43 buf[ 0 .. content.length ] = content; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
44 used = content.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
45 } |
3 | 46 } |
47 | |
48 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
|
49 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
50 return buf.slice()[ index ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
51 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
52 return buf[ index ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
53 } |
3 | 54 } |
55 | |
56 int length(){ | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
57 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
58 return buf.length(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
59 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
60 return used; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
61 } |
3 | 62 } |
63 | |
64 CharSequence subSequence(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
|
65 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
66 return new StringBuffer( buf.slice()[ start .. end ] ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
67 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
68 return new StringBuffer( cast(String)buf[ start .. end ] ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
69 } |
3 | 70 } |
71 | |
72 String toString(){ | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
73 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
74 return buf.slice(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
75 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
76 return cast(String)buf[ 0 .. used ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
77 } |
3 | 78 } |
79 | |
43
b98647bc0aef
swt win compiles for d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
27
diff
changeset
|
80 StringBuffer append( CString s ){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
81 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
82 buf.append( s ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
83 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
84 if( buf.length < used + s.length ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
85 buf.length = used + s.length + STDINCR; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
86 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
87 buf[ used .. used + s.length ] = s; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
88 used += s.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
89 } |
3 | 90 return this; |
91 } | |
92 | |
43
b98647bc0aef
swt win compiles for d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
27
diff
changeset
|
93 StringBuffer append( CString 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
|
94 return append( s[ offset .. offset+len ] ); |
3 | 95 } |
96 | |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
97 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
|
98 return append( other.slice() ); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
99 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
100 |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
101 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
|
102 return append( obj.toString() ); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
103 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
104 |
3 | 105 StringBuffer append( char c ){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
106 char[1] src; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
107 src[0] = c; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
108 return append( cast(String)src ); |
3 | 109 } |
110 | |
111 StringBuffer append( wchar c ){ | |
112 wchar[1] src; | |
113 src[0] = c; | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
114 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
115 char[2] trg; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
116 auto arr = tango.text.convert.Utf.toString( src, trg ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
117 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
118 auto arr = std.utf.toUTF8( src ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
119 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
120 return append( arr ); |
3 | 121 } |
122 | |
123 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
|
124 return append( String_valueOf(i) ); |
3 | 125 } |
126 | |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
127 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
|
128 return append( String_valueOf(i) ); |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
129 } |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
130 |
3 | 131 StringBuffer append( dchar c ){ |
132 dchar[1] src; | |
133 src[0] = c; | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
134 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
135 char[4] trg; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
136 auto arr = tango.text.convert.Utf.toString( src, trg ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
137 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
138 auto arr = std.utf.toUTF8( src ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
139 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
140 return append( arr ); |
3 | 141 } |
142 | |
143 | |
25 | 144 StringBuffer insert(int offset, int i){ |
145 return insert( offset, String_valueOf(i) ); | |
146 } | |
43
b98647bc0aef
swt win compiles for d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
27
diff
changeset
|
147 StringBuffer insert(int offset, CString str){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
148 return replace( offset, offset, str ); |
3 | 149 } |
150 | |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
151 StringBuffer insert(int offset, StringBuffer other){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
152 return insert( offset, other.slice()); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
153 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
154 |
43
b98647bc0aef
swt win compiles for d2+phobos
Frank Benoit <benoit@tionex.de>
parents:
27
diff
changeset
|
155 StringBuffer replace(int start, int end, CString str) { |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
156 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
157 buf.select(start, end-start); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
158 buf.replace(str); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
159 buf.select(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
160 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
161 int incr = end - start - str.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
162 if( incr > 0 ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
163 if( buf.length < used + incr ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
164 char[] newbuf = new char[ 2*(used + incr) + STDINCR ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
165 newbuf[ 0 .. start ] = buf[ 0 .. start ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
166 newbuf[ start .. start + str.length ] = str; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
167 newbuf[ start + str.length .. used + str.length ] = buf[ end .. used ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
168 buf = newbuf; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
169 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
170 else{ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
171 char* s = buf.ptr + start; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
172 char* t = buf.ptr + start + str.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
173 char* e = buf.ptr + start + str.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
174 while( s !is e ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
175 *t = *s; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
176 s++; t++; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
177 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
178 buf[ start .. start + str.length ] = str; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
179 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
180 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
181 else if( incr == 0 ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
182 buf[ start .. end ] = str; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
183 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
184 else{ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
185 buf[ start .. end ] = str; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
186 char* s = buf.ptr + end; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
187 char* t = buf.ptr + start + str.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
188 char* e = buf.ptr + start + str.length; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
189 while( s !is e ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
190 *t = *s; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
191 s--; t--; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
192 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
193 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
194 used += incr; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
195 } |
3 | 196 return this; |
197 } | |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
198 |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
199 void setLength( int newLength ){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
200 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
201 buf.truncate( newLength ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
202 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
203 if( buf.length < newLength ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
204 buf.length = 2*newLength + STDINCR; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
205 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
206 used = newLength; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
207 } |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
208 } |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
209 |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
210 String substring( 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
|
211 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
212 return buf.slice()[ start .. end ].dup; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
213 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
214 return buf[ start .. end ].idup; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
215 } |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
216 } |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
217 |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
218 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
|
219 replace( start, end, "" ); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
220 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
221 String slice(){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
222 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
223 return buf.slice(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
224 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
225 return cast(String)buf[ 0 .. used ]; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
226 } |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
227 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
228 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
|
229 setLength( start ); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
230 } |
3 | 231 } |
232 | |
233 |