Esempio n. 1
0
 internal void SetEnd(ref ReaderItem item)
 {
     if (item.Row == Row)
     {
         end = item.End;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 获取字符串
 /// </summary>
 /// <param name="item"></param>
 /// <param name="ignorePrefix">忽略前缀</param>
 /// <returns></returns>
 internal string GetString(ref ReaderItem item, char ignorePrefix)
 {
     if (content[item.Start] == ignorePrefix)
     {
         return(item.Length != 1 ? content.Substring(item.Start + 1, item.Length - 1) : string.Empty);
     }
     return(content.Substring(item.Start, item.Length));
 }
Esempio n. 3
0
 /// <summary>
 /// CSV 解析数据对象
 /// </summary>
 /// <param name="index"></param>
 /// <param name="item"></param>
 internal ObjectReader(Index index, ref ReaderItem item)
 {
     Index       = index;
     this.reader = item.Reader;
     start       = item.Start;
     end         = item.End;
     Row         = item.Row;
     ValueArray  = new string[Index.ColCount];
 }
Esempio n. 4
0
        /// <summary>
        /// 设置 CSV 数据对象数据
        /// </summary>
        /// <param name="item"></param>
        /// <param name="value"></param>
        /// <returns>是否设置成功,数据列不存在时返回 false</returns>
        public bool SetObject(ReaderItem item, string value)
        {
            tryCreateNextObject(ref item);
            int index = getIndex(item.Col);

            if (index >= 0)
            {
                currentObject.ValueArray[index] = value;
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// 设置 CSV 数据对象数据
        /// </summary>
        /// <param name="item"></param>
        /// <param name="ignorePrefix">数据忽略前缀</param>
        /// <returns>是否设置成功,数据列不存在时返回 false</returns>
        public bool SetObject(ReaderItem item, char ignorePrefix)
        {
            tryCreateNextObject(ref item);
            int index = getIndex(item.Col);

            if (index >= 0)
            {
                currentObject.ValueArray[index] = item.GetString(ignorePrefix);
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
 /// <summary>
 /// 当列号为 0 时创建下一个待解析 CSV 数据对象
 /// </summary>
 /// <param name="item"></param>
 private void tryCreateNextObject(ref ReaderItem item)
 {
     if (currentObject != null && item.Row == currentObject.Row)
     {
         currentObject.SetEnd(ref item);
     }
     else
     {
         if (indexArray == null)
         {
             createIndexArray();
         }
         objectReaders.Add(currentObject = new ObjectReader(this, ref item));
     }
 }
Esempio n. 7
0
 /// <summary>
 /// 获取字符串
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 internal string GetString(ref ReaderItem item)
 {
     if (content[item.Start] == escape)
     {
         if (item.Length == 2)
         {
             return(string.Empty);
         }
         if (escapeString == null)
         {
             escapeString  = escape.ToString();
             escapeString2 = escapeString + escapeString;
         }
         return(content.Substring(item.Start + 1, item.Length - 2).Replace(escapeString2, escapeString));
     }
     return(content.Substring(item.Start, item.Length));
 }
Esempio n. 8
0
 public void AppendName(ReaderItem item, char ignorePrefix)
 {
     appendName(item.GetString(ignorePrefix), item.Col);
 }
Esempio n. 9
0
 public void AppendName(ReaderItem item)
 {
     appendName(item.String, item.Col);
 }
Esempio n. 10
0
 public int GetIndex(ReaderItem item)
 {
     return(getIndex(item.Col));
 }
Esempio n. 11
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);
            }
        }