private string[] ParseDelimitedLine()
 {
     string line = this.ReadNextDataLine();
     if (line == null)
     {
         return null;
     }
     long lineNumber = this.m_LineNumber - 1L;
     int startat = 0;
     List<string> list = new List<string>();
     int endOfLineIndex = this.GetEndOfLineIndex(line);
     while (startat <= endOfLineIndex)
     {
         string field;
         Match match = null;
         bool success = false;
         if (this.m_HasFieldsEnclosedInQuotes)
         {
             match = this.BeginQuotesRegex.Match(line, startat);
             success = match.Success;
         }
         if (success)
         {
             startat = match.Index + match.Length;
             QuoteDelimitedFieldBuilder builder = new QuoteDelimitedFieldBuilder(this.m_DelimiterWithEndCharsRegex, this.m_SpaceChars);
             builder.BuildField(line, startat);
             if (builder.MalformedLine)
             {
                 this.m_ErrorLine = line.TrimEnd(new char[] { '\r', '\n' });
                 this.m_ErrorLineNumber = lineNumber;
                 throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MalFormedDelimitedLine", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
             }
             if (builder.FieldFinished)
             {
                 field = builder.Field;
                 startat = builder.Index + builder.DelimiterLength;
             }
             else
             {
                 do
                 {
                     int length = line.Length;
                     string str3 = this.ReadNextDataLine();
                     if (str3 == null)
                     {
                         this.m_ErrorLine = line.TrimEnd(new char[] { '\r', '\n' });
                         this.m_ErrorLineNumber = lineNumber;
                         throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MalFormedDelimitedLine", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                     }
                     if ((line.Length + str3.Length) > this.m_MaxLineSize)
                     {
                         this.m_ErrorLine = line.TrimEnd(new char[] { '\r', '\n' });
                         this.m_ErrorLineNumber = lineNumber;
                         throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MaxLineSizeExceeded", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                     }
                     line = line + str3;
                     endOfLineIndex = this.GetEndOfLineIndex(line);
                     builder.BuildField(line, length);
                     if (builder.MalformedLine)
                     {
                         this.m_ErrorLine = line.TrimEnd(new char[] { '\r', '\n' });
                         this.m_ErrorLineNumber = lineNumber;
                         throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MalFormedDelimitedLine", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                     }
                 }
                 while (!builder.FieldFinished);
                 field = builder.Field;
                 startat = builder.Index + builder.DelimiterLength;
             }
             if (this.m_TrimWhiteSpace)
             {
                 field = field.Trim();
             }
             list.Add(field);
         }
         else
         {
             Match match2 = this.m_DelimiterRegex.Match(line, startat);
             if (match2.Success)
             {
                 field = line.Substring(startat, match2.Index - startat);
                 if (this.m_TrimWhiteSpace)
                 {
                     field = field.Trim();
                 }
                 list.Add(field);
                 startat = match2.Index + match2.Length;
             }
             else
             {
                 field = line.Substring(startat).TrimEnd(new char[] { '\r', '\n' });
                 if (this.m_TrimWhiteSpace)
                 {
                     field = field.Trim();
                 }
                 list.Add(field);
                 break;
             }
         }
     }
     return list.ToArray();
 }
Example #2
0
        private string[] ParseDelimitedLine()
        {
            string line = this.ReadNextDataLine();

            if (line == null)
            {
                return(null);
            }
            long          lineNumber     = this.m_LineNumber - 1L;
            int           startat        = 0;
            List <string> list           = new List <string>();
            int           endOfLineIndex = this.GetEndOfLineIndex(line);

            while (startat <= endOfLineIndex)
            {
                string field;
                Match  match   = null;
                bool   success = false;
                if (this.m_HasFieldsEnclosedInQuotes)
                {
                    match   = this.BeginQuotesRegex.Match(line, startat);
                    success = match.Success;
                }
                if (success)
                {
                    startat = match.Index + match.Length;
                    QuoteDelimitedFieldBuilder builder = new QuoteDelimitedFieldBuilder(this.m_DelimiterWithEndCharsRegex, this.m_SpaceChars);
                    builder.BuildField(line, startat);
                    if (builder.MalformedLine)
                    {
                        this.m_ErrorLine       = line.TrimEnd(new char[] { '\r', '\n' });
                        this.m_ErrorLineNumber = lineNumber;
                        throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MalFormedDelimitedLine", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                    }
                    if (builder.FieldFinished)
                    {
                        field   = builder.Field;
                        startat = builder.Index + builder.DelimiterLength;
                    }
                    else
                    {
                        do
                        {
                            int    length = line.Length;
                            string str3   = this.ReadNextDataLine();
                            if (str3 == null)
                            {
                                this.m_ErrorLine       = line.TrimEnd(new char[] { '\r', '\n' });
                                this.m_ErrorLineNumber = lineNumber;
                                throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MalFormedDelimitedLine", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                            }
                            if ((line.Length + str3.Length) > this.m_MaxLineSize)
                            {
                                this.m_ErrorLine       = line.TrimEnd(new char[] { '\r', '\n' });
                                this.m_ErrorLineNumber = lineNumber;
                                throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MaxLineSizeExceeded", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                            }
                            line           = line + str3;
                            endOfLineIndex = this.GetEndOfLineIndex(line);
                            builder.BuildField(line, length);
                            if (builder.MalformedLine)
                            {
                                this.m_ErrorLine       = line.TrimEnd(new char[] { '\r', '\n' });
                                this.m_ErrorLineNumber = lineNumber;
                                throw new MalformedLineException(Utils.GetResourceString("TextFieldParser_MalFormedDelimitedLine", new string[] { lineNumber.ToString(CultureInfo.InvariantCulture) }), lineNumber);
                            }
                        }while (!builder.FieldFinished);
                        field   = builder.Field;
                        startat = builder.Index + builder.DelimiterLength;
                    }
                    if (this.m_TrimWhiteSpace)
                    {
                        field = field.Trim();
                    }
                    list.Add(field);
                }
                else
                {
                    Match match2 = this.m_DelimiterRegex.Match(line, startat);
                    if (match2.Success)
                    {
                        field = line.Substring(startat, match2.Index - startat);
                        if (this.m_TrimWhiteSpace)
                        {
                            field = field.Trim();
                        }
                        list.Add(field);
                        startat = match2.Index + match2.Length;
                    }
                    else
                    {
                        field = line.Substring(startat).TrimEnd(new char[] { '\r', '\n' });
                        if (this.m_TrimWhiteSpace)
                        {
                            field = field.Trim();
                        }
                        list.Add(field);
                        break;
                    }
                }
            }
            return(list.ToArray());
        }