protected override Parser.Result Evaluate(string data, ref int from) { // 1. Get the name of the variable. string varName = Utils.GetToken(data, ref from, Constants.NEXT_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't append variable"); } // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Parser.Result currentValue = func.GetValue(data, ref from); // 3. Get the value to be looked for. Parser.Result searchValue = Utils.GetItem(data, ref from); // 4. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string basePart = currentValue.String != null ? currentValue.String : currentValue.Value.ToString(); string search = searchValue.String != null ? searchValue.String : searchValue.Value.ToString(); int result = basePart.IndexOf(search); return(new Parser.Result(result, null)); }
protected override Parser.Result Evaluate(string data, ref int from) { // 1. Get the name of the variable. string varName = Utils.GetToken(data, ref from, Constants.END_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't get variable"); } // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Parser.Result currentValue = func.GetValue(data, ref from); // 3. Take either the length of the underlying tuple or // string part if it is defined, // or the numerical part converted to a string otherwise. int size = currentValue.Tuple != null ? currentValue.Tuple.Count : currentValue.String != null ? currentValue.String.Length : currentValue.Value.ToString().Length; Parser.Result newValue = new Parser.Result(size); return(newValue); }
protected override Parser.Result Evaluate(string data, ref int from) { // 1. Get the name of the variable. string varName = Utils.GetToken(data, ref from, Constants.NEXT_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't append variable"); } // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Parser.Result currentValue = func.GetValue(data, ref from); // 3. Get the value to be added or appended. Parser.Result newValue = Utils.GetItem(data, ref from); // 4. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string arg1 = currentValue.String != null ? currentValue.String : currentValue.Value.ToString(); string arg2 = newValue.String != null ? newValue.String : newValue.Value.ToString(); // 5. The variable becomes a string after adding a string to it. newValue.Reset(); newValue.String = arg1 + arg2; ParserFunction.AddFunction(varName, new GetVarFunction(newValue)); return(newValue); }
protected override Parser.Result Evaluate(string data, ref int from) { string substring; // 1. Get the name of the variable. string varName = Utils.GetToken(data, ref from, Constants.NEXT_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't get variable"); } // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Parser.Result currentValue = func.GetValue(data, ref from); // 3. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string arg = currentValue.String != null ? currentValue.String : currentValue.Value.ToString(); // 4. Get the initial index of the substring. bool lengthAvailable = Utils.SeparatorExists(data, from); Parser.Result init = Utils.GetItem(data, ref from, true /* expectInt */); // 5. Get the length of the substring if available. if (lengthAvailable) { Parser.Result length = Utils.GetItem(data, ref from, true /* expectInt */); 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); } Parser.Result newValue = new Parser.Result(Double.NaN, substring); return(newValue); }
protected override Parser.Result Evaluate(string data, ref int from) { string varName = Utils.GetToken(data, ref from, Constants.NEXT_ARG_ARRAY); if (from >= data.Length) { throw new ArgumentException("Couldn't set variable before end of line"); } Parser.Result varValue = Utils.GetItem(data, ref from); // Check if the variable to be set has the form of x(0), // meaning that this is an array element. int arrayIndex = Utils.ExtractArrayElement(ref varName); if (arrayIndex >= 0) { bool exists = ParserFunction.FunctionExists(varName); Parser.Result currentValue = exists ? ParserFunction.GetFunction(varName).GetValue(data, ref from) : new Parser.Result(); List <Parser.Result> tuple = currentValue.Tuple == null ? new List <Parser.Result>() : currentValue.Tuple; if (tuple.Count > arrayIndex) { tuple[arrayIndex] = varValue; } else { for (int i = tuple.Count; i < arrayIndex; i++) { tuple.Add(new Parser.Result(Double.NaN, string.Empty)); } tuple.Add(varValue); } varValue = new Parser.Result(Double.NaN, null, tuple); } ParserFunction.AddFunction(varName, new GetVarFunction(varValue)); return(new Parser.Result(Double.NaN, varName)); }
public void AddTranslation(NameValueCollection languageDictionary, string originalName) { string translation = languageDictionary[originalName]; if (string.IsNullOrWhiteSpace(translation)) { // The translation is not provided for this function. return; } if (translation.IndexOfAny((" \t\r\n").ToCharArray()) >= 0) { throw new ArgumentException("Translation of [" + translation + "] contains white spaces"); } ParserFunction originalFunction = ParserFunction.GetFunction(originalName); ParserFunction.AddFunction(translation, originalFunction); }