Mercurial > projects > dwt2
annotate java/src/java/lang/StringBuffer.d @ 21:9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 19 Mar 2009 20:38:55 +0100 |
parents | dbfb303e8fb0 |
children | f713da8bc051 |
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 | |
38 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
|
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 | |
80 StringBuffer append( String 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 | |
93 StringBuffer append( String 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 | |
144 StringBuffer insert(int offset, String str){ | |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
145 return replace( offset, offset, str ); |
3 | 146 } |
147 | |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
148 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
|
149 return insert( offset, other.slice()); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
150 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
151 |
3 | 152 StringBuffer replace(int start, int end, String str) { |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
153 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
154 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
|
155 buf.replace(str); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
156 buf.select(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
157 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
158 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
|
159 if( incr > 0 ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 buf = newbuf; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
166 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
167 else{ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 *t = *s; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
173 s++; t++; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
174 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
175 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
|
176 } |
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 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
|
179 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
|
180 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
181 else{ |
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 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
|
184 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
|
185 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
|
186 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
|
187 *t = *s; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
188 s--; t--; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
189 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
190 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
191 used += incr; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
192 } |
3 | 193 return this; |
194 } | |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
195 |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
196 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
|
197 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
198 buf.truncate( newLength ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
199 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
200 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
|
201 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
|
202 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
203 used = newLength; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
204 } |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
205 } |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
206 |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
207 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
|
208 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
209 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
|
210 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
211 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
|
212 } |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
213 } |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
214 |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
215 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
|
216 replace( start, end, "" ); |
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 String slice(){ |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
219 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
220 return buf.slice(); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
221 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
16
diff
changeset
|
222 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
|
223 } |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
224 } |
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
225 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
|
226 setLength( start ); |
16
dbfb303e8fb0
first complete successful compile (win-only)
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
227 } |
3 | 228 } |
229 | |
230 |