コード例 #1
0
 internal void NextRow(ref ReaderStep step)
 {
     ++Row;
     Col   = 0;
     Start = End + 1;
     step  = ReaderStep.Start;
 }
コード例 #2
0
        /// <summary>
        /// 枚举内容
        /// </summary>
        /// <returns></returns>
        public IEnumerable <ReaderItem> Read()
        {
            if (!string.IsNullOrEmpty(content))
            {
                ReaderItem item = new ReaderItem {
                    Reader = this
                };
                int        index = 0;
                ReaderStep step  = ReaderStep.Start;
                foreach (char code in content)
                {
                    switch (step)
                    {
                    case ReaderStep.Start:
                        if (code == colSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextCol(ref step);
                        }
                        else if (code == rowSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextRow(ref step);
                        }
                        else if (code == rowIgnoreSplit)
                        {
                            step = ReaderStep.RowIgnore;
                        }
                        else if (code == escape)
                        {
                            step = ReaderStep.Escape;
                        }
                        else
                        {
                            step = ReaderStep.Next;
                        }
                        break;

                    case ReaderStep.Next:
                        if (code == colSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextCol(ref step);
                        }
                        else if (code == rowSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextRow(ref step);
                        }
                        else if (code == rowIgnoreSplit)
                        {
                            step = ReaderStep.RowIgnore;
                        }
                        break;

                    case ReaderStep.RowIgnore:
                        if (code == colSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextCol(ref step);
                        }
                        else if (code == rowSplit)
                        {
                            item.End = index - 1;
                            yield return(item);

                            item.NextIgnoreRow(ref step);
                        }
                        else
                        {
                            step = ReaderStep.Next;
                        }
                        break;

                    case ReaderStep.Escape:
                        if (code == escape)
                        {
                            step = ReaderStep.NextEscape;
                        }
                        break;

                    case ReaderStep.NextEscape:
                        if (code == colSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextCol(ref step);
                        }
                        else if (code == rowSplit)
                        {
                            item.End = index;
                            yield return(item);

                            item.NextRow(ref step);
                        }
                        else if (code == escape)
                        {
                            step = ReaderStep.Escape;
                        }
                        else if (code == rowIgnoreSplit)
                        {
                            step = ReaderStep.EscapeRowIgnore;
                        }
                        else
                        {
                            item.Error(index);
                            goto RETURN;
                        }
                        break;

                    case ReaderStep.EscapeRowIgnore:
                        if (code == rowSplit)
                        {
                            item.End = index - 1;
                            yield return(item);

                            item.NextIgnoreRow(ref step);
                        }
                        else
                        {
                            item.Error(index);
                            goto RETURN;
                        }
                        break;
                    }
                    ++index;
                }
                item.End = index;
RETURN:
                yield return(item);
            }
        }
コード例 #3
0
 internal void NextCol(ref ReaderStep step)
 {
     ++Col;
     Start = End + 1;
     step  = ReaderStep.Start;
 }