示例#1
0
        /// <summary>
        /// Deep-Equal boolean operation.
        /// </summary>
        /// <param name="one">
        ///            input1 xpath expression/variable. </param>
        /// <param name="two">
        ///            input2 xpath expression/variable. </param>
        /// <param name="context">
        ///            Current dynamic context </param>
        /// <returns> Result of fn:deep-equal operation. </returns>
        public static bool deep_equal(ResultSequence one, ResultSequence two, EvaluationContext context, string collationURI)
        {
            if (one.empty() && two.empty())
            {
                return(true);
            }

            if (one.size() != two.size())
            {
                return(false);
            }

            var onei = one.iterator();
            var twoi = two.iterator();

            while (onei.MoveNext())
            {
                AnyType a = (AnyType)onei.Current;
                twoi.MoveNext();
                AnyType b = (AnyType)twoi.Current;

                if (!deep_equal(a, b, context, collationURI))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// Unordered operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:unordered operation. </returns>
        public static ResultSequence unordered(ICollection args)
        {
            Debug.Assert(args.Count == 1);

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence arg = (ResultSequence)citer.Current;

            if (arg == null || arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            // XXX lame
            ArrayList tmp = new ArrayList();

            for (IEnumerator i = arg.iterator(); i.MoveNext();)
            {
                tmp.Add(i.Current);
            }

            throw new Exception();
            //Collections.shuffle(tmp);

            //ResultBuffer rb = new ResultBuffer();
            //for (IEnumerator i = tmp.GetEnumerator(); i.MoveNext();)
            //{
            //	rb.add((AnyType) i.Current);
            //}

            //return rb.Sequence;
        }
示例#3
0
 /// <param name="rs">
 ///            ResultSequence </param>
 public override void concat(ResultSequence rs)
 {
     for (var i = rs.iterator(); i.MoveNext();)
     {
         _seq.Add(i.Current);
     }
 }
示例#4
0
        /// <summary>
        /// Min operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dynamic">
        ///            Dynamic context </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:min operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence min(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence min(ICollection args, DynamicContext context)
        {
            ResultSequence arg = FnMax.get_arg(args, typeof(CmpLt));

            if (arg.empty())
            {
                return(ResultSequenceFactory.create_new());
            }

            CmpLt max = null;

            TypePromoter tp = new ComparableTypePromoter();

            tp.considerSequence(arg);

            for (var i = arg.iterator(); i.MoveNext();)
            {
                AnyAtomicType conv = tp.promote((AnyType)i.Current);

                if (conv != null)
                {
                    if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan())
                    {
                        return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN))));
                    }
                    if (max == null || ((CmpLt)conv).lt((AnyType)max, context))
                    {
                        max = (CmpLt)conv;
                    }
                }
            }
            return(ResultSequenceFactory.create_new((AnyType)max));
        }
示例#5
0
        /// <summary>
        /// Join the arguments.
        /// </summary>
        /// <param name="args">
        ///            are joined. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> The result of the arguments being joined together. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence string_join(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence string_join(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            IEnumerator argi = cargs.GetEnumerator();

            argi.MoveNext();
            ResultSequence arg1 = (ResultSequence)argi.Current;

            argi.MoveNext();
            ResultSequence arg2 = (ResultSequence)argi.Current;

            string result    = "";
            string separator = ((XSString)arg2.first()).value();

            StringBuilder buf   = new StringBuilder();
            bool          first = false;

            for (var i = arg1.iterator(); i.MoveNext();)
            {
                if (!first)
                {
                    buf.Append(separator);
                }
                first = false;
                XSString item = (XSString)i.Current;
                buf.Append(item.value());
            }

            result = buf.ToString();
            return(new XSString(result));
        }
示例#6
0
        /// <summary>
        /// Atomize a ResultSequnce argument expression.
        /// </summary>
        /// <param name="arg">
        ///            input expression. </param>
        /// <returns> Result of operation. </returns>
        public static ResultSequence atomize(ResultSequence arg)
        {
            ResultBuffer rs = new ResultBuffer();

            for (var i = arg.iterator(); i.MoveNext();)
            {
                AnyType at = (AnyType)i.Current;

                if (at is AnyAtomicType)
                {
                    rs.add(at);
                }
                else if (at is NodeType)
                {
                    NodeType nt = (NodeType)at;
                    rs.concat(nt.typed_value());
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            return(rs.Sequence);
        }
示例#7
0
        /// <summary>
        /// Distinct-values operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:distinct-values operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence distinct_values(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence distinct_values(ICollection args, DynamicContext context)
        {
            ResultBuffer rs = new ResultBuffer();

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence arg1 = (ResultSequence)citer.Current;
            ResultSequence arg2 = ResultBuffer.EMPTY;

            if (citer.MoveNext())
            {
                arg2 = (ResultSequence)citer.Current;
            }

            string collationURI = context.CollationProvider.DefaultCollation;

            if (!(arg2 == null || arg2.empty()))
            {
                XSString collation = (XSString)arg2.item(0);
                collationURI = collation.StringValue;
            }

            for (var iter = arg1.iterator(); iter.MoveNext();)
            {
                AnyAtomicType atomizedItem = (AnyAtomicType)FnData.atomize((Item)iter.Current);
                if (!contains(rs, atomizedItem, context, collationURI))
                {
                    rs.add(atomizedItem);
                }
            }

            return(rs.Sequence);
        }
示例#8
0
 public virtual ResultBuffer concat(ResultSequence rs)
 {
     for (var i = rs.iterator(); i.MoveNext();)
     {
         var s = i.Current;
         values.Add(s);
     }
     // KED KED values.AddRange(collectionWrapper(rs));
     return(this);
 }
示例#9
0
        /// <summary>
        /// Average value operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:avg operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence avg(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence avg(ICollection args)
        {
            var j = args.GetEnumerator();

            j.MoveNext();
            ResultSequence arg = (ResultSequence)j.Current;

            if (arg == null || arg.empty())
            {
                return(ResultSequenceFactory.create_new());
            }

            int elems = 0;

            MathPlus total = null;

            TypePromoter tp = new ScalarTypePromoter();

            tp.considerSequence(arg);

            for (var i = arg.iterator(); i.MoveNext();)
            {
                ++elems;
                AnyAtomicType conv = tp.promote((AnyType)i.Current);
                if (conv != null)
                {
                    if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan())
                    {
                        return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN))));
                    }
                    if (total == null)
                    {
                        total = (MathPlus)conv;
                    }
                    else
                    {
                        total = (MathPlus)total.plus(ResultSequenceFactory.create_new(conv)).first();
                    }
                }
            }

            if (!(total is MathDiv))
            {
                DynamicError.throw_type_error();
            }

            return(((MathDiv)total).div(ResultSequenceFactory.create_new(new XSInteger(new System.Numerics.BigInteger(elems)))));
        }
示例#10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.eclipse.wst.xml.xpath2.api.ResultSequence convertResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        private ResultSequence convertResultSequence(ResultSequence arg)
        {
            ResultSequence carg = arg;
            var            it   = carg.iterator();

            while (it.MoveNext())
            {
                AnyType type = (AnyType)it.Current;
                if (type.string_type().Equals("xs:untypedAtomic") || type.string_type().Equals("xs:string"))
                {
                    throw DynamicError.invalidType();
                }
            }
            carg = constructor(carg);
            return(carg);
        }
示例#11
0
        /// <summary>
        /// Op-Intersect operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence op_intersect(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence op_intersect(ICollection args)
        {
            ResultBuffer rs = new ResultBuffer();

            // convert arguments
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arguments
            IEnumerator iter = cargs.GetEnumerator();

            iter.MoveNext();
            ResultSequence one = (ResultSequence)iter.Current;

            iter.MoveNext();
            ResultSequence two = (ResultSequence)iter.Current;

            // XXX lame
            for (var i = one.iterator(); i.MoveNext();)
            {
                NodeType node  = (NodeType)i.Current;
                bool     found = false;

                // death
                for (var j = two.iterator(); j.MoveNext();)
                {
                    NodeType node2 = (NodeType)j.Current;

                    if (node.node_value() == node2.node_value())
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    rs.add(node);
                }
            }
            rs = NodeType.linarize(rs);

            return(rs.Sequence);
        }
示例#12
0
        /// <summary>
        /// Codepoints to string operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:codepoints-to-string operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence codepoints_to_string(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence codepoints_to_string(ICollection args)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());
            var         j     = cargs.GetEnumerator();

            j.MoveNext();
            ResultSequence arg1 = (ResultSequence)j.Current;

            if (arg1 == null || arg1.empty())
            {
                return(new XSString(""));
            }

            int[] codePointArray = new int[arg1.size()];
            int   codePointIndex = 0;

            for (var i = arg1.iterator(); i.MoveNext();)
            {
                XSInteger code = (XSInteger)i.Current;

                int codepoint = (int)code.int_value();
                if (codepoint < MIN_LEGAL_CODEPOINT || codepoint > MAX_LEGAL_CODEPOINT)
                {
                    throw DynamicError.unsupported_codepoint("U+" + Convert.ToString(codepoint, 16).ToUpper());
                }

                codePointArray[codePointIndex] = codepoint;
                codePointIndex++;
            }

            try
            {
                var    c   = codePointArray.Select(x => (char)x).ToArray();
                string str = new string(c);
                return(new XSString(str));
            }
            catch (System.ArgumentException iae)
            {
                // This should be duoble checked above, but rather safe than sorry
                throw DynamicError.unsupported_codepoint(iae.Message);
            }
        }
示例#13
0
        /// <summary>
        /// Trace operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:trace operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence trace(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence trace(ICollection args)
        {
            // sanity check args
            if (args.Count != 2)
            {
                DynamicError.throw_type_error();
            }

            IEnumerator argsi = args.GetEnumerator();

            argsi.MoveNext();
            ResultSequence arg1 = (ResultSequence)argsi.Current;

            argsi.MoveNext();
            ResultSequence arg2 = (ResultSequence)argsi.Current;

            if (arg2 == null || arg2.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg2.first();

            if (!(at is XSString))
            {
                DynamicError.throw_type_error();
            }

            XSString label = (XSString)at;

            int index = 1;

            for (var i = arg1.iterator(); i.MoveNext(); index++)
            {
                at = (AnyType)i.Current;

                Console.WriteLine(label.value() + " [" + index + "] " + ((AnyType)at).string_type() + ":" + at.StringValue);
            }

            return(arg1);
        }
示例#14
0
        /// <summary>
        /// Sum operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:sum operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence sum(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType zero) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence sum(ResultSequence arg, AnyAtomicType zero)
        {
            if (arg.empty())
            {
                return(ResultSequenceFactory.create_new(zero));
            }

            MathPlus total = null;

            TypePromoter tp = new ScalarTypePromoter();

            tp.considerSequence(arg);

            for (var i = arg.iterator(); i.MoveNext();)
            {
                AnyAtomicType conv = tp.promote((AnyType)i.Current);

                if (conv == null)
                {
                    conv = zero;
                }

                if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan())
                {
                    return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN))));
                }
                if (total == null)
                {
                    total = (MathPlus)conv;
                }
                else
                {
                    total = (MathPlus)total.plus(ResultSequenceFactory.create_new(conv)).first();
                }
            }

            return(ResultSequenceFactory.create_new((AnyType)total));
        }
示例#15
0
        /// <summary>
        /// interate through range.
        /// </summary>
        /// <returns> tail </returns>
        public override IEnumerator <Item> iterator()
        {
            // XXX life is getting hard...
            if (_size != 0)
            {
                ResultSequence newtail = ResultSequenceFactory.create_new();

                for (; _start <= _end; _start++)
                {
                    newtail.add(new XSInteger(new System.Numerics.BigInteger(_start)));
                }

                newtail.concat(_tail);
                _tail.release();
                _tail = newtail;

                _size  = 0;
                _start = 0;
                _end   = 0;
            }

            return(_tail.iterator());
        }
示例#16
0
        /// <summary>
        /// Subsequence operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:subsequence operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence subsequence(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence subsequence(ICollection args)
        {
            ResultBuffer rs = new ResultBuffer();

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence seq = (ResultSequence)citer.Current;

            if (seq.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            citer.MoveNext();
            ResultSequence startLoc = (ResultSequence)citer.Current;
            ResultSequence length   = null;

            if (citer.MoveNext())
            {
                length = (ResultSequence)citer.Current;
            }

            Item at = startLoc.first();

            if (!(at is NumericType))
            {
                DynamicError.throw_type_error();
            }

            at = new XSDouble(at.StringValue);

            int start            = (int)((XSDouble)at).double_value();
            int effectiveNoItems = 0;             // no of items beyond index >= 1 that are added to the result

            if (length != null)
            {
                // the 3rd argument is present
                if (length.size() != 1)
                {
                    DynamicError.throw_type_error();
                }
                at = length.first();
                if (!(at is NumericType))
                {
                    DynamicError.throw_type_error();
                }
                at = new XSDouble(at.StringValue);
                int len = (int)((XSDouble)at).double_value();
                if (len < 0)
                {
                    DynamicError.throw_type_error();
                }

                if (start <= 0)
                {
                    effectiveNoItems = start + len - 1;
                    start            = 1;
                }
                else
                {
                    effectiveNoItems = len;
                }
            }
            else
            {
                // 3rd argument is absent
                if (start <= 0)
                {
                    start            = 1;
                    effectiveNoItems = seq.size();
                }
                else
                {
                    effectiveNoItems = seq.size() - start + 1;
                }
            }

            int pos        = 1;      // index running parallel to the iterator
            int addedItems = 0;

            if (effectiveNoItems > 0)
            {
                for (var seqIter = seq.iterator(); seqIter.MoveNext();)
                {
                    at = (AnyType)seqIter.Current;
                    if (start <= pos && addedItems < effectiveNoItems)
                    {
                        rs.add(at);
                        addedItems++;
                    }
                    pos++;
                }
            }

            return(rs.Sequence);
        }
示例#17
0
        // voodoo 3
        /// <summary>
        /// Actual equality operation for fs_eq_general.
        /// </summary>
        /// <param name="args">
        ///            input arguments. </param>
        /// <param name="type">
        ///            type of the arguments. </param>
        /// <param name="mname">
        ///            Method name for template simulation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of the operation. </returns>
        public static ResultSequence do_cmp_general_op(ICollection args, Type type, string mname, DynamicContext dc)
        {
            // do the voodoo
            MethodBase comparator = null;

            try
            {
                Type[]   margsdef  = new Type[] { type };
                Type[]   margsdef2 = new Type[] { typeof(ICollection), typeof(DynamicContext) };
                object[] margs3    = new object[] { mname, margsdef2 };
                var      v1        = typeof(GenericIComparer)
                                     .GetMethod("GetComparer");
                var v2 = v1.MakeGenericMethod(margsdef);

                comparator = (MethodBase)v2.Invoke(null, margs3);
            }
            catch
            {
                throw new Exception("Can't find method : " + mname);
            }

            // sanity check args and get them
            if (args.Count != 2)
            {
                DynamicError.throw_type_error();
            }

            IEnumerator argiter = args.GetEnumerator();

            argiter.MoveNext();
            ResultSequence one = (ResultSequence)argiter.Current;

            argiter.MoveNext();
            ResultSequence two = (ResultSequence)argiter.Current;

            // XXX ?
            if (one.empty() || two.empty())
            {
                return(ResultSequenceFactory.create_new(new XSBoolean(false)));
            }

            // atomize
            one = FnData.atomize(one);
            two = FnData.atomize(two);

            // we gotta find a pair that satisfied the condition
            for (IEnumerator i = one.iterator(); i.MoveNext();)
            {
                AnyType a = (AnyType)i.Current;
                for (IEnumerator j = two.iterator(); j.MoveNext();)
                {
                    AnyType b = (AnyType)j.Current;

                    if (do_general_pair(a, b, comparator, dc))
                    {
                        return(ResultSequenceFactory.create_new(new XSBoolean(true)));
                    }
                }
            }

            return(ResultSequenceFactory.create_new(new XSBoolean(false)));
        }
示例#18
0
        /// <summary>
        /// Convert-Operand operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fs: operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_operand(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence convert_operand(ICollection args)
        {
            Debug.Assert(args.Count == 2);

            IEnumerator iter = args.GetEnumerator();

            iter.MoveNext();
            ResultSequence actual = (ResultSequence)iter.Current;

            iter.MoveNext();
            ResultSequence expected = (ResultSequence)iter.Current;

            if (expected == null || expected.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = expected.first();

            if (!(at is AnyAtomicType))
            {
                DynamicError.throw_type_error();
            }

            AnyAtomicType exp_aat = (AnyAtomicType)at;

            ResultBuffer result = new ResultBuffer();

            // 1
            if (actual.empty())
            {
                return(result.Sequence);
            }

            // convert sequence
            for (var i = actual.iterator(); i.MoveNext();)
            {
                AnyType item = (AnyType)i.Current;

                // 2
                if (item is XSUntypedAtomic)
                {
                    // a
                    if (exp_aat is XSUntypedAtomic)
                    {
                        result.add(new XSString(item.StringValue));
                    }
                    // b
                    else if (exp_aat is NumericType)
                    {
                        result.add(new XSDouble(item.StringValue));
                    }
                    // c
                    else
                    {
                        Debug.Assert(exp_aat is CtrType);
                        CtrType cons = (CtrType)exp_aat;
                        result.concat(cons.constructor(new XSString(item.StringValue)));
                    }
                }
                // 4
                else
                {
                    result.add(item);
                }
            }

            return(result.Sequence);
        }
示例#19
0
        /// <summary>
        /// Index-Of operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dynamicContext"> </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:index-of operation. </returns>
        public static ResultSequence index_of(ICollection args, DynamicContext dc)
        {
            Function.convert_arguments(args, expected_args());

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence arg1 = (ResultSequence)citer.Current;

            citer.MoveNext();
            ResultSequence arg2 = (ResultSequence)citer.Current;

            if (arg1 == null || arg1.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            // sanity chex
            if (arg2 == null || arg2.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            string collationUri = dc.CollationProvider.DefaultCollation;

            if (citer.MoveNext())
            {
                ResultSequence arg3 = (ResultSequence)citer.Current;
                if (!arg3.empty())
                {
                    XSString collation = (XSString)arg3.first();
                    collationUri = collation.StringValue;
                }
            }

            ResultBuffer  rb = new ResultBuffer();
            AnyAtomicType at = (AnyAtomicType)arg2.first();

            get_comparable(at);

            int index = 1;

            for (var i = arg1.iterator(); i.MoveNext();)
            {
                AnyType cmptype = (AnyType)i.Current;
                get_comparable(cmptype);

                if (!(at is CmpEq))
                {
                    continue;
                }

                if (isBoolean(cmptype, at))
                {
                    XSBoolean boolat = (XSBoolean)cmptype;
                    if (boolat.eq(at, dc))
                    {
                        rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                    }
                }
                else
                {
                    if (isNumeric(cmptype, at))
                    {
                        NumericType numericat = (NumericType)at;
                        if (numericat.eq(cmptype, dc))
                        {
                            rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                        }
                    }
                    else
                    {
                        if (isDuration(cmptype, at))
                        {
                            XSDuration durat = (XSDuration)at;
                            if (durat.eq(cmptype, dc))
                            {
                                rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                            }
                        }
                        else
                        {
                            if (at is QName && cmptype is QName)
                            {
                                QName qname = (QName)at;
                                if (qname.eq(cmptype, dc))
                                {
                                    rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                                }
                            }
                            else
                            {
                                if (needsStringComparison(cmptype, at))
                                {
                                    XSString xstr1   = new XSString(cmptype.StringValue);
                                    XSString itemStr = new XSString(at.StringValue);
                                    if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).Equals(System.Numerics.BigInteger.Zero))
                                    {
                                        rb.add(new XSInteger(new System.Numerics.BigInteger(index)));
                                    }
                                }
                            }
                        }
                    }
                }

                index++;
            }

            return(rb.Sequence);
        }
示例#20
0
        /// <summary>
        /// matches args
        /// </summary>
        /// <param name="args">
        ///            is a result sequence </param>
        /// <exception cref="a">
        ///             dynamic error </exception>
        /// <returns> a result sequence </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence match(org.eclipse.wst.xml.xpath2.api.ResultSequence args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence match(ResultSequence args)
        {
            int occurrence = occurence();

            // Check for empty sequence first
            if (occurrence == OCC_EMPTY && !args.empty())
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            int arg_count = 0;

            for (var i = args.iterator(); i.MoveNext();)
            {
                AnyType arg = (AnyType)i.Current;

                // make sure all args are the same type as expected type
                if (!(typeClass.IsInstanceOfType(arg)))
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }

                if (anytype != null)
                {
                    if ((nodeName != null || wild) && arg is NodeType)
                    {
                        NodeType nodeType = (NodeType)arg;
                        Node     node     = nodeType.node_value();
                        Node     lnode    = ((NodeType)anytype).node_value();
                        if (lnode == null)
                        {
                            //throw new DynamicError(TypeError.invalid_type(null));
                            continue;
                        }
                        if (!lnode.isEqualNode(node))
                        {
                            //throw new DynamicError(TypeError.invalid_type(null));
                            continue;
                        }
                    }
                }

                arg_count++;
            }

            switch (occurrence)
            {
            case OCC_NONE:
                if (arg_count != 1)
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }
                break;

            case OCC_PLUS:
                if (arg_count == 0)
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }
                break;

            case OCC_STAR:
                break;

            case OCC_QMARK:
                if (arg_count > 1)
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }
                break;

            default:
                Debug.Assert(false);

                break;
            }

            return(args);
        }
示例#21
0
        /// <summary>
        /// Insert-Before operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:insert-before operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence insert_before(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence insert_before(ICollection args)
        {
            Debug.Assert(args.Count == 3);

            ResultBuffer rs = new ResultBuffer();

            // get args
            IEnumerator citer = args.GetEnumerator();

            citer.MoveNext();
            ResultSequence target = (ResultSequence)citer.Current;

            citer.MoveNext();
            ResultSequence arg2 = (ResultSequence)citer.Current;

            citer.MoveNext();
            ResultSequence inserts = (ResultSequence)citer.Current;

            // sanity chex
            if (arg2.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg2.first();

            if (!(at is XSInteger))
            {
                DynamicError.throw_type_error();
            }

            // XXX cloning!
            if (target.empty())
            {
                return(inserts);
            }
            if (inserts.empty())
            {
                return(target);
            }

            int position = (int)((XSInteger)at).int_value();

            if (position < 1)
            {
                position = 1;
            }
            int target_size = target.size();

            if (position > target_size)
            {
                position = target_size + 1;
            }

            int curpos = 1;

            for (var i = target.iterator(); i.MoveNext();)
            {
                at = (AnyType)i.Current;

                if (curpos == position)
                {
                    rs.concat(inserts);
                }

                rs.add(at);

                curpos++;
            }
            if (curpos == position)
            {
                rs.concat(inserts);
            }

            return(rs.Sequence);
        }