/// <summary> /// Perform string parsing /// </summary> protected void Parse() { var stringParts = new List <string>(); var stringParams = new Dictionary <string, Param>(); // splitting a string into parts separated by brackets {and} if (!string.IsNullOrEmpty(SrcString)) { var ind = 0; int len = SrcString.Length; while (ind < len) { int braceInd1 = SrcString.IndexOf('{', ind); if (braceInd1 < 0) { stringParts.Add(SrcString.Substring(ind)); break; } else { int braceInd2 = SrcString.IndexOf('}', braceInd1 + 1); int paramNameLen = braceInd2 - braceInd1 - 1; if (paramNameLen <= 0) { stringParts.Add(SrcString.Substring(ind)); break; } else { string paramName = SrcString.Substring(braceInd1 + 1, paramNameLen); Param param; if (!stringParams.TryGetValue(paramName, out param)) { param = new Param(paramName); stringParams.Add(paramName, param); } stringParts.Add(SrcString.Substring(ind, braceInd1 - ind)); param.PartIndexes.Add(stringParts.Count); stringParts.Add(""); ind = braceInd2 + 1; } } } } StringParts = stringParts.ToArray(); Params = stringParams; }
/// <summary> /// Выполнить разбор строки /// </summary> protected void Parse() { List <string> stringParts = new List <string>(); Dictionary <string, Param> stringParams = new Dictionary <string, Param>(); // разбиение строки на части, разделяемые скобками { и } if (!string.IsNullOrEmpty(SrcString)) { int ind = 0; int len = SrcString.Length; while (ind < len) { int braceInd1 = SrcString.IndexOf('{', ind); if (braceInd1 < 0) { stringParts.Add(SrcString.Substring(ind)); break; } else { int braceInd2 = SrcString.IndexOf('}', braceInd1 + 1); int paramNameLen = braceInd2 - braceInd1 - 1; if (paramNameLen <= 0) { stringParts.Add(SrcString.Substring(ind)); break; } else { string paramName = SrcString.Substring(braceInd1 + 1, paramNameLen); Param param; if (!stringParams.TryGetValue(paramName, out param)) { param = new Param(paramName); stringParams.Add(paramName, param); } stringParts.Add(SrcString.Substring(ind, braceInd1 - ind)); param.PartIndexes.Add(stringParts.Count); stringParts.Add(""); ind = braceInd2 + 1; } } } } StringParts = stringParts.ToArray(); Params = stringParams; }