protected internal static bool needsStringComparison(AnyType item, AnyType at) { if (item is NumericType) { if (at is XSFloat) { XSFloat f = (XSFloat)at; if (f.nan()) { return(true); } } if (at is XSDouble) { XSDouble d = (XSDouble)at; if (d.nan()) { return(true); } } } if (at is XSString) { return(true); } if (at is XSUntypedAtomic) { return(true); } return(false); }
/// <summary> /// Absolute value operation. /// </summary> /// <param name="arg"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:abs 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 fn_abs(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence fn_abs(ResultSequence arg) { // sanity chex NumericType nt = get_single_numeric_arg(arg); // empty arg if (nt == null) { return(ResultBuffer.EMPTY); } if (nt is XSDouble) { XSDouble dat = (XSDouble)nt; if (dat.zero() || dat.negativeZero()) { return(new XSDouble("0")); } if (dat.infinite()) { return(new XSDouble(double.PositiveInfinity)); } } if (nt is XSFloat) { XSFloat dat = (XSFloat)nt; if (dat.zero() || dat.negativeZero()) { return(new XSFloat((float)0)); } if (dat.infinite()) { return(new XSFloat(float.PositiveInfinity)); } } return(nt.abs()); }
/// <summary> /// Convert and promote arguments for operation. /// </summary> /// <param name="args"> /// input arguments. </param> /// <param name="sc"> </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of conversion. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static java.util.Collection convert_args(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError private static ICollection convert_args(ICollection args) { var result = new ArrayList(); // Keep track of numeric types for promotion bool has_float = false; bool has_double = false; // atomize arguments for (IEnumerator i = args.GetEnumerator(); i.MoveNext();) { ResultSequence rs = FnData.atomize((ResultSequence)i.Current); if (rs.empty()) { return(new ArrayList()); } if (rs.size() > 1) { throw new DynamicError(TypeError.invalid_type(null)); } AnyType arg = (AnyType)rs.item(0); if (arg is XSUntypedAtomic) { arg = new XSDouble(arg.StringValue); } if (arg is XSDouble) { has_double = true; } if (arg is XSFloat) { has_float = true; } result.Add(ResultBuffer.wrap(arg)); } if (has_double) { has_float = false; } if (has_double || has_float) { var result2 = new ArrayList(); // promote arguments for (IEnumerator i = result.GetEnumerator(); i.MoveNext();) { ResultSequence rs = (ResultSequence)i.Current; Item arg = rs.item(0); if (has_double && (arg is XSFloat)) { arg = new XSDouble(((XSFloat)arg).float_value()); } else if (has_double && (arg is XSDecimal)) { arg = new XSDouble(((XSDecimal)arg).double_value()); } else if (has_float && (arg is XSDecimal)) { arg = new XSFloat((float)((XSDecimal)arg).double_value()); } result2.Add(arg); } return(result2); } return(result); }
/// <summary> /// Making sure that the types are the same before comparing the inputs. /// </summary> /// <param name="a"> /// input1 of any type. </param> /// <param name="b"> /// input2 of any type. </param> /// <param name="dc"> /// Dynamic Context </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of Equality operation. </returns> private static bool do_general_pair(AnyType a, AnyType b, MethodBase comparator, DynamicContext ec) { // section 3.5.2 // rule a // if one is untyped and other is numeric, cast untyped to // double if ((a is XSUntypedAtomic && b is NumericType) || (b is XSUntypedAtomic && a is NumericType)) { if (a is XSUntypedAtomic) { a = new XSDouble(a.StringValue); } else { b = new XSDouble(b.StringValue); } } // rule b // if one is untyped and other is string or untyped, then cast // untyped to string else if ((a is XSUntypedAtomic && (b is XSString || b is XSUntypedAtomic) || (b is XSUntypedAtomic && (a is XSString || a is XSUntypedAtomic)))) { if (a is XSUntypedAtomic) { a = new XSString(a.StringValue); } if (b is XSUntypedAtomic) { b = new XSString(b.StringValue); } } // rule c // if one is untyped and other is not string,untyped,numeric // cast untyped to dynamic type of other // XXX? // TODO: This makes no sense as implemented before else if (a is XSUntypedAtomic) { //ResultSequence converted = ResultSequenceFactory.create_new(a); //Debug.Assert(converted.size() == 1); //a = (AnyType)converted.first(); } else if (b is XSUntypedAtomic) { //ResultSequence converted = ResultSequenceFactory.create_new(b); //Debug.Assert(converted.size() == 1); //b = (AnyType) converted.first(); } // rule d // if value comparison is true, return true. ResultSequence one = ResultSequenceFactory.create_new(a); ResultSequence two = ResultSequenceFactory.create_new(b); var args = new ArrayList(); args.Add(one); args.Add(two); object[] margs = new object[] { args, ec }; ResultSequence result = null; try { result = (ResultSequence)comparator.Invoke(null, margs); } catch (Exception) { throw; } if (((XSBoolean)result.first()).value()) { return(true); } return(false); }
/// <summary> /// Constructor for Doubleiteral /// </summary> /// <param name="value"> /// double value </param> public DoubleLiteral(double value) { _value = new XSDouble(value); }
// convert argument according to section 3.1.5 of xpath 2.0 spec /// <summary> /// Convert the input argument according to section 3.1.5 of specification. /// </summary> /// <param name="arg"> /// input argument. </param> /// <param name="expected"> /// Expected Sequence type. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Converted argument. </returns> public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected) { ResultBuffer result = new ResultBuffer(); // XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class()) AnyType expected_type = expected.type(); // expected is atomic if (expected_type is AnyAtomicType) { AnyAtomicType expected_aat = (AnyAtomicType)expected_type; // atomize org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg); // cast untyped to expected type for (var i = rs.iterator(); i.MoveNext();) { AnyType item = (AnyType)i.Current; if (item is XSUntypedAtomic) { // create a new item of the expected // type initialized with from the string // value of the item ResultSequence converted = null; if (expected_aat is XSString) { XSString strType = new XSString(item.StringValue); converted = ResultSequenceFactory.create_new(strType); } else { converted = ResultSequenceFactory.create_new(item); } result.concat(converted); } // xs:anyURI promotion to xs:string else if (item is XSAnyURI && expected_aat is XSString) { result.add(new XSString(item.StringValue)); } // numeric type promotion else if (item is NumericType) { if (expected_aat is XSDouble) { XSDouble doubleType = new XSDouble(item.StringValue); result.add(doubleType); } else { result.add(item); } } else { result.add(item); } } // do sequence type matching on converted arguments return(expected.match(result.Sequence)); } else { // do sequence type matching on converted arguments return(expected.match(arg)); } }
/// <summary> /// Number operation. /// </summary> /// <param name="arg"> /// Result from the expressions evaluation. </param> /// <param name="dc"> /// Result of dynamic context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:number operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble fn_number(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static XSDouble fn_number(ResultSequence arg, EvaluationContext ec) { if (arg.size() > 1) { throw new DynamicError(TypeError.invalid_type("bad argument passed to fn:number()")); } else if (arg.size() == 1) { Item at = arg.first(); /* * if (!(at instanceof AnyAtomicType)) * DynamicError.throw_type_error(); */ if (at is AnyAtomicType) { if ((at is XSDouble)) { return((XSDouble)at); } else if ((at is XSFloat)) { float value = ((XSFloat)at).float_value(); if (float.IsNaN(value)) { return(new XSDouble(double.NaN)); } else if (value == float.NegativeInfinity) { return(new XSDouble(double.NegativeInfinity)); } else if (value == float.PositiveInfinity) { return(new XSDouble(double.PositiveInfinity)); } else { return(new XSDouble((double)value)); } } else { XSDouble d = XSDouble.parse_double(at.StringValue); return(d != null ? d : new XSDouble(double.NaN)); } } else if (at is NodeType) { XSDouble d = XSDouble.parse_double((FnData.atomize(at)).StringValue); return(d != null ? d : new XSDouble(double.NaN)); } } else { return(new XSDouble(double.NaN)); } // unreach return(null); }
/// <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); }