/// <summary> /// Helper: Builds table with rows delimited by symbol # /// </summary> /// <param name="lines"></param> /// <param name="index"></param> /// <param name="curObj"></param> /// <param name="keywordsList"></param> /// <returns></returns> private int BuildTable(string[] lines, int index, out string tableLine) { tableLine = ""; // start build table from the next string after Table keyword for (int k = index + 1; k < lines.Length; k++) { if (string.IsNullOrEmpty(lines[k])) { continue; } if (KeywordsList.Any(s => lines[k].StartsWith(s))) { return(k - 1); } // if next line is not the end if (k + 1 < lines.Length) { // if next line is new keyword, then end table and exit if (KeywordsList.Any(s => lines[k + 1].Contains(s))) { // add current row to the table tableLine += "#" + lines[k]; return(k); } // for the case if this lines contains line for last roll result if (k + 2 < lines.Length && lines[k + 2].StartsWith(KeywordsList.First())) { if (char.IsDigit(lines[k][0])) { tableLine += "#" + lines[k]; } else { tableLine += " " + lines[k]; } return(k); } } else { // if it was the last line than end tableLine += "#" + lines[k]; return(k); } if (char.IsDigit(lines[k][0])) { tableLine += "#" + lines[k]; } else { tableLine += " " + lines[k]; } } return(-1); }
/// <summary> /// Creates single cypher or artefact /// </summary> /// <param name="lines"></param> /// <param name="currentIndex"></param> /// <param name="curObj"></param> /// <returns></returns> private int BuildCurrentDevice(string[] lines, int currentIndex, out Dictionary <string, string> curObj) { curObj = new Dictionary <string, string>(); curObj.Add(NameKeyword, UppercaseFirstLetters(lines[currentIndex])); // read current object body starting from the next string var currentKeyword = ""; int j; string tableKeyword = KeywordsList.FirstOrDefault(x => x.StartsWith("#")); bool isThereTable = string.IsNullOrEmpty(tableKeyword) ? false : true; for (j = currentIndex + 1; j < lines.Length; j++) { if (string.IsNullOrEmpty(lines[j])) { continue; } // either end of the array or start of the new object if (j + 1 != lines.Length && lines[j + 1].StartsWith(KeywordsList.First())) { return(j - 1); } // check line for Keyword and add new line foreach (var keyword in KeywordsList) { if (keyword == tableKeyword && lines[j].StartsWith(keyword.Substring(1))) { currentKeyword = keyword; break; } if (lines[j].StartsWith(keyword)) { currentKeyword = keyword; break; } } if (currentKeyword == "") { curObj[NameKeyword] += " " + lines[j]; continue; } if (currentKeyword == tableKeyword) { curObj.Add(currentKeyword, ""); j = BuildTable(lines, j, out var tableLine); curObj[currentKeyword] = tableLine; continue; } if (curObj.ContainsKey(currentKeyword)) { curObj[currentKeyword] += " " + lines[j]; } else { var startOfDescription = lines[j].Substring(currentKeyword.Length); curObj.Add(currentKeyword, startOfDescription); } } return(j); }