//---------------------------------------------------------------------------------------------------- public st TruncateRight(int length) { var rtn = new st(); if (length > this.TheString.Length) { return(st.New("")); } rtn.TheString = this.Substring(0, this.TheString.Length - length); return(rtn); }
//---------------------------------------------------------------------------------------------------- public st Replace(string oldValue, string newValue) { var rtn = new st(); if (IsServerSide) { rtn.TheString = this.TheString.Replace(oldValue, newValue); } else { rtn.TheString = this.AsJsString().split(oldValue).join(newValue); } return(rtn); }
//---------------------------------------------------------------------------------------------------- public static st New(string input) { var rtn = new st(); rtn.TheString = input; if (!IsServerSide_StaticCheck) { IsServerSide = false; try { var tmp = ("ABC").As <JsString>().toLowerCase(); } catch { IsServerSide = true; } IsServerSide_StaticCheck = true; } return(rtn); }
//---------------------------------------------------------------------------------------------------- private int CountHyphens(st line) { int max = 50; if (line.Length() < max) { max = line.Length() - 1; } for (int i = 0; i < max; i++) { if (line.Substring(i, 1) != "-") { return(i); } } return(-1); }
//---------------------------------------------------------------------------------------------------- public string ToHtmlString() { string rtn = ""; if (this.ElementType == ElementTypes.ElementsHolder && (this.Children == null || this.Children.Length < 0)) { this.ElementType = ElementTypes.HtmlHolder; } string prefix = ""; for (int i = 1; i < this.TreeLevel; i++) { prefix += " "; } string suffix = "\n"; if (1 != 0) { prefix = ""; suffix = ""; } st attributesStr = st.New(""); if (this.InputType.Length > 0) { attributesStr.AppendST(st.New(" type='{0}'").Format1(this.InputType)); } if (this.ModelKey.Length > 0) { attributesStr.AppendST(st.New(" ModelKey='{0}'").Format1(this.ModelKey)); } if (this.IdClass.Length > 0) { attributesStr.AppendST(st.New(" IdClass='{0}'").Format1(this.IdClass)); } if (this.ClassesString.Length > 0) { attributesStr.AppendST(st.New(" class='{0}'").Format1(this.ClassesString)); } if (this.Value.Length > 0) { attributesStr.AppendST(st.New(" value='{0}'").Format1(this.Value)); } attributesStr = attributesStr.Trim(); if (this.AttributesStr != "") { attributesStr.Append(" " + this.AttributesStr); } if (attributesStr.Length() > 0) { attributesStr.TheString = " " + attributesStr.TheString; } if (this.ElementType == ElementTypes.ElementsHolder) { rtn += st.New("{0}<{1}{2}>{3}").Format4(prefix, this.ElementName, attributesStr.TheString, suffix).TheString; for (int i = 0; i < this.Children.Length; i++) { rtn += this.Children[i].ToHtmlString(); } rtn += st.New("{0}</{1}>{2}").Format3(prefix, this.ElementName, suffix).TheString; } else if (this.ElementType == ElementTypes.HtmlHolder) { rtn += st.New("{0}<{1}{2}>{3}</{1}>{4}").Format5(prefix, this.ElementName, attributesStr.TheString, this.InnerHtml, suffix).TheString; } else if (this.ElementType == ElementTypes.EmptyElementTag) { rtn += st.New("{0}<{1}{2} />{3}").Format4(prefix, this.ElementName, attributesStr.TheString, suffix).TheString; } else if (this.ElementType == ElementTypes.HtmlLiteral) { rtn += st.New("{0}{1}{2}").Format3(prefix, this.InnerHtml, suffix).TheString; } return(rtn); }
//---------------------------------------------------------------------------------------------------- public void Parse(st line) { this.MarkdownLine = line; this.TreeLevel = this.CountHyphens(line); line = line.TruncateLeft(this.TreeLevel).Trim(); if (line.StartsWith("'", false)) { this.ElementName = ""; this.ElementType = ElementTypes.HtmlLiteral; line = line.TruncateLeft(1); if (line.EndsWith("'", false)) { line = line.TruncateRight(1); } this.InnerHtml = line.TheString; } else { this.ElementType = ElementTypes.ElementsHolder; if (line.Contains("html=", false)) { string tmpLine = ""; bool insideSingleQuote = false; for (int i = 0; i < line.Length(); i++) { string c = line.Substring(i, 1); if (c == "'") { insideSingleQuote = !insideSingleQuote; } if (c == " " && insideSingleQuote) { tmpLine += "(---[[[SPACE].].]---)"; } else { tmpLine += c; } } line.TheString = tmpLine; } var tokens = line.Split(" ", false); if (tokens[0].StartsWith("i", true)) { this.ElementType = ElementTypes.EmptyElementTag; this.ElementName = "input"; this.InputType = "text"; var inArr = tokens[0].Split(":", false); if (inArr.Length > 1) { switch (inArr[1].TheString) { case "": this.InputType = "text"; break; case "t": this.InputType = "text"; break; case "b": this.InputType = "button"; break; case "s": this.InputType = "submit"; break; case "c": this.InputType = "checkbox"; break; case "r": this.InputType = "radio"; break; case "f": this.InputType = "file"; break; case "h": this.InputType = "hidden"; break; default: this.InputType = inArr[1].TheString; break; } } } else { switch (tokens[0].TheString) { case "d": this.ElementName = "div"; break; case "s": this.ElementName = "span"; break; case "br": this.ElementName = "br"; this.ElementType = ElementTypes.EmptyElementTag; break; case "t": this.ElementName = "table"; break; case "tr": this.ElementName = "tr"; break; case "td": this.ElementName = "td"; break; default: this.ElementName = tokens[0].TheString; break; } } this.ClassesString = ""; for (int i = 1; i < tokens.Length; i++) { var token = tokens[i].Trim(); token = token.Replace("(---[[[SPACE].].]---)", " "); if (token.Length() > 0) { if (token.StartsWith("#", false)) { this.IdClass = token.TruncateLeft(1).Trim().TheString; } else if (token.StartsWith(".", true)) { this.ClassesString += " " + token.TruncateLeft(1).Replace(".", " ").TheString; } else if (token.StartsWith("evt.", true)) { if (this.EventNames == null) { this.EventNames = new string[0]; } this.EventNames[this.EventNames.Length] = token.TruncateLeft(4).Trim().TheString; } else if (token.StartsWith("m=", true)) { var modelKey = token.TruncateLeft(2).Trim(); if (modelKey.StartsWith("'", false)) { modelKey = modelKey.TruncateLeft(1); } if (modelKey.EndsWith("'", false)) { modelKey = modelKey.TruncateRight(1); } this.ModelKey = modelKey.TheString; } else if (token.StartsWith("html=", true)) { var html = token.TruncateLeft(5).Trim(); if (html.StartsWith("'", false)) { html = html.TruncateLeft(1); } if (html.EndsWith("'", false)) { html = html.TruncateRight(1); } this.InnerHtml = html.TheString; } else if (token.StartsWith("v=", true)) { var value = token.TruncateLeft(2).Trim(); if (value.StartsWith("'", false)) { value = value.TruncateLeft(1); } if (value.EndsWith("'", false)) { value = value.TruncateRight(1); } this.Value = value.TheString; } else if (token.Contains("=", false)) { this.AttributesStr += " " + token.TheString + " "; } } } if (this.IdClass.Length > 0) { this.ClassesString += " " + this.IdClass; } this.ClassesString = st.New(this.ClassesString).Trim().TheString; if (this.EventNames != null && this.IdClass.Length > 0) { for (int i = 0; i < this.EventNames.Length; i++) { this.AttributesStr += st.New(" On_{0}='{1}_{0}'").Format2(this.EventNames[0], this.IdClass).TheString; } } } }
//---------------------------------------------------------------------------------------------------- public static string TestUnit() { string unitName = "ASPdb.FrameworkUI.st"; string passFail = "Failed"; string rtn = ""; st s = null; string suffix = ""; //---------- 01 s = st.New("AAAaaa BBBbbb CCCccc" + suffix); s = s.Replace("BBbb", "--"); if (s.TheString != "AAAaaa B--b CCCccc") { rtn += "01) Replace() \n"; } //---------- 02 s = st.New("aa {0} bb " + suffix); if (s.Format1("AA").TheString != "aa AA bb ") { rtn += "02) Format1() \n"; } s = st.New("aa {0} bb {1} cc " + suffix); if (s.Format2("AA", "BB").TheString != "aa AA bb BB cc ") { rtn += "02) Format2() \n"; } s = st.New("aa {0} bb {1} cc {2} dd " + suffix); if (s.Format3("AA", "BB", "CC").TheString != "aa AA bb BB cc CC dd ") { rtn += "02) Format3() \n"; } s = st.New("aa {0} bb {1} cc {2} dd {3} ee " + suffix); if (s.Format4("AA", "BB", "CC", "DD").TheString != "aa AA bb BB cc CC dd DD ee ") { rtn += "02) Format4() \n"; } s = st.New("aa {0} bb {1} cc {2} dd {3} ee {4} ff " + suffix); if (s.Format5("AA", "BB", "CC", "DD", "EE").TheString != "aa AA bb BB cc CC dd DD ee EE ff ") { rtn += "02) Format5() \n"; } s = st.New("aa {0} bb {1} cc {2} dd {3} ee {4} ff {5} gg " + suffix); if (s.Format6("AA", "BB", "CC", "DD", "EE", "FF").TheString != "aa AA bb BB cc CC dd DD ee EE ff FF gg ") { rtn += "02) Format6() \n"; } s = st.New("aa {0} bb {1} cc {2} dd {3} ee {4} ff {5} gg {6} hh " + suffix); if (s.Format7("AA", "BB", "CC", "DD", "EE", "FF", "GG").TheString != "aa AA bb BB cc CC dd DD ee EE ff FF gg GG hh ") { rtn += "02) Format7() \n"; } s = st.New("aa {0} bb {1} cc {2} dd {3} ee {4} ff {5} gg {6} hh {7} ii " + suffix); if (s.Format8("AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH").TheString != "aa AA bb BB cc CC dd DD ee EE ff FF gg GG hh HH ii ") { rtn += "02) Format8() \n"; } s = st.New("aa {0} bb {1} cc {2} dd {3} ee {4} ff {5} gg {6} hh {7} ii {8} jj " + suffix); if (s.Format9("AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II").TheString != "aa AA bb BB cc CC dd DD ee EE ff FF gg GG hh HH ii II jj ") { rtn += "02) Format9() \n"; } //---------- 03 s = st.New("AAaa 1234567890 bbBB" + suffix); if (s.StartsWith("AAaa 12", false) != true) { rtn += "03.a) StartsWith() \n"; } if (s.StartsWith("aaaa 12", false) != false) { rtn += "03.b) StartsWith() \n"; } if (s.StartsWith("aaaa 12", true) != true) { rtn += "03.c) StartsWith() \n"; } if (s.EndsWith("90 bbBB", false) != true) { rtn += "03.d) EndsWith() \n"; } if (s.EndsWith("90 bbbb", false) != false) { rtn += "03.e) EndsWith() \n"; } if (s.EndsWith("90 bbbb", true) != true) { rtn += "03.f) EndsWith() \n"; } //---------- 04 s = st.New("12345678901234567890" + suffix); if (s.TruncateLeft(0).TheString != "12345678901234567890") { rtn += "04.a) TruncateLeft() \n"; } if (s.TruncateLeft(21).TheString != "") { rtn += "04.b) TruncateLeft() \n"; } if (s.TruncateLeft(5).TheString != "678901234567890") { rtn += "04.c) TruncateLeft() \n"; } if (s.TruncateRight(0).TheString != "12345678901234567890") { rtn += "04.d) TruncateRight() \n"; } if (s.TruncateRight(21).TheString != "") { rtn += "04.e) TruncateRight() \n"; } if (s.TruncateRight(5).TheString != "123456789012345") { rtn += "04.f) TruncateRight() \n"; } //---------- 05 s = st.New("a12345678901234567890z" + suffix); if (s.IfStartsWith_Truncate("A12345", true).TheString != "678901234567890z") { rtn += "05.a) IfStartsWith_Truncate() \n"; } if (s.IfStartsWith_Truncate("A12345", false).TheString != "a12345678901234567890z") { rtn += "05.b) IfStartsWith_Truncate() \n"; } if (s.IfStartsWith_Truncate("a12345", false).TheString != "678901234567890z") { rtn += "05.c) IfStartsWith_Truncate() \n"; } if (s.IfEndsWith_Truncate("7890Z", true).TheString != "a1234567890123456") { rtn += "05.d) IfEndsWith_Truncate() \n"; } if (s.IfEndsWith_Truncate("7890Z", false).TheString != "a12345678901234567890z") { rtn += "05.d) IfEndsWith_Truncate() \n"; } if (s.IfEndsWith_Truncate("7890z", false).TheString != "a1234567890123456") { rtn += "05.d) IfEndsWith_Truncate() \n"; } //---------- 06 s = st.New("AAAxBBBxCCCXDDDXEEE" + suffix); var arr = s.Split("x", false); if (arr.Length != 3) { rtn += "06.a) Split() \n"; } arr = s.Split("x", true); if (arr.Length != 5) { rtn += "06.b) Split() \n"; } if (arr[0].TheString != "AAA") { rtn += "06.c) Split() \n"; } if (arr[4].TheString != "EEE") { rtn += "06.d) Split() \n"; } //---------- 07 s = st.New(" Aa Aa " + suffix); if (s.Trim().TheString != "Aa Aa") { rtn += "07.a) Trim() \n"; } if (s.ToUpper().TheString != " AA AA ") { rtn += "07.b) ToUpper() \n"; } if (s.ToLower().TheString != " aa aa ") { rtn += "07.c) ToLower() \n"; } //---------- 08 s = st.New("aaa aaa" + suffix); s.Append(" aaa"); if (s.TheString != "aaa aaa aaa") { rtn += "08.a) Append() \n"; } s.AppendST(st.New(" bbb")); if (s.TheString != "aaa aaa aaa bbb") { rtn += "08.b) AppendST() \n"; } if (rtn == "") { passFail = "Passed"; } return(st.New("{0} : {1} \n{2}").Format3(unitName, passFail, rtn).TheString); }
//---------------------------------------------------------------------------------------------------- public st AppendST(st str) { return(this.Append(str.TheString)); }
//---------------------------------------------------------------------------------------------------- public st[] Split(string delimiter, bool ignoreCase) { if (IsServerSide) { if (ignoreCase) { var input = this.TheString; var input_L = input.ToLower(); // input.toLowerCase(); var delimiter_L = delimiter.ToLower(); // delimiter.As<JsString>().toLowerCase(); var arr = input_L.Split(new string[] { delimiter_L }, StringSplitOptions.None); var rtn = new st[arr.Length]; int start = 0; for (int i = 0; i < arr.Length; i++) { rtn[i] = new st(); rtn[i].TheString = input.Substring(start, arr[i].Length); start += arr[i].Length + delimiter.Length; } return(rtn); } else { var arr = this.TheString.Split(new string[] { delimiter }, StringSplitOptions.None); // this.AsJsString().split(delimiter); var rtn = new st[arr.Length]; for (int i = 0; i < arr.Length; i++) { rtn[i] = new st(); rtn[i].TheString = arr[i]; } return(rtn); } } else // (!IsServerSide) { if (ignoreCase) { var input = this.AsJsString(); var input_L = input.toLowerCase(); var delimiter_L = delimiter.As <JsString>().toLowerCase(); var arr = input_L.split(delimiter_L); var rtn = new st[arr.length]; int start = 0; for (int i = 0; i < arr.length; i++) { rtn[i] = new st(); rtn[i].TheString = input.substr(start, arr[i].length); start += arr[i].length + delimiter.Length; } return(rtn); } else { var arr = this.AsJsString().split(delimiter); var rtn = new st[arr.length]; for (int i = 0; i < arr.length; i++) { rtn[i] = new st(); rtn[i].TheString = arr[i]; } return(rtn); } } //if(ignoreCase) //{ // var input = this.AsJsString(); // var input_L = input.toLowerCase(); // var delimiter_L = delimiter.As<JsString>().toLowerCase(); // var arr = input_L.split(delimiter_L); // var rtn = new st[arr.length]; // int start = 0; // for (int i = 0; i < arr.length; i++) // { // rtn[i] = new st(); // rtn[i].TheString = input.substr(start, arr[i].length); // start += arr[i].length + delimiter.Length; // } // return rtn; //} //else //{ // var arr = this.AsJsString().split(delimiter); // var rtn = new st[arr.length]; // for (int i = 0; i < arr.length; i++) // { // rtn[i] = new st(); // rtn[i].TheString = arr[i]; // } // return rtn; //} }