private int parseTextListDefinition(CIniFile config, string[] separators, string[] lines, List <string> separeted_string, int startLineIdx) { string[] multitext_line = null, line_with_id = null; string multitext_name = null, line_without_id = null; List <string[]> multitext_lines = new List <string[]>(); List <int> Idxs = new List <int>(); int position; int id; multitext_name = separeted_string[1]; for (int i = startLineIdx + 1; i < lines.Length; i++) { if (lines[i].Length == 0) { TextlistDefinition.Add(config, multitext_name, multitext_lines, Idxs); return(i); } else { line_with_id = lines[i].Split(separators, StringSplitOptions.RemoveEmptyEntries); if (int.TryParse(line_with_id[0], out id) == true) { Idxs.Add(id); position = lines[i].IndexOf(';'); line_without_id = lines[i].Substring(position + 1); // Because of spliting this string. Before semicolon is first index multitext_line = line_without_id.Split(Const.separ_semicolon, StringSplitOptions.RemoveEmptyEntries); multitext_lines.Add(multitext_line); } } } return(0); }
/// <summary> /// New method to parse multitext /// </summary> /// <param name="config"></param> /// <returns></returns> private int parseMultitext(CIniFile config, List <string> lines, int startLineIdx, string name) { List <string[]> multitext_lines = new List <string[]>(); List <int> Indexes = new List <int>(); for (int i = startLineIdx; i < lines.Count; i++) { List <string> multitextLine = new List <string>(); int id = 0; if (lines[i].Length == 0) { TextlistDefinition.Add(config, name, multitext_lines, Indexes); return(i); } else { multitextLine = lines[i].Split(Const.separ_semicolon, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList(); if (int.TryParse(multitextLine[0], out id) == true) { Indexes.Add(id); // 0 index multitextLine = multitextLine.Skip(1).ToList(); multitext_lines.Add(multitextLine.ToArray()); } } } string error = "Multitext Definition doesn't ended!"; Exception e = new Exception(error); string k = e.Message.ToString() + e.Source.ToString() + e.StackTrace.ToString() + error; string controllerName = this.GetType().Name.ToString(); Error.toFile(k, controllerName); return(0); }
/// <summary> /// method to parse multitext defined in only one line /// </summary> /// <param name="config">config structure</param> /// <param name="tableName">name of table</param> /// <param name="column">name of column in db</param> /// <param name="line">a line in names</param> /// <param name="names">names which will contains name in all langs</param> private static void parseMultitextInLine(CIniFile config, string tableName, string column, string line, string[] names) { string[] Tmp = line.Split(Const.separ_equate, StringSplitOptions.RemoveEmptyEntries); string Variable = Tmp[0]; // not used string DefBody = Tmp[1]; string[] langs = DefBody.Split(Const.separ_dollar, StringSplitOptions.RemoveEmptyEntries); langs = langs.Where(p => p.Length > 2).ToArray(); int LangCnt = langs.Length; string[][] items = new string[LangCnt][]; for (int j = 0; j < LangCnt; j++) { string[] Tmp2 = langs[j].Split(Const.separ_names, StringSplitOptions.RemoveEmptyEntries); names[j] = Tmp2[0]; string itemList = Tmp2[1]; items[j] = itemList.Split(Const.separ_backslashNew, StringSplitOptions.RemoveEmptyEntries); } // pricny pruchod List <string[]> values = new List <string[]>(); //For the ending state of values List <int> Idxs = new List <int>(); //Initial defintion int itemCnt = items[0].Length; // bacha, spoleha se, ze jsou vsechna pole stejne dlouha - patri se monzna Minimum delek for (int x = 0; x < itemCnt; x++) { string[] tmpPole = new string[LangCnt]; for (int L = 0; L < LangCnt; L++) { tmpPole[L] = items[L][x]; // transpozice matice } Idxs.Add(x); values.Add(tmpPole); } for (int i = 0; i < names.Length; i++) { if (names[i].Contains(@"\")) { names[i] = names[i].Replace(@"\", "-"); } } TextlistDefinition.Add(config, column, values, Idxs); //name is not present so add name as tablename List <string> units = null; //yes add only null NameDefinition.Add(config, column, names, units, tableName); //Adds name to names }
private static void parseMultitextInLine2(CIniFile config, string tableName, string column, string line, string[] names) { List <string[]> values = new List <string[]>(); //For the ending state of values List <int> Idxs = new List <int>(); //Initial defintion string[] langs = line.Split(Const.separ_dollar, StringSplitOptions.RemoveEmptyEntries); string[][] vals = vals = new string[langs.Length][]; for (int j = 0; j < langs.Length; j++) { int equalPos = langs[j].LastIndexOf(@"="); int semicolonPos = langs[j].IndexOf(@";"); if (equalPos != -1) { names[j] = langs[j].Substring(equalPos + 1, (semicolonPos - equalPos)); langs[j] = langs[j].Substring(equalPos + 1); } else { names[j] = langs[j].Substring(0, (semicolonPos)); langs[j] = langs[j].Substring(semicolonPos + 1); } string[] prevals = langs[j].Split(Const.separ_backslashNew, StringSplitOptions.RemoveEmptyEntries); int index = 0; for (int k = 0; k < prevals.Length; k++) { //vals[j][index] = new string[]; vals[j][index] = prevals[index]; index++; } } for (int k = 0; k < vals.Length; k++) { Idxs.Add(k); values.Add(vals[k]); } TextlistDefinition.Add(config, tableName, values, Idxs); //name is not present so add name as tablename List <string> units = null; //yes add only null NameDefinition.Add(config, column, names, units, tableName); //Adds name to names }
private void multitextInline(CIniFile config, string tableName, string nameLineSecondPart) { List <string[]> textListValues = new List <string[]>(); List <int> Idxs = new List <int>(); string[] separatedFromDollars = nameLineSecondPart.Split(Const.separ_dollar, StringSplitOptions.RemoveEmptyEntries); string[] langs = new string[separatedFromDollars.Length]; string[] valsForLength = separatedFromDollars[0].Split(Const.separ_backslash, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < valsForLength.Length; i++) { for (int j = 0; j < separatedFromDollars.Length; j++) { string[] values = separatedFromDollars[j].Split(Const.separ_backslash, StringSplitOptions.RemoveEmptyEntries); langs[j] = values[i]; } textListValues.Add(langs); Idxs.Add(i - 1); TextlistDefinition.Add(config, tableName, textListValues, Idxs); } }