Пример #1
0
        private static List <string> Tratamento(int modo, List <string> inputLines, string mainRegex, string replacement = "", bool casoEspecial1 = false)
        {
            TextBuffer    _buffer       = new TextBuffer();
            StringBuilder output        = new StringBuilder();
            string        match         = string.Empty;
            int           matchsCounter = 0;
            bool          isMatch       = false;

            foreach (var line in inputLines)
            {
                isMatch = Regex.IsMatch(line, mainRegex);
                if (isMatch)
                {
                    matchsCounter++;
                    match = Regex.Match(line, mainRegex).ToString();
                    switch (modo)
                    {
                    case 1:
                        _buffer.AppendToHeader(match.Trim());                       // o match
                        _buffer.AppendToBody(line.Replace(match, "").Trim());       // o restante da linha sem o match
                        break;

                    case 2:
                        _buffer.AppendToHeader(replacement);                       // o match
                        _buffer.AppendToBody(line.Replace(match, "").Trim());      // o restante da linha sem o match
                        break;
                    }
                }
                else
                {
                    TrataCasoEspecial1(_buffer, matchsCounter, casoEspecial1);

                    if (matchsCounter > 0)         // quebrou sequência de MATCHS
                    {
                        _buffer.Flush(ref output); // escreve o buffer no arquivo saída
                        matchsCounter = 0;
                    }
                    output.AppendLine(line.ToString().Trim());
                }
            }
            inputLines = ConvertToLines(output);
            return(inputLines);
        }