コード例 #1
0
ファイル: TextElement.cs プロジェクト: turkmvc/TextEngine
        public string Footer(bool outputformat = false)
        {
            if (this.SlashUsed || this.DirectClosed || this.AutoClosed)
            {
                return(null);
            }
            var text = new StringBuilder();

            if (this.ElementType == TextElementType.ElementNode)
            {
                if (outputformat)
                {
                    if (this.LastChild?.ElemName != "#text")
                    {
                        text.Append('\t', this.Depth);
                    }
                }
                var eName = this.ElemName;
                if (!PhpFuctions.empty(this.AliasName))
                {
                    eName = this.AliasName;
                }
                text.Append(this.BaseEvulator.LeftTag.ToString() + '/' + eName + this.BaseEvulator.RightTag.ToString());
            }
            if (outputformat)
            {
                text.Append("\r\n");
            }
            return(text.ToString());
        }
コード例 #2
0
ファイル: TextElement.cs プロジェクト: turkmvc/TextEngine
        public string Outer(bool outputformat = false)
        {
            if (this.ElemName == "#document")
            {
                return(this.Inner());
            }
            if (this.ElemName == "#text")
            {
                return(this.value);
            }
            if (this.ElementType == TextElementType.CommentNode)
            {
                return(this.BaseEvulator.LeftTag.ToString() + "--" + this.Value + "--" + this.BaseEvulator.RightTag.ToString());
            }
            StringBuilder text       = new StringBuilder();
            StringBuilder additional = new StringBuilder();

            if (!PhpFuctions.empty(this.TagAttrib))
            {
                additional.Append("=" + this.TagAttrib);
            }
            if (this.ElementType == TextElementType.Parameter)
            {
                text.Append(this.BaseEvulator.LeftTag.ToString() + this.BaseEvulator.ParamChar.ToString() + this.ElemName + HTMLUTIL.ToAttribute(this.ElemAttr) + this.BaseEvulator.RightTag.ToString());
            }
            else
            {
                if (this.AutoAdded)
                {
                    if (this.SubElementsCount == 0)
                    {
                        return(string.Empty);
                    }
                }
                text.Append(this.BaseEvulator.LeftTag.ToString() + this.ElemName + additional.ToString() + ((this.NoAttrib && this.ElementType == TextElementType.ElementNode) ? ' ' + this.Value : HTMLUTIL.ToAttribute(this.ElemAttr)));
                if (this.DirectClosed)
                {
                    text.Append(" /" + this.BaseEvulator.RightTag);
                }
                else if (this.AutoClosed)
                {
                    text.Append(this.BaseEvulator.RightTag);
                }
                else
                {
                    text.Append(this.BaseEvulator.RightTag);
                    text.Append(this.Inner(outputformat));
                    var eName = this.ElemName;
                    if (!PhpFuctions.empty(this.AliasName))
                    {
                        eName = this.AliasName;
                    }
                    text.Append(this.BaseEvulator.LeftTag + '/' + eName + this.BaseEvulator.RightTag.ToString());
                }
            }
            return(text.ToString());
        }
コード例 #3
0
ファイル: TextElement.cs プロジェクト: turkmvc/TextEngine
        public string Header(bool outputformat = false)
        {
            if (this.AutoAdded && this.SubElementsCount == 0)
            {
                return(null);
            }

            StringBuilder text = new StringBuilder();

            if (outputformat)
            {
                text.Append('\t', this.Depth);
            }
            if (this.ElementType == TextElementType.XMLTag)
            {
                text.Append(this.BaseEvulator.LeftTag.ToString() + "?" + this.ElemName + HTMLUTIL.ToAttribute(this.ElemAttr) + "?" + this.BaseEvulator.RightTag.ToString());
            }
            if (this.ElementType == TextElementType.Parameter)
            {
                text.Append(this.BaseEvulator.LeftTag.ToString() + this.BaseEvulator.ParamChar.ToString() + this.ElemName + HTMLUTIL.ToAttribute(this.ElemAttr) + this.BaseEvulator.RightTag.ToString());
            }
            else if (this.ElementType == TextElementType.ElementNode)
            {
                StringBuilder additional = new StringBuilder();
                if (!PhpFuctions.empty(this.TagAttrib))
                {
                    additional.Append('=' + this.TagAttrib);
                }
                text.Append(this.BaseEvulator.LeftTag.ToString() + this.ElemName + additional.ToString() + ((this.NoAttrib) ? ' ' + this.Value : HTMLUTIL.ToAttribute(this.ElemAttr)));
                if (this.DirectClosed)
                {
                    text.Append(" /" + this.BaseEvulator.RightTag.ToString());
                }
                else if (this.AutoClosed)
                {
                    text.Append(this.BaseEvulator.RightTag);
                }
                else
                {
                    text.Append(this.BaseEvulator.RightTag);
                }
            }
            else if (this.ElementType == TextElementType.CDATASection)
            {
                text.Append(this.BaseEvulator.LeftTag.ToString() + "![CDATA[" + this.Value + "]]" + this.BaseEvulator.RightTag.ToString());
            }
            else if (this.ElementType == TextElementType.CommentNode)
            {
                text.Append(this.BaseEvulator.LeftTag.ToString() + "--" + this.Value + "--" + this.BaseEvulator.RightTag.ToString());
            }
            if (outputformat && this.FirstChild?.ElemName != "#text")
            {
                text.Append("\r\n");
            }
            return(text.ToString());
        }
コード例 #4
0
ファイル: TextElement.cs プロジェクト: turkmvc/TextEngine
 public TextElement GetSubElement(params string[] names)
 {
     for (int i = 0; i < this.SubElementsCount; i++)
     {
         if (PhpFuctions.in_array(this.SubElements[i].ElemName, names))
         {
             return(this.SubElements[i]);
         }
     }
     return(null);
 }
コード例 #5
0
ファイル: TextElement.cs プロジェクト: turkmvc/TextEngine
        public TextElement NextElementWN(params string[] names)
        {
            var next = this.NextElement();

            while (next != null)
            {
                if (next.ElementType == TextElementType.Parameter || next.ElemName == "#text")
                {
                    next = next.NextElement();
                    continue;
                }
                if (PhpFuctions.in_array(next.ElemName, names))
                {
                    return(next);
                }
                next = next.NextElement();
            }
            return(null);
        }
コード例 #6
0
ファイル: TextElement.cs プロジェクト: turkmvc/TextEngine
        public TextElement PreviousElementWN(params string[] names)
        {
            var prev = this.PreviousElement();

            while (prev != null)
            {
                if (prev.ElementType == TextElementType.Parameter || prev.ElemName == "#text")
                {
                    prev = prev.PreviousElement();
                    continue;
                }
                if (PhpFuctions.in_array(prev.ElemName, names))
                {
                    return(prev);
                }
                prev = prev.PreviousElement();
            }
            return(null);
        }
コード例 #7
0
        public ComputeResult Compute(object vars = null, InnerItem sender = null, object localvars = null)
        {
            var       cr            = new ComputeResult();
            object    lastvalue     = null;
            InnerItem xoperator     = null;
            InnerItem previtem      = null;
            InnerItem waititem      = null;
            InnerItem waititem2     = null;
            string    waitop        = "";
            object    waitvalue     = null;
            string    waitop2       = "";
            object    waitvalue2    = null;
            string    waitkey       = "";
            bool      unlemused     = false;
            bool      stopdoubledot = false;

            if (this.IsObject())
            {
                cr.Result.AddObject(new ExpandoObject());
            }
            for (int i = 0; i < this.InnerItems.Count; i++)
            {
                object    currentitemvalue = null;
                InnerItem current          = this.InnerItems[i];
                ParItem   paritem          = null;
                if (current.IsParItem())
                {
                    paritem = current as ParItem;
                }
                if (stopdoubledot)
                {
                    if (current.IsOperator && current.Value.ToString() == ":")
                    {
                        break;
                    }
                }
                InnerItem next   = null;
                string    nextop = "";
                if (i + 1 < this.InnerItems.Count)
                {
                    next = this.InnerItems[i + 1];
                }
                if (next != null && next.IsOperator)
                {
                    nextop = next.Value.ToString();
                }
                if (current.IsParItem())
                {
                    var    subresult = paritem.Compute(vars, this, localvars);
                    string prevvalue = "";
                    bool   previsvar = false;
                    if (previtem != null && !previtem.IsOperator && previtem.Value != null)
                    {
                        previsvar = previtem.InnerType == InnerType.TYPE_VARIABLE;
                        prevvalue = previtem.Value.ToString();
                    }
                    object varnew = null;
                    if (lastvalue != null)
                    {
                        varnew = lastvalue;
                    }
                    else
                    {
                        varnew = vars;
                    }
                    if (prevvalue != "")
                    {
                        if (paritem.ParName == "(")
                        {
                            currentitemvalue = ComputeActions.CallMethod(prevvalue, subresult.Result.GetObjects(), varnew, localvars);
                        }
                        else if (paritem.ParName == "[")
                        {
                            var prop = ComputeActions.GetProp(prevvalue, varnew);
                            if (PhpFuctions.is_array(prop))
                            {
                                int indis  = (int)Convert.ChangeType(subresult.Result[0], TypeCode.Int32);
                                var aritem = prop as IList;

                                currentitemvalue = aritem[indis];
                            }
                            else if (PhpFuctions.is_indis(prop))
                            {
                                var indisProp = prop.GetType().GetProperty("Item");
                                var newParams = ParamUtil.MatchParams(subresult.Result.GetObjects(), indisProp.GetIndexParameters());
                                currentitemvalue = indisProp.GetValue(prop, newParams);
                            }
                            else
                            {
                                int indis = (int)Convert.ChangeType(subresult.Result[0], TypeCode.Int32);
                                currentitemvalue = ((string)prop)[indis];
                            }
                        }
                    }
                    else
                    {
                        if (paritem.ParName == "(")
                        {
                            currentitemvalue = subresult.Result[0];
                        }
                        else if (paritem.ParName == "[")
                        {
                            if (subresult.Result.KeysIncluded())
                            {
                                currentitemvalue = subresult.Result.ToDictionary();
                            }
                            else
                            {
                                currentitemvalue = subresult.Result.GetObjects();
                            }
                        }
                        else if (paritem.ParName == "{")
                        {
                            currentitemvalue = subresult.Result.First();
                        }
                    }
                }
                else
                {
                    if (!current.IsOperator && current.InnerType == InnerType.TYPE_VARIABLE && next != null && next.IsParItem())
                    {
                        currentitemvalue = null;
                    }
                    else
                    {
                        currentitemvalue = current.Value;
                    }

                    if (current.InnerType == InnerType.TYPE_VARIABLE && (next == null || !next.IsParItem()) && (xoperator == null || xoperator.Value.ToString() != "."))
                    {
                        if (currentitemvalue == null || currentitemvalue.ToString() == "null")
                        {
                            currentitemvalue = null;
                        }
                        else if (currentitemvalue.ToString() == "false")
                        {
                            currentitemvalue = false;
                        }
                        else if (currentitemvalue.ToString() == "true")
                        {
                            currentitemvalue = true;
                        }
                        else if (!this.IsObject())
                        {
                            currentitemvalue = ComputeActions.GetPropValue(current, vars, localvars);
                        }
                    }
                }
                if (unlemused)
                {
                    currentitemvalue = !PhpFuctions.not_empty(currentitemvalue);
                    unlemused        = false;
                }
                if (current.IsOperator)
                {
                    if (current.Value.ToString() == "!")
                    {
                        unlemused = !unlemused;
                        previtem  = current;
                        continue;
                    }
                    if ((this.IsParItem() && current.Value.ToString() == ",") || (this.IsArray() && current.Value.ToString() == "=>" && (waitvalue == null || waitvalue.ToString() == "")) || (this.IsObject() && current.Value.ToString() == ":" && (waitvalue == null || waitvalue.ToString() == "")))
                    {
                        if (waitop2 != "")
                        {
                            lastvalue  = ComputeActions.OperatorResult(waitvalue2, lastvalue, waitop2);
                            waitvalue2 = null;
                            waitop2    = "";
                        }
                        if (waitop != "")
                        {
                            lastvalue = ComputeActions.OperatorResult(waitvalue, lastvalue, waitop);
                            waitvalue = null;
                            waitop    = "";
                        }
                        if (current.Value.ToString() == ",")
                        {
                            if (this.IsObject())
                            {
                                var exp = cr.Result.First <IDictionary <string, object> >();
                                exp.Add(waitkey, lastvalue);
                            }
                            else
                            {
                                cr.Result.AddObject(waitkey, lastvalue);
                            }

                            waitkey = "";
                        }
                        else
                        {
                            waitkey = lastvalue.ToString();
                        }
                        lastvalue = null;
                        xoperator = null;
                        previtem  = current;
                        continue;
                    }
                    string opstr = current.Value.ToString();
                    if (opstr == "||" || opstr == "|" || opstr == "or" || opstr == "&&" || opstr == "&" || opstr == "and" || opstr == "?")
                    {
                        if (waitop2 != "")
                        {
                            lastvalue  = ComputeActions.OperatorResult(waitvalue2, lastvalue, waitop2);
                            waitvalue2 = null;
                            waitop2    = "";
                        }
                        if (waitop != "")
                        {
                            lastvalue = ComputeActions.OperatorResult(waitvalue, lastvalue, waitop);
                            waitvalue = null;
                            waitop    = "";
                        }

                        bool state = PhpFuctions.not_empty(lastvalue);
                        xoperator = null;
                        if (opstr == "?")
                        {
                            if (state)
                            {
                                stopdoubledot = true;
                            }
                            else
                            {
                                for (int j = i + 1; j < this.InnerItems.Count; j++)
                                {
                                    var item = this.InnerItems[j];
                                    if (item.IsOperator && item.Value.ToString() == ":")
                                    {
                                        i = j;
                                        break;
                                    }
                                }
                            }
                            lastvalue = null;
                            previtem  = current;
                            continue;
                        }



                        if (opstr == "||" || opstr == "|" || opstr == "or")
                        {
                            if (state)
                            {
                                lastvalue = true;
                                if (opstr != "|")
                                {
                                    if (this.IsObject())
                                    {
                                        var exp = cr.Result.First <IDictionary <string, object> >();
                                        exp.Add(waitkey, true);
                                    }
                                    else
                                    {
                                        cr.Result.AddObject(waitkey, true);
                                    }
                                    return(cr);
                                }
                            }
                            else
                            {
                                lastvalue = false;
                            }
                        }
                        else
                        {
                            if (!state)
                            {
                                lastvalue = false;
                                if (opstr != "&")
                                {
                                    if (this.IsObject())
                                    {
                                        var exp = cr.Result.First <IDictionary <string, object> >();
                                        exp.Add(waitkey, false);
                                    }
                                    else
                                    {
                                        cr.Result.AddObject(waitkey, false);
                                    }
                                    return(cr);
                                }
                            }
                            else
                            {
                                lastvalue = true;
                            }
                        }
                        xoperator = current;
                    }
                    else
                    {
                        xoperator = current;
                    }

                    previtem = current;
                    continue;
                }
                else
                {
                    if (xoperator != null)
                    {
                        if (ComputeActions.PriotiryStop.Contains(xoperator.Value.ToString()))
                        {
                            if (waitop2 != "")
                            {
                                lastvalue  = ComputeActions.OperatorResult(waitvalue2, lastvalue, waitop2);
                                waitvalue2 = null;
                                waitop2    = "";
                            }
                            if (waitop != "")
                            {
                                lastvalue = ComputeActions.OperatorResult(waitvalue, lastvalue, waitop);
                                waitvalue = null;
                                waitop    = "";
                            }
                        }

                        if (next != null && next.IsParItem())
                        {
                            if (xoperator.Value.ToString() == ".")
                            {
                                if (currentitemvalue != null && !string.IsNullOrEmpty(currentitemvalue.ToString()))
                                {
                                    lastvalue = ComputeActions.GetProp(currentitemvalue.ToString(), lastvalue);
                                }
                            }
                            else
                            {
                                if (waitop == "")
                                {
                                    waitop    = xoperator.Value.ToString();
                                    waititem  = current;
                                    waitvalue = lastvalue;
                                }
                                else if (waitop2 == "")
                                {
                                    waitop2    = xoperator.Value.ToString();
                                    waititem2  = current;
                                    waitvalue2 = lastvalue;
                                }
                                lastvalue = null;
                            }
                            xoperator = null;
                            previtem  = current;
                            continue;
                        }
                        if (xoperator.Value.ToString() == ".")
                        {
                            lastvalue = ComputeActions.GetProp(currentitemvalue.ToString(), lastvalue);
                        }
                        else if (nextop != "." && ((xoperator.Value.ToString() != "+" && xoperator.Value.ToString() != "-") || nextop == "" || (ComputeActions.PriotiryStop.Contains(nextop))))
                        {
                            var opresult = ComputeActions.OperatorResult(lastvalue, currentitemvalue, xoperator.Value.ToString());
                            lastvalue = opresult;
                        }
                        else
                        {
                            if (waitop == "")
                            {
                                waitop    = xoperator.Value.ToString();
                                waititem  = current;
                                waitvalue = lastvalue;
                                lastvalue = currentitemvalue;
                            }
                            else if (waitop2 == "")
                            {
                                waitop2    = xoperator.Value.ToString();
                                waititem2  = current;
                                waitvalue2 = lastvalue;
                                lastvalue  = currentitemvalue;
                            }

                            continue;
                        }
                    }
                    else
                    {
                        lastvalue = currentitemvalue;
                    }
                }

                previtem = current;
            }
            if (waitop2 != "")
            {
                lastvalue  = ComputeActions.OperatorResult(waitvalue2, lastvalue, waitop2);
                waitvalue2 = null;
                waitop2    = "";
            }
            if (waitop != "")
            {
                lastvalue = ComputeActions.OperatorResult(waitvalue, lastvalue, waitop);
                waitvalue = null;
                waitop    = "";
            }
            if (this.IsObject())
            {
                var exp = cr.Result.First <IDictionary <string, object> >();
                exp.Add(waitkey, lastvalue);
            }
            else
            {
                cr.Result.AddObject(waitkey, lastvalue);
            }
            return(cr);
        }
コード例 #8
0
 public bool IsArray(object exobject)
 {
     return(!PhpFuctions.is_array(exobject) && this.IsArray());
 }
コード例 #9
0
ファイル: XPathActions.cs プロジェクト: turkmvc/TextEngine
        public object[] EvulateActionSingle(XPathExpression item, IXPathExpressionItem sender = null)
        {
            object curvalue = null;
            IXPathExpressionItem previtem  = null;
            XPathExpressionItem  xoperator = null;
            object        waitvalue        = null;
            string        waitop           = null;
            List <object> values           = new List <object>();

            for (int j = 0; j < item.XPathExpressionItems.Count; j++)
            {
                var    curitem              = item.XPathExpressionItems[j];
                var    nextitem             = (j + 1 < item.XPathExpressionItems.Count) ? item.XPathExpressionItems[j + 1] : null;
                string nextop               = null;
                XPathExpressionItem nextExp = null;
                if (nextitem != null && !nextitem.IsSubItem)
                {
                    nextExp = nextitem as XPathExpressionItem;
                    nextop  = (nextExp != null && nextExp.IsOperator) ? nextExp.Value.ToString() : null;
                }
                object expvalue = null;
                if (curitem.IsSubItem)
                {
                    expvalue = EvulateAction((IXPathExpressionItems)curitem);
                    if (!previtem.IsSubItem)
                    {
                        var prevexp = previtem as XPathExpressionItem;
                        if (prevexp.IsOperator)
                        {
                            expvalue = ((object[])expvalue)[0];
                        }
                        else
                        {
                            if (XPathFunctions != null)
                            {
                                if (curitem.ParChar == '[')
                                {
                                    var xitems = XPathFunctions.BaseItem.FindByXPath(prevexp.Value.ToString());
                                    if (xitems.Count > 0)
                                    {
                                        xitems = Eliminate(xitems, (IXPathExpressionItems)curitem);
                                    }
                                    if (xitems.Count > 0)
                                    {
                                        expvalue = true;
                                    }
                                    else
                                    {
                                        expvalue = false;
                                    }
                                    if (curvalue == null)
                                    {
                                        curvalue = expvalue;
                                        previtem = curitem;
                                        continue;
                                    }
                                }
                                else if (curitem.ParChar == '(')
                                {
                                    var method = XPathFunctions.GetMetohdByName(prevexp.Value.ToString());
                                    if (method != null)
                                    {
                                        expvalue = ComputeActions.CallMethodDirect(XPathFunctions, method, (object[])expvalue);
                                        if (curvalue == null)
                                        {
                                            curvalue = expvalue;
                                            previtem = curitem;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var expItem = curitem as XPathExpressionItem;
                    if (nextitem != null && nextitem.IsSubItem)
                    {
                        previtem = curitem;
                        continue;
                    }

                    if (expItem.IsOperator)
                    {
                        if (expItem.Value.ToString() == ",")
                        {
                            if (waitop != null)
                            {
                                curvalue  = ComputeActions.OperatorResult(waitvalue, curvalue, waitop);
                                waitvalue = null;
                                waitop    = null;
                            }
                            values.Add(curvalue);
                            curvalue  = null;
                            xoperator = null;
                            continue;
                        }
                        string opstr = expItem.Value.ToString();
                        if (opstr == "||" || opstr == "|" || opstr == "or" || opstr == "&&" || opstr == "&" || opstr == "and")
                        {
                            if (waitop != null)
                            {
                                curvalue  = ComputeActions.OperatorResult(waitvalue, curvalue, waitop);
                                waitvalue = null;
                                waitop    = null;
                            }
                            bool state = PhpFuctions.not_empty(curvalue);
                            if (opstr == "||" || opstr == "|" || opstr == "or")
                            {
                                if (state)
                                {
                                    values.Add(true);
                                    return(values.ToArray());
                                }
                                else
                                {
                                    curvalue = null;
                                }
                            }
                            else
                            {
                                if (!state)
                                {
                                    values.Add(false);
                                    return(values.ToArray());
                                }
                                else
                                {
                                    curvalue = null;
                                }
                            }
                            xoperator = null;
                        }
                        else
                        {
                            xoperator = expItem;
                        }

                        previtem = curitem;
                        continue;
                    }
                    else
                    {
                        if (expItem.IsVariable)
                        {
                            if (expItem.Value.ToString().StartsWith("@"))
                            {
                                string s = expItem.Value.ToString().Substring(1);

                                if ((nextExp == null || !nextExp.IsOperator) && (sender is null || !sender.IsSubItem || sender.ParChar != '('))
                                {
                                    expvalue = this.XPathFunctions.BaseItem.ElemAttr.HasAttribute(s);
                                }
                                else
                                {
                                    expvalue = this.XPathFunctions.BaseItem.GetAttribute(s);
                                }
                                if (expvalue == null)
                                {
                                    expvalue = false;
                                }
                            }
                            else
                            {
                                var items = this.XPathFunctions.BaseItem.FindByXPath(expItem.Value.ToString());
                                if (items.Count == 0)
                                {
                                    expvalue = false;
                                }
                                else
                                {
                                    expvalue = items[0].Inner();
                                }
                            }
                        }
コード例 #10
0
        private void ParseTagHeader(ref TextElement tagElement)
        {
            bool          inquot    = false;
            bool          inspec    = false;
            StringBuilder current   = new StringBuilder();
            bool          namefound = false;
            //bool inattrib = false;
            bool          firstslashused = false;
            bool          lastslashused  = false;
            StringBuilder currentName    = new StringBuilder();

#pragma warning disable CS0219 // Değişken atandı ancak değeri hiç kullanılmadı
            bool quoted = false;
#pragma warning restore CS0219 // Değişken atandı ancak değeri hiç kullanılmadı
            char quotchar = '\0';
            bool initial  = false;
            for (int i = this.pos; i < this.TextLength; i++)
            {
                var cur = this.Text[i];


                if (inspec)
                {
                    inspec = false;
                    current.Append(cur);
                    continue;
                }
                var next  = '\0';
                var next2 = '\0';
                if (i + 1 < this.TextLength)
                {
                    next = this.Text[i + 1];
                }
                if (i + 2 < this.TextLength)
                {
                    next2 = this.Text[i + 2];
                }
                if (tagElement.ElementType == TextElementType.CDATASection)
                {
                    if (cur == ']' && next == ']' && next2 == this.Evulator.RightTag)
                    {
                        tagElement.Value = current.ToString();
                        this.pos         = i += 2;
                        return;
                    }
                    current.Append(cur);
                    continue;
                }
                if (this.Evulator.AllowXMLTag && cur == '?' && !namefound && current.Length == 0)
                {
                    tagElement.Closed      = true;
                    tagElement.AutoClosed  = true;
                    tagElement.ElementType = TextElementType.XMLTag;
                    continue;
                }
                if (this.Evulator.SupportExclamationTag && cur == '!' && !namefound && current.Length == 0)
                {
                    tagElement.Closed     = true;
                    tagElement.AutoClosed = true;
                    if (i + 8 < this.TextLength)
                    {
                        var mtn = this.Text.Substring(i, 8);
                        if (this.Evulator.SupportCDATA && mtn == "![CDATA[")
                        {
                            tagElement.ElementType = TextElementType.CDATASection;
                            tagElement.ElemName    = "#cdata";
                            namefound = true;
                            i        += 7;
                            continue;
                        }
                    }
                }
                if (cur == '\\' && tagElement.ElementType != TextElementType.CommentNode)
                {
                    if (!namefound && tagElement.ElementType != TextElementType.Parameter)
                    {
                        this.Evulator.IsParseMode = false;
                        throw new Exception("Syntax Error");
                    }
                    inspec = true;
                    continue;
                }

                if (!initial && cur == '!' && next == '-' && next2 == '-')
                {
                    tagElement.ElementType = TextElementType.CommentNode;
                    tagElement.ElemName    = "#summary";
                    tagElement.Closed      = true;
                    i += 2;
                    continue;
                }
                if (tagElement.ElementType == TextElementType.CommentNode)
                {
                    if (cur == '-' && next == '-' && next2 == this.Evulator.RightTag)
                    {
                        tagElement.Value = current.ToString();
                        this.pos         = i + 2;
                        return;
                    }
                    else
                    {
                        current.Append(cur);
                    }
                    continue;
                }
                initial = true;
                if (this.Evulator.DecodeAmpCode && tagElement.ElementType != TextElementType.CommentNode && cur == '&')
                {
                    current.Append(this.DecodeAmp(i + 1));
                    i = this.pos;
                    continue;
                }

                if (tagElement.ElementType == TextElementType.Parameter && this.Evulator.ParamNoAttrib)
                {
                    if (cur != this.Evulator.RightTag)
                    {
                        current.Append(cur);
                        continue;
                    }
                }
                if (namefound && tagElement.NoAttrib)
                {
                    if (cur != this.Evulator.RightTag)
                    {
                        current.Append(cur);
                        continue;
                    }
                }
                if (firstslashused && namefound)
                {
                    if (cur != this.Evulator.RightTag)
                    {
                        if (cur == ' ' && next != '\t' && next != ' ')
                        {
                            this.Evulator.IsParseMode = false;
                            throw new Exception("Syntax Error");
                        }
                    }
                }
                if (cur == '"' || cur == '\'')
                {
                    if (!namefound || currentName.Length == 0)
                    {
                        this.Evulator.IsParseMode = false;
                        throw new Exception("Syntax Error");
                    }
                    if (inquot && cur == quotchar)
                    {
                        if (currentName.ToString() == "##set_TAG_ATTR##")
                        {
                            tagElement.TagAttrib = current.ToString();
                        }
                        else if (currentName.Length > 0)
                        {
                            tagElement.ElemAttr.SetAttribute(currentName.ToString(), current.ToString());
                        }
                        currentName.Clear();
                        current.Clear();
                        inquot = false;
                        quoted = true;
                        continue;
                    }
                    else if (!inquot)
                    {
                        quotchar = cur;
                        inquot   = true;
                        continue;
                    }
                }
                if (!inquot)
                {
                    if (cur == this.Evulator.ParamChar && !namefound && !firstslashused)
                    {
                        tagElement.ElementType = TextElementType.Parameter;
                        tagElement.Closed      = true;
                        continue;
                    }
                    if (cur == '/')
                    {
                        if (!namefound && current.Length > 0)
                        {
                            namefound           = true;
                            tagElement.ElemName = current.ToString();
                            current.Clear();
                        }
                        if (namefound)
                        {
                            lastslashused = true;
                        }
                        else
                        {
                            firstslashused = true;
                        }
                        continue;
                    }
                    if (cur == '=')
                    {
                        if (namefound)
                        {
                            if (current.Length == 0)
                            {
                                this.Evulator.IsParseMode = false;
                                throw new Exception("Syntax Error");
                            }
                            currentName.Clear();
                            currentName.Append(current.ToString());
                            current.Clear();
                        }
                        else
                        {
                            namefound           = true;
                            tagElement.ElemName = current.ToString();
                            current.Clear();
                            currentName.Clear();
                            currentName.Append("##set_TAG_ATTR##");
                        }
                        continue;
                    }
                    if (tagElement.ElementType == TextElementType.XMLTag)
                    {
                        if (cur == '?' && next == this.Evulator.RightTag)
                        {
                            cur = next;
                            i++;
                        }
                    }

                    if (cur == this.Evulator.LeftTag)
                    {
                        this.Evulator.IsParseMode = false;
                        throw new Exception("Syntax Error");
                    }
                    if (cur == this.Evulator.RightTag)
                    {
                        if (!namefound)
                        {
                            tagElement.ElemName = current.ToString();
                            current.Clear();
                        }
                        if (tagElement.NoAttrib)
                        {
                            tagElement.Value = current.ToString();
                        }
                        else if (currentName.ToString() == "##set_TAG_ATTR##")
                        {
                            tagElement.TagAttrib = current.ToString();
                        }
                        else if (currentName.Length > 0)
                        {
                            tagElement.SetAttribute(currentName.ToString(), current.ToString());
                        }
                        else if (current.Length > 0)
                        {
                            tagElement.SetAttribute(current.ToString(), null);
                        }
                        tagElement.SlashUsed = firstslashused;
                        if (lastslashused)
                        {
                            tagElement.DirectClosed = true;
                            tagElement.Closed       = true;
                        }
                        string elname = tagElement.ElemName.ToLowerInvariant();
                        if (this.Evulator.AutoClosedTags.Any(e => e.ToLowerInvariant() == elname))
                        {
                            tagElement.Closed     = true;
                            tagElement.AutoClosed = true;
                        }
                        this.pos = i;
                        return;
                    }
                    if (cur == ' ')
                    {
                        if (next == ' ' || next == '\t' || next == this.Evulator.RightTag)
                        {
                            continue;
                        }
                        if (!namefound && !PhpFuctions.empty(current))
                        {
                            namefound           = true;
                            tagElement.ElemName = current.ToString();
                            current.Clear();
                        }
                        else if (namefound)
                        {
                            if (currentName.ToString() == "##set_TAG_ATTR##")
                            {
                                tagElement.TagAttrib = current.ToString();
                                quoted = false;
                                currentName.Clear();
                                current.Clear();
                            }
                            else if (!PhpFuctions.empty(currentName))
                            {
                                tagElement.SetAttribute(currentName.ToString(), current.ToString());
                                currentName.Clear();
                                current.Clear();
                                quoted = false;
                            }
                            else if (!PhpFuctions.empty(current))
                            {
                                tagElement.SetAttribute(current.ToString(), null);
                                current.Clear();
                                quoted = false;
                            }
                        }
                        continue;
                    }
                }
                current.Append(cur);
            }
            this.pos = this.TextLength;
        }
コード例 #11
0
        public static object OperatorResult(object item1, object item2, string @operator)
        {
            if (item1 == null && item2 == null)
            {
                return(null);
            }
            if ((@operator == "+" || @operator == "-") && item1 == null && item2 != null && TypeUtil.IsNumericType(item2))
            {
                var leftitem  = 0d;
                var rightitem = (double)Convert.ChangeType(item2, typeof(double));
                if (@operator == "+")
                {
                    return(leftitem + rightitem);
                }
                else
                {
                    return(leftitem - rightitem);
                }
            }
            if (@operator == "||" || @operator == "|" || @operator == "or" || @operator == "&&" || @operator == "&" || @operator == "and")
            {
                bool lefstate   = PhpFuctions.not_empty(item1);
                bool rightstate = PhpFuctions.not_empty(item2);
                if (@operator == "||" || @operator == "|" || @operator == "or")
                {
                    if (lefstate != rightstate)
                    {
                        return(true);
                    }
                    return(lefstate);
                }
                else
                {
                    if (lefstate && rightstate)
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            if ((item1 is string && item2 == null) || item2 is string && item1 == null)
            {
                return(false);
            }

            if (@operator == "==" || @operator == "=" || @operator == "!=" && (item1 == null || item2 == null))
            {
                if (item1 == null)
                {
                    if (@operator == "==" || @operator == "=")
                    {
                        return(item2 == null);
                    }
                    else

                    {
                        return(item2 != null);
                    }
                }
                else if (item2 == null)
                {
                    if (@operator == "==" || @operator == "=")
                    {
                        return(item1 == null);
                    }
                    else

                    {
                        return(item1 != null);
                    }
                }
            }
            if (item1 is string && @operator == "+")
            {
                return(item1.ToString() + item2);
            }
            else if (item2 is string && @operator == "+")
            {
                return(item1 + item2.ToString());
            }
            if (item1 is bool && item2 is bool)
            {
                var leftitem  = (bool)item1;
                var rightitem = (bool)item2;
                switch (@operator)
                {
                case "==":
                case "=":
                    return(leftitem == rightitem);

                case "!=":
                    return(leftitem != rightitem);
                }
            }
            else if ((item1 is DateTime && TypeUtil.IsNumericType(item2)) || (item2 is DateTime && TypeUtil.IsNumericType(item1)))
            {
                if (item1 is DateTime)
                {
                    var leftitem  = (DateTime)item1;
                    var rightitem = (double)item2;
                    switch (@operator)
                    {
                    case "+":

                        return(leftitem.AddDays(rightitem));

                    case "-":
                        return(leftitem.AddDays(-1d * rightitem));
                    }
                }
                else
                {
                    var leftitem  = (double)item1;
                    var rightitem = (DateTime)item2;
                    switch (@operator)
                    {
                    case "+":

                        return(rightitem.AddDays(leftitem));

                    case "-":
                        return(rightitem.AddDays(-1d * leftitem));
                    }
                }
            }
            else if (item1 is DateTime && item2 is DateTime)
            {
                var leftitem  = (DateTime)item1;
                var rightitem = (DateTime)item2;
                int cmpres    = leftitem.CompareTo(rightitem);
                switch (@operator)
                {
                case "==":
                case "=":
                    return(cmpres == 0);

                case "!=":
                    return(cmpres != 0);

                case "<":

                    return(cmpres == -1);

                case "<=":
                    return(cmpres == 0 || cmpres == -1);

                case ">":
                    return(cmpres == 1);

                case ">=":
                    return(cmpres == 0 || cmpres == 1);

                default:
                    break;
                }
            }
            else if (item1 is string && item2 is string)
            {
                var leftitem  = (string)item1;
                var rightitem = (string)item2;
                int cmpres    = leftitem.CompareTo(rightitem);
                switch (@operator)
                {
                case "==":
                case "=":
                    return(cmpres == 0);

                case "!=":
                    return(cmpres != 0);

                case "<":

                    return(cmpres == -1);

                case "<=":
                    return(cmpres == 0 || cmpres == -1);

                case ">":
                    return(cmpres == 1);

                case ">=":
                    return(cmpres == 0 || cmpres == 1);

                default:
                    break;
                }
            }

            else
            {
                if (item2 == null)
                {
                    item2 = "";
                }
                if (item1 == null)
                {
                    item1 = "";
                }
                if (TypeUtil.IsNumericType(item1) && TypeUtil.IsNumericType(item2) || TypeUtil.IsNumericType(item1) && item2.ToString().IsNumeric() || TypeUtil.IsNumericType(item2) && item1.ToString().IsNumeric())
                {
                    var leftitem  = (double)Convert.ChangeType(item1, typeof(double));
                    var rightitem = (double)Convert.ChangeType(item2, typeof(double));
                    switch (@operator)
                    {
                    case "==":
                    case "=":
                        return(leftitem == rightitem);

                    case "!=":
                        return(leftitem != rightitem);

                    case "<":
                        return(leftitem < rightitem);

                    case "<=":
                        return(leftitem <= rightitem);

                    case ">":
                        return(leftitem > rightitem);

                    case ">=":
                        return(leftitem >= rightitem);

                    case "+":
                        return(leftitem + rightitem);

                    case "-":
                        return(leftitem - rightitem);

                    case "*":
                        return(leftitem * rightitem);

                    case "/":
                    case "div":
                        return(leftitem / rightitem);

                    case "%":
                    case "mod":
                        return(leftitem % rightitem);

                    case "^":
                        return(Math.Pow(leftitem, rightitem));

                    case "&":
                        return((long)leftitem & (long)rightitem);

                    case "|":
                        return((long)leftitem | (long)rightitem);

                    default:
                        break;
                    }
                }
            }
            return(null);
        }