Esempio n. 1
0
        protected override Variable Evaluate(ParsingScript script)
        {
            // 1. Get the name of the variable.
            string varName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY);

            Utils.CheckNotEnd(script, m_name);

            // 2. Get the current value of the variable.
            ParserFunction func = ParserFunction.GetFunction(varName);

            Utils.CheckNotNull(varName, func);
            Variable currentValue = func.GetValue(script);

            Utils.CheckArray(currentValue, varName);

            // 3. Get the variable to remove.
            Variable item = Utils.GetItem(script);

            Utils.CheckNonNegativeInt(item);

            currentValue.Tuple.RemoveAt(item.AsInt());

            ParserFunction.AddGlobalOrLocalVariable(varName,
                                                    new GetVarFunction(currentValue));
            return(Variable.EmptyInstance);
        }
Esempio n. 2
0
        public int GetArrayIndex(Variable indexVar)
        {
            if (this.Type != VarType.ARRAY)
            {
                return(-1);
            }

            if (indexVar.Type == VarType.NUMBER)
            {
                Utils.CheckNonNegativeInt(indexVar);
                return((int)indexVar.Value);
            }

            string hash = indexVar.AsString();
            int    ptr  = m_tuple.Count;

            if (m_dictionary.TryGetValue(hash, out ptr) &&
                ptr < m_tuple.Count)
            {
                return(ptr);
            }

            int result = -1;

            if (!String.IsNullOrWhiteSpace(indexVar.String) &&
                Int32.TryParse(indexVar.String, out result))
            {
                return(result);
            }

            return(-1);
        }
Esempio n. 3
0
        protected override Variable Evaluate(ParsingScript script)
        {
            string substring;

            // 1. Get the name of the variable.
            string varName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY);

            Utils.CheckNotEmpty(script, varName, m_name);

            // 2. Get the current value of the variable.
            ParserFunction func         = ParserFunction.GetFunction(varName);
            Variable       currentValue = func.GetValue(script);

            // 3. Take either the string part if it is defined,
            // or the numerical part converted to a string otherwise.
            string arg = currentValue.AsString();
            // 4. Get the initial index of the substring.
            Variable init = Utils.GetItem(script);

            Utils.CheckNonNegativeInt(init);

            // 5. Get the length of the substring if available.
            bool lengthAvailable = Utils.SeparatorExists(script);

            if (lengthAvailable)
            {
                Variable length = Utils.GetItem(script);
                Utils.CheckPosInt(length);
                if (init.Value + length.Value > arg.Length)
                {
                    throw new ArgumentException("The total substring length is larger than [" +
                                                arg + "]");
                }
                substring = arg.Substring((int)init.Value, (int)length.Value);
            }
            else
            {
                substring = arg.Substring((int)init.Value);
            }
            Variable newValue = new Variable(substring);

            return(newValue);
        }
Esempio n. 4
0
        public int GetArrayIndex(Variable indexVar)
        {
            if (this.Type != VarType.ARRAY)
            {
                return(-1);
            }

            if (indexVar.Type == VarType.NUMBER)
            {
                Utils.CheckNonNegativeInt(indexVar);
                return((int)indexVar.Value);
            }

            string hash = indexVar.AsString();
            int    ptr  = m_tuple.Count;

            if (m_dictionary.TryGetValue(hash, out ptr) &&
                ptr < m_tuple.Count)
            {
                return(ptr);
            }

            return(-1);
        }