Ejemplo n.º 1
0
 public override object Evaluate(XPathNodeIterator nodeIterator)
 {
     return(GetValue(_op,
                     XmlConvertEx.ToXPathDouble(_opnd1.Evaluate(nodeIterator)),
                     XmlConvertEx.ToXPathDouble(_opnd2.Evaluate(nodeIterator))
                     ));
 }
Ejemplo n.º 2
0
        public int Compare(object x, object y)
        {
            switch (_dataType)
            {
            case XmlDataType.Text:
                string s1     = Convert.ToString(x, _cinfo);
                string s2     = Convert.ToString(y, _cinfo);
                int    result = _cinfo.CompareInfo.Compare(s1, s2, _caseOrder != XmlCaseOrder.None ? CompareOptions.IgnoreCase : CompareOptions.None);

                if (result != 0 || _caseOrder == XmlCaseOrder.None)
                {
                    return((_order == XmlSortOrder.Ascending) ? result : -result);
                }

                // If we came this far, it means that strings s1 and s2 are
                // equal to each other when case is ignored. Now it's time to check
                // and see if they differ in case only and take into account the user
                // requested case order for sorting purposes.
                result = _cinfo.CompareInfo.Compare(s1, s2);
                return((_caseOrder == XmlCaseOrder.LowerFirst) ? result : -result);

            case XmlDataType.Number:
                double r1 = XmlConvertEx.ToXPathDouble(x);
                double r2 = XmlConvertEx.ToXPathDouble(y);
                result = r1.CompareTo(r2);
                return((_order == XmlSortOrder.Ascending) ? result : -result);

            default:
                // dataType doesn't support any other value
                throw new InvalidOperationException(SR.Xml_InvalidOperation);
            }
        } // Compare ()
Ejemplo n.º 3
0
        private double Number(XPathNodeIterator nodeIterator)
        {
            if (arg == null)
            {
                return(XmlConvertEx.ToXPathDouble(nodeIterator.Current.Value));
            }
            object argVal = arg.Evaluate(nodeIterator);

            switch (GetXPathType(argVal))
            {
            case XPathResultType.NodeSet:
                XPathNavigator value = arg.Advance();
                if (value != null)
                {
                    return(Number(value.Value));
                }
                break;

            case XPathResultType.String:
                return(Number((string)argVal));

            case XPathResultType.Boolean:
                return(Number((bool)argVal));

            case XPathResultType.Number:
                return((double)argVal);

            case XPathResultType_Navigator:
                return(Number(((XPathNavigator)argVal).Value));
            }
            return(double.NaN);
        }
Ejemplo n.º 4
0
        private double ScanFraction()
        {
            Debug.Assert(XmlCharType.IsDigit(this.CurrentChar));
            int start = _xpathExprIndex - 2;

            Debug.Assert(0 <= start && _xpathExpr[start] == '.');
            int len = 1; // '.'

            while (XmlCharType.IsDigit(this.CurrentChar))
            {
                NextChar(); len++;
            }
            return(XmlConvertEx.ToXPathDouble(_xpathExpr.Substring(start, len)));
        }
Ejemplo n.º 5
0
        private double ScanNumber()
        {
            Debug.Assert(this.CurrentChar == '.' || XmlCharType.IsDigit(this.CurrentChar));
            int start = _xpathExprIndex - 1;
            int len   = 0;

            while (XmlCharType.IsDigit(this.CurrentChar))
            {
                NextChar(); len++;
            }
            if (this.CurrentChar == '.')
            {
                NextChar(); len++;
                while (XmlCharType.IsDigit(this.CurrentChar))
                {
                    NextChar(); len++;
                }
            }
            return(XmlConvertEx.ToXPathDouble(_xpathExpr.Substring(start, len)));
        }
Ejemplo n.º 6
0
        private string Substring(XPathNodeIterator nodeIterator)
        {
            string str1 = argList[0].Evaluate(nodeIterator).ToString();
            double num  = XmlConvertEx.XPathRound(XmlConvertEx.ToXPathDouble(argList[1].Evaluate(nodeIterator))) - 1;

            if (Double.IsNaN(num) || str1.Length <= num)
            {
                return(string.Empty);
            }
            if (argList.Count == 3)
            {
                double num1 = XmlConvertEx.XPathRound(XmlConvertEx.ToXPathDouble(argList[2].Evaluate(nodeIterator)));
                if (Double.IsNaN(num1))
                {
                    return(string.Empty);
                }
                if (num < 0 || num1 < 0)
                {
                    num1 = num + num1;
                    // NOTE: condition is true for NaN
                    if (!(num1 > 0))
                    {
                        return(string.Empty);
                    }
                    num = 0;
                }
                double maxlength = str1.Length - num;
                if (num1 > maxlength)
                {
                    num1 = maxlength;
                }
                return(str1.Substring((int)num, (int)num1));
            }
            if (num < 0)
            {
                num = 0;
            }
            return(str1.Substring((int)num));
        }
Ejemplo n.º 7
0
 internal static double Number(string arg)
 {
     return(XmlConvertEx.ToXPathDouble(arg));
 }
Ejemplo n.º 8
0
        private double Round(XPathNodeIterator nodeIterator)
        {
            double n = XmlConvertEx.ToXPathDouble(arg.Evaluate(nodeIterator));

            return(XmlConvertEx.XPathRound(n));
        }