From ba88c3789df2034e2f882caa16dba0b8720717fe Mon Sep 17 00:00:00 2001 From: Sebastian Loncar Date: Sat, 2 Aug 2014 09:45:34 +0200 Subject: [PATCH] Fixed StringBuilder.Length --- Frameworks/JsClr/System/Text/StringBuilder.cs | 233 +++++++++--------- 1 file changed, 122 insertions(+), 111 deletions(-) diff --git a/Frameworks/JsClr/System/Text/StringBuilder.cs b/Frameworks/JsClr/System/Text/StringBuilder.cs index 89c7452..c4bdf73 100644 --- a/Frameworks/JsClr/System/Text/StringBuilder.cs +++ b/Frameworks/JsClr/System/Text/StringBuilder.cs @@ -6,75 +6,75 @@ namespace SharpKit.JavaScript.Private { - [JsType(Name = "System.Text.StringBuilder", Filename="~/res/System.Text.js")] - class JsImplStringBuilder - { - JsExtendedArray array; - int length; - - public JsImplStringBuilder() - { - this.array = new string[0].As(); - this.length = 0; - - } - - public JsImplStringBuilder(int len) - { - this.array = new string[0].As(); - this.length = 0; - - } - - public JsImplStringBuilder(string s) - { - this.array = new string[] { s }.As(); - this.length = s == null ? 0 : s.Length; - } - - - public void Append(char s) - { - this.array.push(s); - this.length += 1; - } - - public void Append(string s) - { - this.array.push(s); - this.length += s.Length; - } - - public void AppendFormat(string s, object arg0) - { - string ss = String.Format(s, arg0); - this.array.push(ss); - this.length += ss.Length; - } - - public void AppendFormat(string s, object arg0, object arg1) - { - string ss = String.Format(s, arg0, arg1); - this.array.push(ss); - this.length += ss.Length; - } - - public void AppendFormat(string s, object arg0, object arg1, object arg2) - { - string ss = String.Format(s, arg0, arg1, arg2); - this.array.push(ss); - this.length += ss.Length; - } - - public void Append(object obj) - { - if (obj != null) - { - var s = obj.ToString(); - this.array.push(s); - this.length += s.Length; - } - } + [JsType(Name = "System.Text.StringBuilder", Filename = "~/res/System.Text.js")] + class JsImplStringBuilder + { + JsExtendedArray array; + int length; + + public JsImplStringBuilder() + { + this.array = new string[0].As(); + this.length = 0; + + } + + public JsImplStringBuilder(int len) + { + this.array = new string[0].As(); + this.length = 0; + + } + + public JsImplStringBuilder(string s) + { + this.array = new string[] { s }.As(); + this.length = s == null ? 0 : s.Length; + } + + + public void Append(char s) + { + this.array.push(s); + this.length += 1; + } + + public void Append(string s) + { + this.array.push(s); + this.length += s.Length; + } + + public void AppendFormat(string s, object arg0) + { + string ss = String.Format(s, arg0); + this.array.push(ss); + this.length += ss.Length; + } + + public void AppendFormat(string s, object arg0, object arg1) + { + string ss = String.Format(s, arg0, arg1); + this.array.push(ss); + this.length += ss.Length; + } + + public void AppendFormat(string s, object arg0, object arg1, object arg2) + { + string ss = String.Format(s, arg0, arg1, arg2); + this.array.push(ss); + this.length += ss.Length; + } + + public void Append(object obj) + { + if (obj != null) + { + var s = obj.ToString(); + this.array.push(s); + this.length += s.Length; + } + } /// /// Inserts the string representation of a specified Unicode character into this instance at the specified character position. @@ -346,7 +346,7 @@ public JsImplStringBuilder Insert(int index, string value, int count) if (index < 0 || index > this.array.length) throw new ArgumentOutOfRangeException(); - for (int i = 0; i < count; i++ ) + for (int i = 0; i < count; i++) this.array.insert(index, value); return this; } @@ -374,62 +374,73 @@ public JsImplStringBuilder Insert(int index, char[] value, int count) /// /// A that represents this instance. public override string ToString() - { - return this.array.join(""); - } + { + return this.array.join(""); + } /// /// Gets or sets the length. /// /// The length. /// Not Implemented - public int Length - { - get - { - return this.array.length; - } - set - { - if (value < 0) - throw new ArgumentOutOfRangeException(); - - // Setting the length in Javascript will truncate the array. - if (value < this.array.length) - this.array.length = value; + public int Length + { + get + { + //return this.array.length; + return length; + } + set + { + if (value == length) return; + if (value > length) + Append(new JsArray(value + 1).join("\x00")); else { - for(int i = this.array.length; i().Remove(start, count); - this.array = new object[] { s }.As(); - this.length = s.length; - return this; - } - } + + //--- + + //if (value < 0) + // throw new ArgumentOutOfRangeException(); + + //// Setting the length in Javascript will truncate the array. + //if (value < this.array.length) + // this.array.length = value; + //else + //{ + // for(int i = this.array.length; i().Remove(start, count); + this.array = new object[] { s }.As(); + this.length = s.length; + return this; + } + } [JsType(Name = "System.StringComparison", Filename = "~/Internal/Core.js")] - public enum JsImplStringComparison - { - CurrentCulture, - CurrentCultureIgnoreCase, - InvariantCulture, - InvariantCultureIgnoreCase, - Ordinal, - OrdinalIgnoreCase - } + public enum JsImplStringComparison + { + CurrentCulture, + CurrentCultureIgnoreCase, + InvariantCulture, + InvariantCultureIgnoreCase, + Ordinal, + OrdinalIgnoreCase + } + - }