public override string TransformRange(string stringToTransform, string commandContent, Dictionary <string, string> variables) { // Note that we require that the content be like 2,variableName or 3,4. // We don't allow the content to consist of other commands that can be reduced to that. var split = commandContent.Split(',').ToList(); string variableName = split[0]; int firstValueInclusive, secondValueExclusive; if (!int.TryParse(split[1], out firstValueInclusive)) { firstValueInclusive = Int32.Parse(variables[split[1]]); } if (!int.TryParse(split[2], out secondValueExclusive)) { secondValueExclusive = Int32.Parse(variables[split[2]]); } StringBuilder sb = new StringBuilder(); for (int i = firstValueInclusive; i < secondValueExclusive; i++) { variables[variableName] = i.ToString(); sb.Append(StringTemplate.Process(stringToTransform, variables)); } variables.Remove(variableName); return(sb.ToString()); }
public override string TransformRange(string stringToTransform, string commandContent, Dictionary <string, string> variables) { int numCyclesLeft = 0; if (commandContent != null && commandContent != "") { numCyclesLeft = Int32.Parse(commandContent); } // When there is exactly 1 cycle left, we unencode the command block. The result of this is that the contents will not be evaluated // until the last cycle. if (numCyclesLeft == 1) { stringToTransform = StringTemplate.EncodeCommandBlock(stringToTransform, unencode: true); } if (numCyclesLeft > 0) { return(StringTemplate.CreateReprocessBlock(stringToTransform, numCyclesLeft - 1)); // we are going to delay processing; this allows external variables to be set } return(StringTemplate.Process(stringToTransform, variables)); }