Mercurial > projects > dwt2
annotate java/src/java/lang/StringBuffer.d @ 15:c4b1a29263fc
Successful build of org.eclipse.text
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 15 Mar 2009 19:51:07 +0100 |
parents | 4c0057e71936 |
children | dbfb303e8fb0 |
rev | line source |
---|---|
3 | 1 module java.lang.StringBuffer; |
2 | |
3 import java.lang.util; | |
4 | |
5 static import tango.text.Text; | |
6 static import tango.text.convert.Utf; | |
7 | |
8 class StringBuffer : CharSequence { | |
9 alias tango.text.Text.Text!(char) TBuf; | |
10 TBuf buf; | |
11 | |
12 public this(){ | |
13 buf = new TBuf(); | |
14 } | |
15 | |
16 public this( int cap ){ | |
17 buf = new TBuf( cap ); | |
18 } | |
19 | |
20 public this( String content ){ | |
21 buf = new TBuf( content ); | |
22 } | |
23 | |
24 char charAt(int index){ | |
25 return buf.slice()[ index ]; | |
26 } | |
27 | |
28 int length(){ | |
29 return buf.length(); | |
30 } | |
31 | |
32 CharSequence subSequence(int start, int end){ | |
33 return new StringBuffer( buf.slice()[ start .. end ] ); | |
34 } | |
35 | |
36 String toString(){ | |
37 return buf.slice(); | |
38 } | |
39 | |
40 StringBuffer append( String s ){ | |
41 buf.append( s ); | |
42 return this; | |
43 } | |
44 | |
45 StringBuffer append( String s, int offset, int len ){ | |
46 buf.append( s[ offset .. offset+len ] ); | |
47 return this; | |
48 } | |
49 | |
50 StringBuffer append( char c ){ | |
51 buf.append( c ); | |
52 return this; | |
53 } | |
54 | |
55 StringBuffer append( wchar c ){ | |
56 wchar[1] src; | |
57 src[0] = c; | |
58 char[2] trg; | |
59 auto s = tango.text.convert.Utf.toString( src, trg ); | |
60 buf.append( s ); | |
61 return this; | |
62 } | |
63 | |
64 StringBuffer append( int i ){ | |
65 buf.append( String_valueOf(i) ); | |
66 return this; | |
67 } | |
68 | |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
69 StringBuffer append( long i ){ |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
70 buf.append( String_valueOf(i) ); |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
71 return this; |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
72 } |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
73 |
3 | 74 StringBuffer append( dchar c ){ |
75 dchar[1] src; | |
76 src[0] = c; | |
77 char[4] trg; | |
78 auto s = tango.text.convert.Utf.toString( src, trg ); | |
79 buf.append( s ); | |
80 return this; | |
81 } | |
82 | |
83 | |
84 StringBuffer insert(int offset, String str){ | |
85 buf.select(offset, 0); | |
86 buf.replace(str); | |
87 buf.select(); | |
88 return this; | |
89 } | |
90 | |
91 StringBuffer replace(int start, int end, String str) { | |
92 buf.select(start, end-start); | |
93 buf.replace(str); | |
94 buf.select(); | |
95 return this; | |
96 } | |
15
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
97 |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
98 void setLength( int newLength ){ |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
99 buf.truncate( newLength ); |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
100 } |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
101 |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
102 String substring( int start, int end ){ |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
103 return buf.slice()[ start .. end ].dup; |
c4b1a29263fc
Successful build of org.eclipse.text
Frank Benoit <benoit@tionex.de>
parents:
3
diff
changeset
|
104 } |
3 | 105 } |
106 | |
107 |