Example #1
0
        public override bool Equals(object obj)
        {
            UCutType type = obj as UCutType;

            if (object.Equals(type, null))
            {
                return(false);
            }

            return(this.TypeId == type.TypeId);
        }
Example #2
0
        /// <summary>
        /// 返回下一个代码切块
        /// </summary>
        /// <returns></returns>
        public UCodeCut GetNextCut()
        {
            try
            {
                UCodeCut    cut     = new UCodeCut();
                List <byte> cutData = new List <byte>();
                byte        b;
                UCutType    currType = UCutType.None;

                bool inString = false; // 是否解析字符串

                if (EndOfCode == true)
                {
                    cut.CutType = UCutType.End;
                    return(cut);
                }

                while (!EndOfCode)
                {
                    b = GetNextByte();
                    cutData.Add(b);

                    #region UCutType.None
                    if (currType == UCutType.None)
                    {
                        if (b == UConfig.Space)
                        {
                            currType = UCutType.Space;
                            continue;
                        }

                        if (b == UConfig.Tab)
                        {
                            currType = UCutType.Tab;
                            break;
                        }

                        if (b == UConfig.DoubleQuote)
                        {
                            currType = UCutType.String;
                            inString = true;
                            continue;
                        }

                        if (b == UConfig.NewLine)
                        {
                            currType = UCutType.NewLine;

                            // 跳过回车符
                            if (PeekNextByte() == UConfig.Enter)
                            {
                                GetNextByte();
                            }

                            break;
                        }

                        if (b == UConfig.BackSlash)
                        {
                            if (PeekNextByte() == UConfig.BackSlash)
                            {
                                currType = UCutType.Annotation;
                                continue;
                            }
                        }

                        if (UHelper.IsSymbol(b))
                        {
                            currType = UCutType.Symbol;
                            break;
                        }

                        if (UHelper.IsCharacter(b))
                        {
                            currType = UCutType.Normal;
                            continue;
                        }

                        if (UHelper.IsDigit(b))
                        {
                            currType = UCutType.Digit;
                            continue;
                        }
                    }
                    #endregion

                    #region UCutType.Normal
                    if (currType == UCutType.Normal)
                    {
                        if (UHelper.IsCutEnd(b))
                        {
                            BackToLastByte();

                            cutData.RemoveAt(cutData.Count - 1);
                            break;
                        }
                    }
                    #endregion

                    #region UCutType.String
                    if (currType == UCutType.String)
                    {
                        if (b == UConfig.NewLine)
                        {
                            BackToLastByte();

                            currType = UCutType.Normal;
                            break;
                        }

                        if (b == UConfig.DoubleQuote)
                        {
                            inString = false;
                            break;
                        }

                        if (b == UConfig.Slash)
                        {
                            // 添加 \ 后的字符
                            if (inString)
                            {
                                //ch = (char)GetNextChar();
                                //cutData.Add((byte)ch);
                                cutData.Add(GetNextByte());
                                continue;
                            }
                        }
                    }
                    #endregion

                    #region UCutType.Space
                    if (currType == UCutType.Space)
                    {
                        if (b != UConfig.Space)
                        {
                            BackToLastByte();

                            cutData.RemoveAt(cutData.Count - 1);

                            break;
                        }
                    }
                    #endregion

                    #region UCutType.Digit
                    if (currType == UCutType.Digit)
                    {
                        if (UHelper.IsCutEnd(b))
                        {
                            BackToLastByte();

                            cutData.RemoveAt(cutData.Count - 1);
                            break;
                        }

                        if (!UHelper.IsDigit(b))
                        {
                            BackToLastByte();

                            cutData.RemoveAt(cutData.Count - 1);
                            break;
                        }
                    }
                    #endregion

                    #region UCutType.Annotation
                    if (currType == UCutType.Annotation)
                    {
                        if (b == UConfig.NewLine)
                        {
                            BackToLastByte();

                            cutData.RemoveAt(cutData.Count - 1);

                            break;
                        }
                    }
                    #endregion
                }

                cut.CutType = currType;

                // 替换Tab为Space
                if (currType == UCutType.Tab)
                {
                    cut.Data = UConfig.TabString;
                }
                else
                {
                    cut.Data = UHelper.GetStringByBytes(cutData.ToArray());
                }

                return(ParseCodeCutType(cut));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
 public UCodeCut(UCodeCut cut)
 {
     this.CutType = cut.CutType;
     this.Data    = cut.Data;
 }
Example #4
0
        public UCodeCut()
        {
            Data = string.Empty;

            CutType = UCutType.Normal;
        }