当前位置: 首页>>代码示例>>C#>>正文


C# BufferedTextReader.ReadUntil方法代码示例

本文整理汇总了C#中BufferedTextReader.ReadUntil方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedTextReader.ReadUntil方法的具体用法?C# BufferedTextReader.ReadUntil怎么用?C# BufferedTextReader.ReadUntil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BufferedTextReader的用法示例。


在下文中一共展示了BufferedTextReader.ReadUntil方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseDecimal

		private static decimal ParseDecimal(BufferedTextReader reader, ref int cur, char matchEnd)
		{
			var neg = cur == '-';
			if (neg)
				cur = reader.Read();
			var buf = reader.SmallBuffer;
			buf[0] = (char)cur;
			var size = reader.ReadUntil(buf, 1, ',', matchEnd) + 1;
			cur = reader.Read();
			if (cur >= '0' && cur <= '9' || cur == '.')
				throw new FrameworkException("Too long decimal number: " + new string(buf, 0, size));
			if (size > 18)
			{
				if (neg)
					return -decimal.Parse(new string(buf, 0, size), Invariant);
				return decimal.Parse(new string(buf, 0, size), Invariant);
			}
			long value = 0;
			int scale = 0;
			char ch;
			for (int i = 0; i < size && i < buf.Length; i++)
			{
				ch = buf[i];
				if (ch == '.')
					scale = size - i - 1;
				else
					value = (value << 3) + (value << 1) + ch - 48;
			}
			return new decimal((int)value, (int)(value >> 32), 0, neg, (byte)scale);
		}
开发者ID:dstimac,项目名称:revenj,代码行数:30,代码来源:DecimalConverter.cs

示例2: ParseTimestampUtc

 private static DateTime ParseTimestampUtc(BufferedTextReader reader, int context)
 {
     var cur = reader.Read(context);
     var buf = reader.SmallBuffer;
     buf[0] = (char)cur;
     var len = reader.ReadUntil(buf, 1, '\\', '"') + 1;
     reader.Read(context);
     if (buf[10] != ' ')
         return DateTime.Parse(new string(buf, 0, len), CultureInfo.InvariantCulture);
     var year = NumberConverter.Read4(buf, 0);
     var month = NumberConverter.Read2(buf, 5);
     var date = NumberConverter.Read2(buf, 8);
     var hour = NumberConverter.Read2(buf, 11);
     var minutes = NumberConverter.Read2(buf, 14);
     var seconds = NumberConverter.Read2(buf, 17);
     if (buf[19] == '.')
     {
         long nano = 0;
         var max = len - 3;
         for (int i = 20, r = 0; i < max && r < TimestampReminder.Length && i < buf.Length; i++, r++)
             nano += TimestampReminder[r] * (buf[i] - 48);
         var pos = buf[len - 3] == '+';
         var offset = NumberConverter.Read2(buf, len - 2);
         var dt = offset != 0
             ? new DateTime(year, month, date, hour, minutes, seconds, DateTimeKind.Utc).AddHours(pos ? -offset : offset)
             : new DateTime(year, month, date, hour, minutes, seconds, DateTimeKind.Utc);
         return new DateTime(dt.Ticks + nano, DateTimeKind.Utc);
     }
     else
     {
         var pos = buf[len - 3] == '+';
         var offset = NumberConverter.Read2(buf, len - 2);
         if (offset != 0)
             return new DateTime(year, month, date, hour, minutes, seconds, DateTimeKind.Utc).AddHours(pos ? -offset : offset);
         return new DateTime(year, month, date, hour, minutes, seconds, DateTimeKind.Utc);
     }
 }
开发者ID:instant-hrvoje,项目名称:revenj,代码行数:37,代码来源:TimestampConverter.cs

示例3: Deserialize

		public static byte[] Deserialize(BufferedTextReader sr, int nextToken)
		{
			if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
			nextToken = sr.Read();
			if (nextToken == '"') return EmptyBytes;
			var base64 = sr.LargeTempBuffer;
			var res = new List<byte[]>();
			int total = 0;
			int i = 1;
			base64[0] = (char)nextToken;
			int len;
			while ((len = sr.ReadUntil(base64, i, '"')) > 0)
			{
				i += len;
				if (i == base64.Length)
				{
					var bytes = Convert.FromBase64CharArray(base64, 0, base64.Length);
					res.Add(bytes);
					i = 0;
					total += bytes.Length;
				}
			}
			nextToken = sr.Read();
			if (i > 0)
			{
				var bytes = Convert.FromBase64CharArray(base64, 0, i);
				res.Add(bytes);
				total += bytes.Length;
			}
			if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found end of stream.");
			var result = new byte[total];
			var cur = 0;
			for (i = 0; i < res.Count; i++)
			{
				var item = res[i];
				Array.Copy(item, 0, result, cur, item.Length);
				cur += item.Length;
			}
			return result;
		}
开发者ID:dstimac,项目名称:revenj,代码行数:40,代码来源:BinaryConverter.cs

示例4: DeserializeStream

		public static Stream DeserializeStream(BufferedTextReader sr, int nextToken)
		{
			if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
			nextToken = sr.Read();
			if (nextToken == '"') return new MemoryStream();
			//TODO: lazy init stream (more lightweight!?)
			var res = new ChunkedMemoryStream();
			var base64 = sr.LargeTempBuffer;
			int i = 1;
			base64[0] = (char)nextToken;
			int len;
			while ((len = sr.ReadUntil(base64, i, '"')) > 0)
			{
				i += len;
				if (i == base64.Length)
				{
					var bytes = Convert.FromBase64CharArray(base64, 0, base64.Length);
					res.Write(bytes, 0, bytes.Length);
					i = 0;
				}
			}
			nextToken = sr.Read();
			if (i > 0)
			{
				var bytes = Convert.FromBase64CharArray(base64, 0, i);
				res.Write(bytes, 0, bytes.Length);
			}
			if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found end of stream.");
			return res;
		}
开发者ID:dstimac,项目名称:revenj,代码行数:30,代码来源:BinaryConverter.cs


注:本文中的BufferedTextReader.ReadUntil方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。