示例#1
0
        /// <summary> 读取从当前位置到终止字符之间的数据
        /// </summary>
        /// <param name="stop">终止字符</param>
        /// <param name="mode">读取模式</param>
        public string ReadToStop(Func <char, bool> stopCharMatch, ReadMode mode = ReadMode.SkipAll | ReadMode.RemoveStop | ReadMode.AllowToEnd)
        {
            ReadNext(mode | ReadMode.ReserveStop);

            int startIndex = Position;
            int stopIndex;
            var parse = 0 != (mode & ReadMode.ParseAll);

            do
            {
                if (parse && Current == '\\')
                {
                    var str = new QuickStringWriter();
                    str.Append(_rawCharArray, startIndex, Position - startIndex);
                    foreach (var s in ReadParseString(stopCharMatch, mode))
                    {
                        str.Append(s);
                    }
                    return(str.ToString());
                }
                if (stopCharMatch(Current))
                {
                    if (CheckAnd(mode, ReadMode.RemoveStop))
                    {
                        stopIndex = Position;
                    }
                    else
                    {
                        stopIndex = Position + 1;
                    }
                    if (CheckAnd(mode, ReadMode.ReserveStop) == false)
                    {
                        ReadNext();
                    }
                    if (CheckAnd(mode, ReadMode.RemoveStart))
                    {
                        startIndex++;
                    }
                    return(new string(_rawCharArray, startIndex, stopIndex - startIndex));
                }
            } while (ReadNext());

            if ((mode & ReadMode.AllowToEnd) == 0)
            {
                throw new NotSupportedException("已达字符串结尾");
            }
            else
            {
                return(new string(_rawCharArray, startIndex, Length - startIndex));
            }
        }
示例#2
0
        /// <summary> 将 任意对象 转换Json字符串写入Buffer
        /// </summary>
        /// <param name="obj">任意对象</param>
        protected void AppendObject(object obj)
        {
            if (obj == null || obj is DBNull)
            {
                Buffer.Append("null");
                return;
            }

            var tojson = obj as IToJson;

            if (tojson != null)
            {
                AppendObject(tojson.ToJson());
                return;
            }
            var s = obj as string;

            if (s != null)
            {
                AppendString(s);
            }
            else
            {
                var conv = obj as IConvertible;
                if (conv != null)
                {
                    AppendConvertible(conv);
                }
                else if (obj is Guid)
                {
                    AppendGuid((Guid)obj);
                }
                else
                {
                    AppendCheckLoopRef(obj);
                }
            }
        }