Esempio n. 1
0
        private string ParseQuotedText(out bool success)
        {
            int           errorCount     = Errors.Count;
            StringBuilder text           = new StringBuilder();
            int           start_position = position;

            MatchTerminal('"', out success);
            if (!success)
            {
                Error("Failed to parse '\\\"' of QuotedText.");
                position = start_position;
                return(text.ToString());
            }

            while (true)
            {
                ErrorStatck.Push(errorCount); errorCount = Errors.Count;
                while (true)
                {
                    char ch_1 = MatchTerminalSet("\"\r\n\\", true, out success);
                    if (success)
                    {
                        ClearError(errorCount);
                        text.Append(ch_1);
                        break;
                    }

                    ch_1 = ParseEscapeSequence(out success);
                    if (success)
                    {
                        ClearError(errorCount);
                        text.Append(ch_1);
                        break;
                    }

                    break;
                }
                errorCount = ErrorStatck.Pop();
                if (!success)
                {
                    break;
                }
            }
            success = true;

            MatchTerminal('"', out success);
            if (!success)
            {
                Error("Failed to parse '\\\"' of QuotedText.");
                position = start_position;
            }

            if (success)
            {
                ClearError(errorCount);
            }
            return(text.ToString());
        }
Esempio n. 2
0
        private string ParseField(out bool success)
        {
            int    errorCount     = Errors.Count;
            string str            = null;
            int    start_position = position;

            ParseSpacing(out success);

            ErrorStatck.Push(errorCount); errorCount = Errors.Count;
            while (true)
            {
                str = ParseQuotedText(out success);
                if (success)
                {
                    ClearError(errorCount); break;
                }

                str = ParseUnQuotedText(out success);
                if (success)
                {
                    ClearError(errorCount); break;
                }

                break;
            }
            errorCount = ErrorStatck.Pop();
            if (!success)
            {
                Error("Failed to parse (QuotedText / UnQuotedText) of Field.");
                position = start_position;
            }

            if (success)
            {
                ClearError(errorCount);
            }
            return(str);
        }
Esempio n. 3
0
        private CsvRecord ParseCsvRecord(out bool success)
        {
            int       errorCount     = Errors.Count;
            CsvRecord csvRecord      = new CsvRecord();
            int       start_position = position;

            int not_start_position1 = position;

            ParseEndOfFile(out success);
            position = not_start_position1;
            success  = !success;
            if (!success)
            {
                Error("Failed to parse !(EndOfFile) of CsvRecord.");
                position = start_position;
                return(csvRecord);
            }

            while (true)
            {
                int    seq_start_position2 = position;
                string str_1 = ParseField(out success);
                if (success)
                {
                    csvRecord.Fields.Add(str_1);
                }
                else
                {
                    Error("Failed to parse Field of CsvRecord.");
                    break;
                }

                while (true)
                {
                    while (true)
                    {
                        int seq_start_position3 = position;
                        ParseSeparator(out success);
                        if (!success)
                        {
                            Error("Failed to parse Separator of CsvRecord.");
                            break;
                        }

                        str_1 = ParseField(out success);
                        if (success)
                        {
                            csvRecord.Fields.Add(str_1);
                        }
                        else
                        {
                            Error("Failed to parse Field of CsvRecord.");
                            position = seq_start_position3;
                        }
                        break;
                    }
                    if (!success)
                    {
                        break;
                    }
                }
                success = true;
                break;
            }
            if (!success)
            {
                Error("Failed to parse Fields of CsvRecord.");
                position = start_position;
                return(csvRecord);
            }

            ErrorStatck.Push(errorCount); errorCount = Errors.Count;
            while (true)
            {
                ParseEnfOfLine(out success);
                if (success)
                {
                    ClearError(errorCount); break;
                }

                ParseEndOfFile(out success);
                if (success)
                {
                    ClearError(errorCount); break;
                }

                break;
            }
            errorCount = ErrorStatck.Pop();
            if (!success)
            {
                Error("Failed to parse (EnfOfLine / EndOfFile) of CsvRecord.");
                position = start_position;
            }

            if (success)
            {
                ClearError(errorCount);
            }
            return(csvRecord);
        }