getStringLength() публичный Метод

getStringLength return the string length of a token as if the token is converted into a string (entity resolved)
public getStringLength ( int index ) : int
index int
Результат int
Пример #1
0
        private int getStringLen(VTDNav vn)
        {
            if (argCount1 == 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 k = vn.getCurrentIndex2();
                        // int type = vn.getTokenType(k);
                        return vn.XPathStringLength(k);
                    }
                }
                catch (NavException e)
                {
                    return 0;
                }
            }
            else if (argCount1 == 1)
            {
                int result = 0;
                if (argumentList.e.NodeSet)
                {
                    int a = 0x7fffffff, k = -1;
                    vn.push2();
                    int size = vn.contextStack2.size;
                    try
                    {
                        if (argumentList.e.needReordering)
                        {
                            argumentList.e.adjust(vn.getTokenCount());
                            while ((k = argumentList.e.evalNodeSet(vn)) != -1)
                            {
                                if (k < a)
                                    a = k; // a is always smaller
                            }
                            if (a == 0x7fffffff)
                            {
                                a = -1;
                            }
                        }
                        else
                        {
                            a = argumentList.e.evalNodeSet(vn);
                        }
                        if (a == -1)
                            result = 0;
                        else
                        {

                            int type = vn.getTokenType(a);
                            if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS || type == VTDNav.TOKEN_PI_NAME)
                            {
                                result = vn.getStringLength(a + 1);
                            }
                            else if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_DOCUMENT)
                            {
                                result = vn.XPathStringLength(a);
                            }
                            else
                            {
                                result = vn.getStringLength(a);
                            }
                        }
                    }
                    catch (VTDException e)
                    {

                    }
                    argumentList.e.reset(vn);
                    vn.contextStack2.size = size;
                    vn.pop2();
                    return result;
                }
                else
                    return argumentList.e.evalString(vn).Length;
            }
            else
            {
                throw new System.ArgumentException("string-length()'s argument count is invalid");
            }
        }
Пример #2
0
        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;

            }
        }
Пример #3
0
		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;
				
			}
		}