Browse Source

Added short array appender.

woollybah 7 năm trước cách đây
mục cha
commit
84cb276e28

+ 1 - 0
stringbuilder.mod/common.bmx

@@ -63,6 +63,7 @@ Extern
 	Function bmx_stringbuilder_append_ulong(buffer:Byte Ptr, value:ULong)
 	Function bmx_stringbuilder_append_sizet(buffer:Byte Ptr, value:Size_T)
 ?
+	Function bmx_stringbuilder_append_shorts(buffer:Byte Ptr, shorts:Short Ptr, length:Int)
 	Function bmx_stringbuilder_left:String(buffer:Byte Ptr, length:Int)
 	Function bmx_stringbuilder_right:String(buffer:Byte Ptr, length:Int)
 	

+ 25 - 0
stringbuilder.mod/examples/example_16.bmx

@@ -0,0 +1,25 @@
+'
+' Append an array of shorts to a string builder
+'
+SuperStrict
+
+Framework BRL.StringBuilder
+Import brl.standardio
+
+Local sb:TStringBuilder = New TStringBuilder
+
+sb.Append("Shorts!... ")
+
+Local shorts:Short[10]
+' characters A to J
+For Local i:Int = 0 Until shorts.length
+	shorts[i] = 65 + i
+Next
+
+sb.AppendShorts(shorts, shorts.length)
+
+Print sb.ToString()
+
+
+
+

+ 10 - 0
stringbuilder.mod/glue.c

@@ -563,6 +563,16 @@ void bmx_stringbuilder_append_sizet(struct MaxStringBuilder * buf, BBSIZET value
 
 #endif
 
+void bmx_stringbuilder_append_shorts(struct MaxStringBuilder * buf, short * shorts, int length) {
+	if (length > 0) {
+		bmx_stringbuilder_resize(buf, buf->count + length);
+		BBChar * p = buf->buffer + buf->count;
+		memcpy(p, shorts, length * sizeof(BBChar));
+		
+		buf->count += length;
+	}	
+}
+
 BBString * bmx_stringbuilder_left(struct MaxStringBuilder * buf, int length) {
 	if (length <= 0) {
 		return &bbEmptyString;

+ 8 - 0
stringbuilder.mod/stringbuilder.bmx

@@ -250,6 +250,14 @@ Public
 		bmx_stringbuilder_append_utf8string(buffer, chars)
 		Return Self
 	End Method
+
+	Rem
+	bbdoc: Appends an array of shorts onto the string builder.
+	End Rem
+	Method AppendShorts:TStringBuilder(shorts:Short Ptr, length:Int)
+		bmx_stringbuilder_append_shorts(buffer, shorts, length)
+		Return Self
+	End Method
 	
 	Rem
 	bbdoc: Finds first occurance of a sub string.