internal int AddParametricSegment(int segmentTextStart, PtcParameter parameter) { LineSegments.Add( new PtcLineSegment(parameter) ); //Return the location of the start of the next segment return(segmentTextStart + parameter.ParameterPlaceholderLength); }
/// <summary> /// Find the next occurance of a parameter placeholder inside the given line /// </summary> /// <param name="lineText"></param> /// <param name="startAt"></param> /// <param name="parameter"></param> /// <returns></returns> private int NextParameter(string lineText, int startAt, out PtcParameter parameter) { //Find the first occurance of a left delimiter starting from nextSegmentStart var leftDelIndex = lineText.IndexOf( LeftDelimiter, startAt, StringComparison.Ordinal ); while (true) { //No left delimiter is found. end search for parameter placeholder if (leftDelIndex < 0) { parameter = null; return(-1); } //Find first occurance of a right delimiter starting after the left delimiter that was found var rightDelIndex = lineText.IndexOf( RightDelimiter, leftDelIndex + LeftDelimiter.Length, StringComparison.Ordinal ); //A right delimiter is not found. End search for parameter placeholder if (rightDelIndex <= leftDelIndex) { parameter = null; return(-1); } //A right delimiter is found var startIndex = leftDelIndex + LeftDelimiter.Length; var endIndex = rightDelIndex - 1; var length = endIndex - startIndex + 1; //Read the text between the left and right delimiters var parameterName = lineText.Substring(startIndex, length); //If the text is not a legal parameter name try searching for a new left delimiter if (parameterName.All(c => c == '-' || c == '_' || char.IsLetterOrDigit(c)) == false) { leftDelIndex = lineText.IndexOf( LeftDelimiter, leftDelIndex + 1, StringComparison.Ordinal ); continue; } //If the parameter name is not defined add it with an empty string value if (_parameters.TryGetValue(parameterName, out parameter) == false) { parameter = new PtcParameter(this, parameterName); _parameters.Add(parameterName, parameter); } return(leftDelIndex); } }