Exemplo n.º 1
0
        private void Parse(string regex, bool includeComments, bool useDebug)
        {
            var splits = regex.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (splits.Count() == 1)
            {
                Regex = splits.First();
                return;
            }

            Groups = (from item in splits.Take(splits.Count() - 1)
                      where !item.StartsWith("##")
                      let keyValueSplit = item.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)
                                          let key = keyValueSplit.First().Trim()
                                                    let value = keyValueSplit.Last().Trim()
                                                                where !String.IsNullOrEmpty(key)
                                                                where !String.IsNullOrEmpty(value)
                                                                let regexWithoutComments = includeComments ? value.Split(new[] { "##" }, 2, StringSplitOptions.RemoveEmptyEntries).First().Trim() : value
                                                                                           select new TreeData {
                Key = key, Value = regexWithoutComments
            }).ToList();

            Final = splits.Last().Trim();

            Regex = Final;

            for (int i = Groups.Count - 1; i >= 0; i--)
            {
                var item = Groups[i];
                Regex = Regex.Replace(item.Key, item.Value);
                if (useDebug)
                {
                    DebugTrace.Add(Regex);
                }
            }
        }