|
@@ -27,13 +27,33 @@
|
|
A String buffer is an efficient way to build a big string by
|
|
A String buffer is an efficient way to build a big string by
|
|
appending small elements together.
|
|
appending small elements together.
|
|
**/
|
|
**/
|
|
|
|
+#if (js || flash)
|
|
|
|
+@:native("String")
|
|
|
|
+extern class StringBuf {
|
|
|
|
+ public function new():Void {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public inline function add( x : Dynamic ):String {
|
|
|
|
+ return untyped __this__ += x;
|
|
|
|
+ }
|
|
|
|
+ public inline function addChar( i : Int ):String {
|
|
|
|
+ return untyped __this__ += String.fromCharCode(i);
|
|
|
|
+ }
|
|
|
|
+ public inline function addSub( s : String, pos : Int, ?len : Int):String {
|
|
|
|
+ return untyped __this__ += s.substr(pos, len);
|
|
|
|
+ }
|
|
|
|
+ public inline function toString():String {
|
|
|
|
+ return untyped __this__;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+#else
|
|
class StringBuf {
|
|
class StringBuf {
|
|
|
|
|
|
/**
|
|
/**
|
|
Creates a new string buffer.
|
|
Creates a new string buffer.
|
|
**/
|
|
**/
|
|
public function new() {
|
|
public function new() {
|
|
- #if (js || cpp)
|
|
|
|
|
|
+ #if cpp
|
|
b = new Array();
|
|
b = new Array();
|
|
#elseif cs
|
|
#elseif cs
|
|
b = new cs.StringBuilder();
|
|
b = new cs.StringBuilder();
|
|
@@ -48,9 +68,7 @@ class StringBuf {
|
|
Adds the representation of any value to the string buffer.
|
|
Adds the representation of any value to the string buffer.
|
|
**/
|
|
**/
|
|
public inline function add( x : Dynamic ) {
|
|
public inline function add( x : Dynamic ) {
|
|
- #if js
|
|
|
|
- b[b.length] = x == null ? 'null' : x;
|
|
|
|
- #elseif cpp
|
|
|
|
|
|
+ #if cpp
|
|
b[b.length] = x;
|
|
b[b.length] = x;
|
|
#elseif cs
|
|
#elseif cs
|
|
b.Append(x);
|
|
b.Append(x);
|
|
@@ -65,12 +83,7 @@ class StringBuf {
|
|
Adds a part of a string to the string buffer.
|
|
Adds a part of a string to the string buffer.
|
|
**/
|
|
**/
|
|
public inline function addSub( s : String, pos : Int, ?len : Int ) {
|
|
public inline function addSub( s : String, pos : Int, ?len : Int ) {
|
|
- #if flash9
|
|
|
|
- if( len == null )
|
|
|
|
- b += s.substr(pos);
|
|
|
|
- else
|
|
|
|
- b += s.substr(pos,len);
|
|
|
|
- #elseif (js || cpp)
|
|
|
|
|
|
+ #if cpp
|
|
b[b.length] = s.substr(pos,len);
|
|
b[b.length] = s.substr(pos,len);
|
|
#elseif cs
|
|
#elseif cs
|
|
var l:Int = (len == null) ? (s.length - pos) : len;
|
|
var l:Int = (len == null) ? (s.length - pos) : len;
|
|
@@ -87,10 +100,8 @@ class StringBuf {
|
|
Adds a character to the string buffer.
|
|
Adds a character to the string buffer.
|
|
**/
|
|
**/
|
|
public inline function addChar( c : Int ) untyped {
|
|
public inline function addChar( c : Int ) untyped {
|
|
- #if (js || cpp)
|
|
|
|
|
|
+ #if cpp
|
|
b[b.length] = String.fromCharCode(c);
|
|
b[b.length] = String.fromCharCode(c);
|
|
- #elseif (flash && !flash9)
|
|
|
|
- b += String["fromCharCode"](c);
|
|
|
|
#elseif cs
|
|
#elseif cs
|
|
b.Append(cast(c, cs.StdTypes.Char16));
|
|
b.Append(cast(c, cs.StdTypes.Char16));
|
|
#elseif java
|
|
#elseif java
|
|
@@ -105,7 +116,7 @@ class StringBuf {
|
|
The buffer is not emptied by this operation.
|
|
The buffer is not emptied by this operation.
|
|
**/
|
|
**/
|
|
public inline function toString() : String {
|
|
public inline function toString() : String {
|
|
- #if (js || cpp)
|
|
|
|
|
|
+ #if cpp
|
|
return b.join("");
|
|
return b.join("");
|
|
#elseif cs
|
|
#elseif cs
|
|
return b.ToString();
|
|
return b.ToString();
|
|
@@ -117,14 +128,15 @@ class StringBuf {
|
|
}
|
|
}
|
|
|
|
|
|
private var b :
|
|
private var b :
|
|
- #if (js || cpp)
|
|
|
|
|
|
+ #if cpp
|
|
Array<Dynamic>
|
|
Array<Dynamic>
|
|
#elseif cs
|
|
#elseif cs
|
|
- cs.StringBuilder
|
|
|
|
|
|
+ cs.StringBuilder
|
|
#elseif java
|
|
#elseif java
|
|
java.lang.StringBuilder
|
|
java.lang.StringBuilder
|
|
#else
|
|
#else
|
|
String
|
|
String
|
|
#end;
|
|
#end;
|
|
|
|
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
+#end
|