Пример #1
0
		public static List<DateTime?> ParseNullableCollection(BufferedTextReader reader, int context)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var escaped = cur == '"' || cur == '\\';
			if (escaped)
				reader.Read(context);
			var list = new List<DateTime?>();
			cur = reader.Peek();
			if (cur == '}')
				reader.Read();
			while (cur != -1 && cur != '}')
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					cur = reader.Read(4);
					list.Add(null);
				}
				else
				{
					list.Add(ParseDate(reader, cur));
					cur = reader.Read();
				}
			}
			if (escaped)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #2
0
		public static List<bool> ParseCollection(BufferedTextReader reader, int context)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var espaced = cur != '{';
			if (espaced)
				reader.Read(context);
			var list = new List<bool>();
			cur = reader.Peek();
			if (cur == '}')
				reader.Read();
			while (cur != -1 && cur != '}')
			{
				cur = reader.Read();
				if (cur == 't')
					list.Add(true);
				else if (cur == 'f')
					list.Add(false);
				else
				{
					reader.Read(3);
					list.Add(false);
				}
				cur = reader.Read();
			}
			if (espaced)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #3
0
		public static List<decimal?> ParseNullableCollection(BufferedTextReader reader, int context)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var espaced = cur != '{';
			if (espaced)
				reader.Read(context);
			cur = reader.Peek();
			if (cur == '}')
			{
				if (espaced)
					reader.Read(context + 2);
				else
					reader.Read(2);
				return new List<decimal?>(0);
			}
			var list = new List<decimal?>();
			do
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					list.Add(null);
					cur = reader.Read(4);
				}
				else list.Add(ParseDecimal(reader, ref cur, '}'));
			} while (cur == ',');
			if (espaced)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #4
0
 public static List<Dictionary<string, string>> ParseCollection(BufferedTextReader reader, int context, bool allowNulls)
 {
     var cur = reader.Read();
     if (cur == ',' || cur == ')')
         return null;
     var espaced = cur != '{';
     if (espaced)
         reader.Read(context);
     var innerContext = context << 1;
     var list = new List<Dictionary<string, string>>();
     cur = reader.Peek();
     if (cur == '}')
         reader.Read();
     while (cur != -1 && cur != '}')
     {
         cur = reader.Read();
         if (cur == 'N')
         {
             cur = reader.Read(4);
             list.Add(allowNulls ? null : new Dictionary<string, string>());
         }
         else
         {
             list.Add(ParseDictionary(reader, innerContext, innerContext << 1, ref cur, '}'));
         }
     }
     if (espaced)
         reader.Read(context + 1);
     else
         reader.Read();
     return list;
 }
Пример #5
0
        public static List <byte[]> ParseCollection(BufferedTextReader reader, int context, bool allowNulls)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var escaped = cur != '{';

            if (escaped)
            {
                reader.Read(context);
            }
            var innerContext = context << 1;
            var skipInner    = innerContext + (innerContext << 1);
            var list         = new List <byte[]>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            var emptyColl = allowNulls ? null : EmptyBytes;

            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    list.Add(emptyColl);
                    cur = reader.Read(4);
                }
                else
                {
                    reader.Read(skipInner);
                    var item = new List <byte>(1024);
                    cur = reader.Read();
                    while (cur != -1 && cur != '"' && cur != '\\')
                    {
                        item.Add((byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]));
                        cur = reader.Read();
                    }
                    cur = reader.Read(innerContext);
                    list.Add(item.ToArray());
                }
            }
            if (escaped)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #6
0
        public static List <DateTime> ParseCollectionUtc(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var escaped = cur != '{';

            if (escaped)
            {
                reader.Read(context);
            }
            int innerContext = context == 0 ? 1 : context << 1;

            cur = reader.Peek();
            if (cur == '}')
            {
                if (escaped)
                {
                    reader.Read(context + 2);
                }
                else
                {
                    reader.Read(2);
                }
                return(new List <DateTime>(0));
            }
            var list = new List <DateTime>();

            do
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read(4);
                    list.Add(MinUtc);
                }
                else
                {
                    list.Add(ParseTimestampUtc(reader, innerContext));
                    cur = reader.Read();
                }
            } while (cur == ',');
            if (escaped)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #7
0
        public static List <double> ParseCollection(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            var list = new List <double>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read();
                    if (cur == 'U')
                    {
                        cur = reader.Read(3);
                        list.Add(0);
                    }
                    else
                    {
                        list.Add(double.NaN);
                        cur = reader.Read(2);
                    }
                }
                else
                {
                    list.Add(ParseDouble(reader, ref cur, '}'));
                }
            }
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #8
0
        public static List <Guid> ParseCollection(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            cur = reader.Peek();
            if (cur == '}')
            {
                if (espaced)
                {
                    reader.Read(context + 2);
                }
                else
                {
                    reader.Read(2);
                }
                return(new List <Guid>(0));
            }
            var list = new List <Guid>();

            do
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read(4);
                    list.Add(Guid.Empty);
                }
                else
                {
                    list.Add(ParseCollectionGuid(reader, cur));
                    cur = reader.Read();
                }
            } while (cur == ',');
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #9
0
        public static List <decimal?> ParseNullableCollection(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            cur = reader.Peek();
            if (cur == '}')
            {
                if (espaced)
                {
                    reader.Read(context + 2);
                }
                else
                {
                    reader.Read(2);
                }
                return(new List <decimal?>(0));
            }
            var list = new List <decimal?>();

            do
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    list.Add(null);
                    cur = reader.Read(4);
                }
                else
                {
                    list.Add(ParseDecimal(reader, ref cur, '}'));
                }
            } while (cur == ',');
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #10
0
        public static List <bool> ParseCollection(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            var list = new List <bool>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 't')
                {
                    list.Add(true);
                }
                else if (cur == 'f')
                {
                    list.Add(false);
                }
                else
                {
                    reader.Read(3);
                    list.Add(false);
                }
                cur = reader.Read();
            }
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #11
0
        public static List <Dictionary <string, string> > ParseCollection(BufferedTextReader reader, int context, bool allowNulls)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var escaped = cur != '{';

            if (escaped)
            {
                reader.Read(context);
            }
            int innerContext = context == 0 ? 1 : context << 1;
            var list         = new List <Dictionary <string, string> >();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read(4);
                    list.Add(allowNulls ? null : new Dictionary <string, string>());
                }
                else
                {
                    list.Add(ParseDictionary(reader, innerContext, innerContext << 1, ref cur, '}'));
                }
            }
            if (escaped)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #12
0
        public static List <DateTime?> ParseNullableCollection(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var escaped = cur == '"' || cur == '\\';

            if (escaped)
            {
                reader.Read(context);
            }
            var list = new List <DateTime?>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read(4);
                    list.Add(null);
                }
                else
                {
                    list.Add(ParseDate(reader, cur));
                    cur = reader.Read();
                }
            }
            if (escaped)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #13
0
        public static List <short?> ParseNullableCollection(BufferedTextReader reader, int context)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            var list = new List <short?>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read(4);
                    list.Add(null);
                }
                else
                {
                    list.Add(ParseShort(reader, ref cur, '}'));
                }
            }
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #14
0
		public static List<byte[]> ParseCollection(BufferedTextReader reader, int context, bool allowNulls)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var escaped = cur != '{';
			if (escaped)
				reader.Read(context);
			var innerContext = context << 1;
			var skipInner = innerContext + (innerContext << 1);
			var list = new List<byte[]>();
			cur = reader.Peek();
			if (cur == '}')
				reader.Read();
			var emptyColl = allowNulls ? null : EmptyBytes;
			while (cur != -1 && cur != '}')
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					list.Add(emptyColl);
					cur = reader.Read(4);
				}
				else
				{
					reader.Read(skipInner);
					var item = new List<byte>(1024);
					cur = reader.Read();
					while (cur != -1 && cur != '"' && cur != '\\')
					{
						item.Add((byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]));
						cur = reader.Read();
					}
					cur = reader.Read(innerContext);
					list.Add(item.ToArray());
				}
			}
			if (escaped)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #15
0
 public static List<string> ParseCollection(BufferedTextReader reader, int context, bool allowNull)
 {
     var cur = reader.Read();
     if (cur == ',' || cur == ')')
         return null;
     var espaced = cur != '{';
     if (espaced)
         reader.Read(context);
     var innerContext = context << 1;
     cur = reader.Peek();
     if (cur == '}')
     {
         if (espaced)
             reader.Read(context + 2);
         else
             reader.Read(2);
         return new List<string>(0);
     }
     var list = new List<string>();
     var emptyCol = allowNull ? null : string.Empty;
     do
     {
         cur = reader.Read();
         if (cur == '"' || cur == '\\')
             list.Add(ParseEscapedString(reader, innerContext, ref cur, '}'));
         else
         {
             reader.InitBuffer((char)cur);
             reader.FillUntil(',', '}');
             cur = reader.Read();
             if (reader.BufferMatches("NULL"))
                 list.Add(emptyCol);
             else
                 list.Add(reader.BufferToString());
         }
     } while (cur == ',');
     if (espaced)
         reader.Read(context + 1);
     else
         reader.Read();
     return list;
 }
Пример #16
0
		public static List<double> ParseCollection(BufferedTextReader reader, int context)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var espaced = cur != '{';
			if (espaced)
				reader.Read(context);
			var list = new List<double>();
			cur = reader.Peek();
			if (cur == '}')
				reader.Read();
			while (cur != -1 && cur != '}')
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					cur = reader.Read();
					if (cur == 'U')
					{
						cur = reader.Read(3);
						list.Add(0);
					}
					else
					{
						list.Add(double.NaN);
						cur = reader.Read(2);
					}
				}
				else
				{
					list.Add(ParseDouble(reader, ref cur, '}'));
				}
			}
			if (espaced)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #17
0
 public static List<DateTime> ParseCollection(BufferedTextReader reader, int context)
 {
     var cur = reader.Read();
     if (cur == ',' || cur == ')')
         return null;
     var escaped = cur != '{';
     if (escaped)
         reader.Read(context);
     var innerContext = context << 1;
     cur = reader.Peek();
     if (cur == '}')
     {
         if (escaped)
             reader.Read(context + 2);
         else
             reader.Read(2);
         return new List<DateTime>(0);
     }
     var list = new List<DateTime>();
     do
     {
         cur = reader.Read();
         if (cur == 'N')
         {
             cur = reader.Read(4);
             list.Add(DateTime.MinValue);
         }
         else
         {
             list.Add(ParseTimestampUtc(reader, innerContext).ToLocalTime());
             cur = reader.Read();
         }
     } while (cur == ',');
     if (escaped)
         reader.Read(context + 1);
     else
         reader.Read();
     return list;
 }
Пример #18
0
        public static List <Stream> ParseStreamCollection(BufferedTextReader reader, int context, bool allowNulls)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var escaped = cur != '{';

            if (escaped)
            {
                reader.Read(context);
            }
            var innerContext = context << 1;
            var skipInner    = innerContext + (innerContext << 1);
            var list         = new List <Stream>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            var emptyCol = allowNulls ? null : new MemoryStream();
            var bytes    = reader.ByteBuffer;

            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    list.Add(emptyCol);
                    cur = reader.Read(4);
                }
                else
                {
                    cur = reader.Read(skipInner + 1);
                    int ind = 0;
                    while (ind < bytes.Length && cur != '\\' && cur != '"')
                    {
                        bytes[ind++] = (byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]);
                        cur          = reader.Read();
                    }
                    Stream stream;
                    if (cur == '\\' || cur == '"')
                    {
                        stream = new MemoryStream();
                        stream.Write(bytes, 0, ind);
                    }
                    else
                    {
                        stream = ChunkedMemoryStream.Create();
                        stream.Write(bytes, 0, ind);
                        while (cur != -1 && cur != '\\' && cur != '"')
                        {
                            stream.WriteByte((byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]));
                            cur = reader.Read();
                        }
                    }
                    cur             = reader.Read(innerContext);
                    stream.Position = 0;
                    list.Add(stream);
                }
            }
            if (escaped)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #19
0
        public static List <T?> ParseNullableCollection <T>(BufferedTextReader reader, int context, Func <BufferedTextReader, T> factory)
            where T : struct
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            cur = reader.Peek();
            if (cur == '}')
            {
                if (espaced)
                {
                    reader.Read(context);
                }
                else
                {
                    reader.Read(2);
                }
                return(new List <T?>(0));
            }
            var innerContext = context == 0 ? 1 : context << 1;
            var list         = new List <T?>();

            do
            {
                cur = reader.Read();
                if (cur == '"' || cur == '\\')
                {
                    cur = reader.Read(innerContext);
                    reader.InitBuffer((char)cur);
                    reader.FillUntil('\\', '"');
                    list.Add(factory(reader));
                    cur = reader.Read(innerContext + 1);
                }
                else
                {
                    reader.InitBuffer((char)cur);
                    reader.FillUntil(',', '}');
                    cur = reader.Read();
                    if (reader.BufferMatches("NULL"))
                    {
                        list.Add(null);
                    }
                    else
                    {
                        list.Add(factory(reader));
                    }
                }
            } while (cur == ',');
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #20
0
 private static Dictionary<string, string> ParseDictionary(
     BufferedTextReader reader,
     int context,
     int quoteContext,
     ref int cur,
     char matchEnd)
 {
     cur = reader.Read(quoteContext);
     if (cur == ',' || cur == matchEnd)
         return new Dictionary<string, string>(0);
     var dict = new Dictionary<string, string>();
     for (int i = 0; i < context; i++)
         cur = reader.Read();
     reader.InitBuffer();
     do
     {
         do
         {
             if (cur == '\\' || cur == '"')
             {
                 cur = reader.Read(quoteContext);
                 if (cur == '=')
                     break;
                 for (int i = 0; i < quoteContext - 1; i++)
                     cur = reader.Read();
             }
             reader.AddToBuffer((char)cur);
             reader.FillUntil('\\', '"');
             cur = reader.Read();
         } while (cur != -1);
         var name = reader.BufferToString();
         cur = reader.Read(2);
         if (cur == 'N')
         {
             dict.Add(name, null);
             cur = reader.Read(4);
             if (cur == '\\' || cur == '"')
             {
                 reader.Read(context);
                 return dict;
             }
             if (cur == ',' && reader.Peek() != ' ')
                 return dict;
             do { cur = reader.Read(); }
             while (cur == ' ');
         }
         else
         {
             cur = reader.Read(quoteContext);
             do
             {
                 if (cur == '\\' || cur == '"')
                 {
                     cur = reader.Read(quoteContext);
                     if (cur == ',')
                     {
                         dict.Add(name, reader.BufferToString());
                         do { cur = reader.Read(); }
                         while (cur == ' ');
                         cur = reader.Read(quoteContext);
                         break;
                     }
                     for (int i = 0; i < context; i++)
                         cur = reader.Read();
                     if (cur == ',' || cur == -1 || cur == matchEnd)
                     {
                         dict.Add(name, reader.BufferToString());
                         return dict;
                     }
                     for (int i = 0; i < context - 1; i++)
                         cur = reader.Read();
                 }
                 reader.AddToBuffer((char)cur);
                 reader.FillUntil('\\', '"');
                 cur = reader.Read();
             } while (cur != -1);
         }
     } while (cur != -1);
     return dict;
 }
Пример #21
0
        private static Dictionary <string, string> ParseDictionary(
            BufferedTextReader reader,
            int context,
            int quoteContext,
            ref int cur,
            char matchEnd)
        {
            cur = reader.Read(quoteContext);
            if (cur == ',' || cur == matchEnd)
            {
                return(new Dictionary <string, string>(0));
            }
            var dict = new Dictionary <string, string>();

            for (int i = 0; i < context; i++)
            {
                cur = reader.Read();
            }
            reader.InitBuffer();
            do
            {
                do
                {
                    if (cur == '\\' || cur == '"')
                    {
                        cur = reader.Read(quoteContext);
                        if (cur == '=')
                        {
                            break;
                        }
                        for (int i = 0; i < quoteContext - 1; i++)
                        {
                            cur = reader.Read();
                        }
                    }
                    reader.AddToBuffer((char)cur);
                    reader.FillUntil('\\', '"');
                    cur = reader.Read();
                } while (cur != -1);
                var name = reader.BufferToString();
                cur = reader.Read(2);
                if (cur == 'N')
                {
                    dict.Add(name, null);
                    cur = reader.Read(4);
                    if (cur == '\\' || cur == '"')
                    {
                        reader.Read(context);
                        return(dict);
                    }
                    if (cur == ',' && reader.Peek() != ' ')
                    {
                        return(dict);
                    }
                    do
                    {
                        cur = reader.Read();
                    }while (cur == ' ');
                }
                else
                {
                    cur = reader.Read(quoteContext);
                    do
                    {
                        if (cur == '\\' || cur == '"')
                        {
                            cur = reader.Read(quoteContext);
                            if (cur == ',')
                            {
                                dict.Add(name, reader.BufferToString());
                                do
                                {
                                    cur = reader.Read();
                                }while (cur == ' ');
                                cur = reader.Read(quoteContext);
                                break;
                            }
                            for (int i = 0; i < context; i++)
                            {
                                cur = reader.Read();
                            }
                            if (cur == ',' || cur == -1 || cur == matchEnd)
                            {
                                dict.Add(name, reader.BufferToString());
                                return(dict);
                            }
                            for (int i = 0; i < context - 1; i++)
                            {
                                cur = reader.Read();
                            }
                        }
                        reader.AddToBuffer((char)cur);
                        reader.FillUntil('\\', '"');
                        cur = reader.Read();
                    } while (cur != -1);
                }
            } while (cur != -1);
            return(dict);
        }
Пример #22
0
        public static List <T> ParseCollection <T>(BufferedTextReader reader, int context, IServiceProvider locator, Func <BufferedTextReader, int, int, IServiceProvider, T> parseItem)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var escaped = cur != '{';

            if (escaped)
            {
                reader.Read(context);
            }
            cur = reader.Peek();
            if (cur == '}')
            {
                if (escaped)
                {
                    reader.Read(context + 2);
                }
                else
                {
                    reader.Read(2);
                }
                return(new List <T>(0));
            }
            var list          = new List <T>();
            var arrayContext  = Math.Max(context << 1, 1);
            var recordContext = arrayContext << 1;

            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                if (cur == 'N')
                {
                    cur = reader.Read(4);
                    list.Add(default(T));
                }
                else
                {
                    var innerEscaped = cur != '(';
                    if (innerEscaped)
                    {
                        reader.Read(arrayContext);
                    }
                    list.Add(parseItem(reader, 0, recordContext, locator));
                    if (innerEscaped)
                    {
                        cur = reader.Read(arrayContext + 1);
                    }
                    else
                    {
                        cur = reader.Read();
                    }
                }
            }
            if (escaped)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #23
0
		public static List<Stream> ParseStreamCollection(BufferedTextReader reader, int context, bool allowNulls)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var escaped = cur != '{';
			if (escaped)
				reader.Read(context);
			var innerContext = context << 1;
			var skipInner = innerContext + (innerContext << 1);
			var list = new List<Stream>();
			cur = reader.Peek();
			if (cur == '}')
				reader.Read();
			var emptyCol = allowNulls ? null : new MemoryStream();
			var bytes = reader.ByteBuffer;
			while (cur != -1 && cur != '}')
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					list.Add(emptyCol);
					cur = reader.Read(4);
				}
				else
				{
					cur = reader.Read(skipInner + 1);
					int ind = 0;
					while (ind < bytes.Length && cur != '\\' && cur != '"')
					{
						bytes[ind++] = (byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]);
						cur = reader.Read();
					}
					Stream stream;
					if (cur == '\\' || cur == '"')
					{
						stream = new MemoryStream();
						stream.Write(bytes, 0, ind);
					}
					else
					{
						stream = ChunkedMemoryStream.Create();
						stream.Write(bytes, 0, ind);
						while (cur != -1 && cur != '\\' && cur != '"')
						{
							stream.WriteByte((byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]));
							cur = reader.Read();
						}
					}
					cur = reader.Read(innerContext);
					stream.Position = 0;
					list.Add(stream);
				}
			}
			if (escaped)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #24
0
		public static List<Guid> ParseCollection(BufferedTextReader reader, int context)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var espaced = cur != '{';
			if (espaced)
				reader.Read(context);
			cur = reader.Peek();
			if (cur == '}')
			{
				if (espaced)
					reader.Read(context + 2);
				else
					reader.Read(2);
				return new List<Guid>(0);
			}
			var list = new List<Guid>();
			do
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					cur = reader.Read(4);
					list.Add(Guid.Empty);
				}
				else
				{
					list.Add(ParseCollectionGuid(reader, cur));
					cur = reader.Read();
				}
			} while (cur == ',');
			if (espaced)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}
Пример #25
0
        public static List <string> ParseCollection(BufferedTextReader reader, int context, bool allowNull)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                reader.Read(context);
            }
            cur = reader.Peek();
            if (cur == '}')
            {
                if (espaced)
                {
                    reader.Read(context + 2);
                }
                else
                {
                    reader.Read(2);
                }
                return(new List <string>(0));
            }
            var innerContext = context << 1;
            var list         = new List <string>();
            var emptyCol     = allowNull ? null : string.Empty;

            do
            {
                cur = reader.Read();
                if (cur == '"' || cur == '\\')
                {
                    list.Add(ParseEscapedString(reader, innerContext, ref cur, '}'));
                }
                else
                {
                    reader.InitBuffer((char)cur);
                    reader.FillUntil(',', '}');
                    cur = reader.Read();
                    if (reader.BufferMatches("NULL"))
                    {
                        list.Add(emptyCol);
                    }
                    else
                    {
                        list.Add(reader.BufferToString());
                    }
                }
            } while (cur == ',');
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #26
0
 public static List<Stream> ParseStreamCollection(BufferedTextReader reader, int context, bool allowNull)
 {
     var cur = reader.Read();
     if (cur == ',' || cur == ')')
         return null;
     var espaced = cur != '{';
     if (espaced)
         cur = reader.Read(context);
     var innerContext = context << 1;
     var list = new List<Stream>();
     cur = reader.Peek();
     if (cur == '}')
         reader.Read();
     while (cur != -1 && cur != '}')
     {
         cur = reader.Read();
         var cms = ChunkedMemoryStream.Create();
         var sw = cms.GetWriter();
         if (cur == '"' || cur == '\\')
         {
             cur = reader.Read(innerContext);
             while (cur != -1)
             {
                 if (cur == '\\' || cur == '"')
                 {
                     cur = reader.Read(innerContext);
                     if (cur == ',' || cur == '}')
                         break;
                     for (int i = 0; i < innerContext - 1; i++)
                         cur = reader.Read();
                 }
                 sw.Write((char)cur);
                 cur = reader.Read();
             }
             sw.Flush();
             cms.Position = 0;
             list.Add(cms);
         }
         else
         {
             do
             {
                 sw.Write((char)cur);
                 cur = reader.Read();
             } while (cur != -1 && cur != ',' && cur != '}');
             sw.Flush();
             cms.Position = 0;
             if (cms.Matches(NULL))
             {
                 list.Add(null);
                 cms.Dispose();
             }
             else
                 list.Add(cms);
         }
     }
     if (espaced)
         reader.Read(context + 1);
     else
         reader.Read();
     return list;
 }
Пример #27
0
        public static List <Stream> ParseStreamCollection(BufferedTextReader reader, int context, bool allowNull)
        {
            var cur = reader.Read();

            if (cur == ',' || cur == ')')
            {
                return(null);
            }
            var espaced = cur != '{';

            if (espaced)
            {
                cur = reader.Read(context);
            }
            var innerContext = context << 1;
            var list         = new List <Stream>();

            cur = reader.Peek();
            if (cur == '}')
            {
                reader.Read();
            }
            while (cur != -1 && cur != '}')
            {
                cur = reader.Read();
                var cms = ChunkedMemoryStream.Create();
                var sw  = cms.GetWriter();
                if (cur == '"' || cur == '\\')
                {
                    cur = reader.Read(innerContext);
                    while (cur != -1)
                    {
                        if (cur == '\\' || cur == '"')
                        {
                            cur = reader.Read(innerContext);
                            if (cur == ',' || cur == '}')
                            {
                                break;
                            }
                            for (int i = 0; i < innerContext - 1; i++)
                            {
                                cur = reader.Read();
                            }
                        }
                        sw.Write((char)cur);
                        cur = reader.Read();
                    }
                    sw.Flush();
                    cms.Position = 0;
                    list.Add(cms);
                }
                else
                {
                    do
                    {
                        sw.Write((char)cur);
                        cur = reader.Read();
                    } while (cur != -1 && cur != ',' && cur != '}');
                    sw.Flush();
                    cms.Position = 0;
                    if (cms.Matches(NULL))
                    {
                        list.Add(null);
                        cms.Dispose();
                    }
                    else
                    {
                        list.Add(cms);
                    }
                }
            }
            if (espaced)
            {
                reader.Read(context + 1);
            }
            else
            {
                reader.Read();
            }
            return(list);
        }
Пример #28
0
		public static List<DateTime?> ParseNullableCollectionUtc(BufferedTextReader reader, int context)
		{
			var cur = reader.Read();
			if (cur == ',' || cur == ')')
				return null;
			var escaped = cur != '{';
			if (escaped)
				reader.Read(context);
			int innerContext = context == 0 ? 1 : context << 1;
			cur = reader.Peek();
			if (cur == '}')
			{
				if (escaped)
					reader.Read(context + 2);
				else
					reader.Read(2);
				return new List<DateTime?>(0);
			}
			var list = new List<DateTime?>();
			do
			{
				cur = reader.Read();
				if (cur == 'N')
				{
					cur = reader.Read(4);
					list.Add(null);
				}
				else
				{
					list.Add(ParseTimestampUtc(reader, innerContext));
					cur = reader.Read();
				}
			} while (cur == ',');
			if (escaped)
				reader.Read(context + 1);
			else
				reader.Read();
			return list;
		}