コード例 #1
0
ファイル: CsvHelper.cs プロジェクト: ITAGroup/SpecAid
        private static string ConsumeNoQuoted(CsvSplitInfo info, char starter, StringEnumWithPeek readMe)
        {
            info.FieldExpected = false;

            var sb = new StringBuilder();
            sb.Append(starter);

            while (readMe.MoveNext())
            {
                // null not possible with inside a MoveNext loop
                var item = readMe.Current.Value;
                if (item == ',')
                {
                    info.FieldExpected = true;

                    // Remove ending spaces on No Quoted Fields
                    return sb.ToString().Trim();
                }

                sb.Append(item);
            }

            // Remove ending spaces on No Quoted Fields
            return sb.ToString().Trim();
        }
コード例 #2
0
ファイル: CsvHelper.cs プロジェクト: programatt/SpecAid
        private static string ConsumeNoQuoted(CsvSplitInfo info, char starter, StringEnumWithPeek readMe)
        {
            info.FieldExpected = false;

            var sb = new StringBuilder();

            sb.Append(starter);

            while (readMe.MoveNext())
            {
                // null not possible with inside a MoveNext loop
                var item = readMe.Current.Value;
                if (item == ',')
                {
                    info.FieldExpected = true;

                    // Remove ending spaces on No Quoted Fields
                    return(sb.ToString().Trim());
                }

                sb.Append(item);
            }

            // Remove ending spaces on No Quoted Fields
            return(sb.ToString().Trim());
        }
コード例 #3
0
ファイル: CsvHelper.cs プロジェクト: programatt/SpecAid
        private static string ComsumeQuoted(CsvSplitInfo info, StringEnumWithPeek readMe)
        {
            info.FieldExpected = false;

            var sb = new StringBuilder();

            sb.Append('"');

            while (readMe.MoveNext())
            {
                // null not possible with inside a MoveNext loop
                var item = readMe.Current.Value;
                if (item == '"')
                {
                    var nextItem = readMe.PeekNext();
                    if (nextItem == '"')
                    {
                        sb.Append('"');
                        readMe.MoveNext();
                        continue;
                    }
                    sb.Append('"');

                    return(sb.ToString());
                }

                sb.Append(item);
            }

            sb.Append('"');

            return(sb.ToString());
        }
コード例 #4
0
ファイル: CsvHelper.cs プロジェクト: programatt/SpecAid
 private static void GoToNextItem(CsvSplitInfo info, StringEnumWithPeek readMe)
 {
     while (readMe.MoveNext())
     {
         // null not possible with inside a MoveNext loop
         var item = readMe.Current.Value;
         if (item == ',')
         {
             info.FieldExpected = true;
             return;
         }
     }
 }
コード例 #5
0
ファイル: CsvHelper.cs プロジェクト: programatt/SpecAid
        public static List <string> Split(string text)
        {
            var result = new List <string>();

            var readMe = new StringEnumWithPeek(text);

            var info = new CsvSplitInfo();

            info.FieldExpected = false;

            while (readMe.MoveNext())
            {
                // null not possible with inside a MoveNext loop
                var item = readMe.Current.Value;

                if (item == ' ')
                {
                    continue;
                }

                if (item == ',')
                {
                    result.Add(string.Empty);
                    info.FieldExpected = true;
                    continue;
                }

                if (item == '"')
                {
                    var quotedItem = ComsumeQuoted(info, readMe);
                    result.Add(quotedItem);
                    GoToNextItem(info, readMe);
                    continue;
                }

                var unquotedItem = ConsumeNoQuoted(info, item, readMe);
                result.Add(unquotedItem);
            }

            // ending comma situation
            if (info.FieldExpected)
            {
                result.Add(string.Empty);
            }

            return(result);
        }
コード例 #6
0
ファイル: CsvHelper.cs プロジェクト: ITAGroup/SpecAid
        public static List<string> Split(string text)
        {
            var result = new List<string>();

            var readMe = new StringEnumWithPeek(text);

            var info = new CsvSplitInfo();
            info.FieldExpected = false;

            while (readMe.MoveNext())
            {
                // null not possible with inside a MoveNext loop
                var item = readMe.Current.Value;

                if (item == ' ')
                    continue;

                if (item == ',')
                {
                    result.Add(string.Empty);
                    info.FieldExpected = true;
                    continue;
                }

                if (item == '"')
                {
                    var quotedItem = ComsumeQuoted(info,readMe);
                    result.Add(quotedItem);
                    GoToNextItem(info, readMe);
                    continue;
                }

                var unquotedItem = ConsumeNoQuoted(info, item, readMe);
                result.Add(unquotedItem);
            }

            // ending comma situation
            if (info.FieldExpected)
                result.Add(string.Empty);

            return result;
        }
コード例 #7
0
ファイル: CsvHelper.cs プロジェクト: ITAGroup/SpecAid
 private static void GoToNextItem(CsvSplitInfo info, StringEnumWithPeek readMe)
 {
     while (readMe.MoveNext())
     {
         // null not possible with inside a MoveNext loop
         var item = readMe.Current.Value;
         if (item == ',')
         {
             info.FieldExpected = true;
             return;
         }
     }
 }
コード例 #8
0
ファイル: CsvHelper.cs プロジェクト: ITAGroup/SpecAid
        private static string ComsumeQuoted(CsvSplitInfo info, StringEnumWithPeek readMe)
        {
            info.FieldExpected = false;

            var sb = new StringBuilder();
            sb.Append('"');

            while (readMe.MoveNext())
            {
                // null not possible with inside a MoveNext loop
                var item = readMe.Current.Value;
                if (item == '"')
                {
                    var nextItem = readMe.PeekNext();
                    if (nextItem == '"')
                    {
                        sb.Append('"');
                        readMe.MoveNext();
                        continue;
                    }
                    sb.Append('"');

                    return sb.ToString();
                }

                sb.Append(item);
            }

            sb.Append('"');

            return sb.ToString();
        }