예제 #1
0
        public override string calculate(string input)
        {
            String        output = "";
            List <String> lines  = splitTextToLines(input);

            String oldStart  = variables[0].Trim();
            String oldLength = variables[1].Trim();
            String newStart  = variables[2].Trim();
            String newEnd    = variables[3].Trim();

            InnerReadNode innerReadValue = new InnerReadNode();

            innerReadValue.parseArgs(QUOTES);

            foreach (String line in lines)
            {
                if (line.Contains(oldStart) && line.Contains(oldLength))
                {
                    List <String> attributes = splitTextToAttributes(line);

                    String startAttribute  = getAttribute(attributes, oldStart);
                    String lengthAttribute = getAttribute(attributes, oldLength);

                    int startVal, endVal, lengthVal;

                    startVal  = int.Parse(innerReadValue.calculate(startAttribute).Trim());
                    lengthVal = int.Parse(innerReadValue.calculate(lengthAttribute).Trim());
                    endVal    = startVal + lengthVal;

                    String newStartReplace = newStart + "=\"" + startVal + "\"";
                    String newEndReplace   = newEnd + "=\"" + endVal + "\"";

                    String updatedLine = line.Replace(startAttribute, newStartReplace).Replace(lengthAttribute, newEndReplace);
                    output += updatedLine + Environment.NewLine;
                }
                else
                {
                    output += line + Environment.NewLine;
                }
            }

            return(output);
        }