public override double evalNumber(VTDNav vn) { int ac = 0; switch (opCode) { case FuncName.LAST: /*if (argCount() != 0) throw new System.ArgumentException("floor()'s argument count is invalid");*/ return contextSize; case FuncName.POSITION: /*if (argCount() != 0) throw new System.ArgumentException("position()'s argument count is invalid");*/ return position; case FuncName.COUNT: return count(vn); case FuncName.NUMBER: /*if (argCount() != 1) throw new System.ArgumentException("number()'s argument count is invalid");*/ return argumentList.e.evalNumber(vn); case FuncName.SUM: return sum(vn); case FuncName.FLOOR: /*if (argCount() != 1) throw new System.ArgumentException("floor()'s argument count is invalid");*/ return System.Math.Floor(argumentList.e.evalNumber(vn)); case FuncName.CEILING: /*if (argCount() != 1) throw new System.ArgumentException("ceiling()'s argument count is invalid");*/ return System.Math.Ceiling(argumentList.e.evalNumber(vn)); case FuncName.STRING_LENGTH: //return stringLen ac = argCount(); if (ac == 0) { try { if (vn.atTerminal == true) { int type = vn.getTokenType(vn.LN); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { return vn.getStringLength(vn.LN + 1); } else { return vn.getStringLength(vn.LN); } } else { int i = vn.getText(); if (i == -1) return 0; else return vn.getStringLength(i); } } catch (NavException e) { return 0; } } else if (ac == 1) { return argumentList.e.evalString(vn).Length; } else { throw new System.ArgumentException("string-length()'s argument count is invalid"); } //goto case FuncName.ROUND; case FuncName.ROUND:/* if (argCount() != 1) throw new System.ArgumentException("round()'s argument count is invalid");*/ //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangMathround_double'" return (long)System.Math.Round(argumentList.e.evalNumber(vn)); case FuncName.ABS: /*if (argCount() != 1) throw new System.ArgumentException("abs()'s argument count is invalid");*/ //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangMathround_double'" return (long)System.Math.Abs(argumentList.e.evalNumber(vn)); case FuncName.ROUND_HALF_TO_EVEN: return roundHalfToEven(vn); /*int numArg = argCount(); if (numArg < 1 || numArg > 2) { throw new System.ArgumentException("Argument count for roundHalfToEven() is invalid. Expected: 1 or 2; Actual: " + numArg); } double value = argumentList.e.evalNumber(vn); int precision = (numArg == 2) ? (int)Math.Floor(argumentList.next.e.evalNumber(vn) + 0.5d) : 0; return (long)System.Math.Round(value, precision, MidpointRounding.ToEven);*/ case FuncName.ROUND_HALF_TO_ODD: throw new com.ximpleware.xpath.UnsupportedException("not yet implemented"); default: if (isBoolean_Renamed_Field) { if (evalBoolean(vn)) return 1; else return 0; } else { try { double dval = System.Double.Parse(evalString(vn)); return dval; } catch (System.FormatException e) { return System.Double.NaN; } //return System.Double.Parse(evalString(vn)); } //break; } }
private double sum(VTDNav vn) { double d = 0; /*if (argCount() != 1 || argumentList.e.NodeSet == false) throw new System.ArgumentException("sum()'s argument count is invalid");*/ vn.push2(); try { a = 0; int i1; while ((a = argumentList.e.evalNodeSet(vn)) != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_STARTING_TAG) { i1 = vn.getText(); if (i1 != -1) d = d + vn.parseDouble(i1); if (System.Double.IsNaN(d)) break; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS) { d = d + vn.parseDouble(a + 1); if (System.Double.IsNaN(d)) break; } else if (t == VTDNav.TOKEN_CHARACTER_DATA || t == VTDNav.TOKEN_CDATA_VAL || t == VTDNav.TOKEN_COMMENT) { d = d + vn.parseDouble(a); if (System.Double.IsNaN(d)) break; } else if (t == VTDNav.TOKEN_PI_NAME) { if (a + 1 < vn.vtdSize && vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) { d += vn.parseDouble(a + 1); } else { d = Double.NaN; break; } } // fib1.append(i); } argumentList.e.reset(vn); vn.pop2(); return d; } catch (System.Exception e) { argumentList.e.reset(vn); vn.pop2(); return System.Double.NaN; } }
private int getStringVal(VTDNav vn, int i) { int i1, t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG) { i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t == VTDNav.TOKEN_PI_NAME) return i + 1; else return i; }
/// <summary> /// /// </summary> /// <param name="vn"></param> /// <returns></returns> protected int getStringIndex(VTDNav vn) { int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { a++; } else if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG) { a = vn.getText(); } else if (t == VTDNav.TOKEN_PI_NAME) { a++; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; }
public override double evalNumber(VTDNav vn) { int ac = 0; switch (opCode) { case FuncName.LAST: if (argCount() != 0) throw new System.ArgumentException("floor()'s argument count is invalid"); return contextSize; case FuncName.POSITION: if (argCount() != 0) throw new System.ArgumentException("position()'s argument count is invalid"); return position; case FuncName.COUNT: return count(vn); case FuncName.NUMBER: if (argCount() != 1) throw new System.ArgumentException("number()'s argument count is invalid"); return argumentList.e.evalNumber(vn); case FuncName.SUM: return sum(vn); case FuncName.FLOOR: if (argCount() != 1) throw new System.ArgumentException("floor()'s argument count is invalid"); return System.Math.Floor(argumentList.e.evalNumber(vn)); case FuncName.CEILING: if (argCount() != 1) throw new System.ArgumentException("ceiling()'s argument count is invalid"); return System.Math.Ceiling(argumentList.e.evalNumber(vn)); case FuncName.STRING_LENGTH: ac = argCount(); if (ac == 0) { try { if (vn.atTerminal == true) { int type = vn.getTokenType(vn.LN); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { return vn.getStringLength(vn.LN + 1); } else { return vn.getStringLength(vn.LN); } } else { int i = vn.getText(); if (i == - 1) return 0; else return vn.getStringLength(i); } } catch (NavException e) { return 0; } } else if (ac == 1) { return argumentList.e.evalString(vn).Length; } else { throw new System.ArgumentException("string-length()'s argument count is invalid"); } //goto case FuncName.ROUND; case FuncName.ROUND: if (argCount() != 1) throw new System.ArgumentException("round()'s argument count is invalid"); //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangMathround_double'" return (long) System.Math.Round(argumentList.e.evalNumber(vn)); default: if (isBoolean_Renamed_Field) { if (evalBoolean(vn)) return 1; else return 0; } else { return System.Double.Parse(evalString(vn)); } //break; } }
public override System.String evalString(VTDNav vn) { vn.push2(); int size = vn.contextStack2.size; int a = - 1; try { a = evalNodeSet(vn); if (a != - 1) { if (vn.getTokenType(a) == VTDNav.TOKEN_ATTR_NAME) { a++; } if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG) { a = vn.getText(); } } } catch (System.Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); try { if (a != - 1) return vn.toString(a); } catch (NavException e) { } return ""; }
public override double evalNumber(VTDNav vn) { //double d; int a = - 1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != - 1) { if (vn.getTokenType(a) == VTDNav.TOKEN_ATTR_NAME) { a++; } else if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG) { a = vn.getText(); } } } catch (System.Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); try { if (a != - 1) return vn.parseDouble(a); } catch (NavException e) { } return System.Double.NaN; }
private int getStringVal(VTDNav vn, int i) { int i1, t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG) { i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS) return i + 1; else /*if (t == VTDNav.TOKEN_CHARACTER_DATA || t == VTDNav.TOKEN_CDATA_VAL) return i;*/ return i; }