Example #1
0
        //----------------------------------------------------------------------------------------------------
        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;
                    }
                }
            }
        }
Example #2
0
        //----------------------------------------------------------------------------------------------------
        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);
        }