本文整理汇总了C#中BufferedTextReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedTextReader.Read方法的具体用法?C# BufferedTextReader.Read怎么用?C# BufferedTextReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedTextReader
的用法示例。
在下文中一共展示了BufferedTextReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseNullableCollection
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: 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);
}
示例3: DeserializeDecimal
public static decimal DeserializeDecimal(BufferedTextReader sr, ref int nextToken)
{
if (nextToken == '"')
{
sr.InitBuffer();
sr.FillUntil('"');
nextToken = sr.Read(2);
try
{
return sr.BufferToValue(ConvertToDecimal);
}
catch (Exception ex)
{
throw new SerializationException("Error parsing decimal at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex);
}
}
var buf = sr.SmallBuffer;
buf[0] = (char)nextToken;
var size = sr.ReadNumber(buf, 1) + 1;
nextToken = sr.Read();
try
{
return ConvertToDecimal(buf, size, sr);
}
catch (Exception ex)
{
throw new SerializationException("Error parsing decimal at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex);
}
}
示例4: ParseNullable
public static bool? ParseNullable(BufferedTextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
reader.Read();
return cur == 't';
}
示例5: Parse
public static bool Parse(BufferedTextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return false;
reader.Read();
return cur == 't';
}
示例6: Parse
public static S3 Parse(BufferedTextReader reader, int context)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
var s3 = ParseS3(reader, context, context == 0 ? 1 : context << 1, null);
reader.Read();
return s3;
}
示例7: ParseNullable
public static DateTime? ParseNullable(BufferedTextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
var res = ParseDate(reader, cur);
reader.Read();
return res;
}
示例8: Parse
public static DateTime Parse(BufferedTextReader reader, int context)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return DateTime.MinValue;
var dt = ParseTimestampUtc(reader, context);
reader.Read();
return dt.ToLocalTime();
}
示例9: Parse
public static DateTime Parse(BufferedTextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return DateTime.MinValue;
var res = ParseDate(reader, cur);
reader.Read();
return res;
}
示例10: DeserializeNullable
public static XElement DeserializeNullable(BufferedTextReader sr, ref int nextToken)
{
if (nextToken == 'n')
{
if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l')
return null;
throw new SerializationException("Invalid null value found at " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
}
return Deserialize(sr, ref nextToken);
}
示例11: DeserializeDate
public static DateTime DeserializeDate(BufferedTextReader sr, int nextToken)
{
if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
nextToken = sr.Read();
int year = 0;
//TODO: 6!?
for (int i = 0; i < 6 && (nextToken != '-'); i++, nextToken = sr.Read())
year = year * 10 + (nextToken - '0');
nextToken = sr.Read();
int month = nextToken - 48;
nextToken = sr.Read();
if (nextToken != '-')
{
month = month * 10 + (nextToken - '0');
if ((nextToken = sr.Read()) != '-') throw new SerializationException("Expecting '-' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
}
nextToken = sr.Read();
int day = nextToken - 48;
nextToken = sr.Read();
if (nextToken != '"' && nextToken != ' ' && nextToken != 'T')
{
day = day * 10 + (nextToken - '0');
nextToken = sr.Read();
}
for (int i = 0; i < 24 && nextToken != '"'; i++)
nextToken = sr.Read();
if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
return new DateTime(year, month, day);
}
示例12: ParseS3
private static S3 ParseS3(BufferedTextReader reader, int context, int innerContext, IServiceProvider locator)
{
for (int i = 0; i < context; i++)
reader.Read();
var bucket = StringConverter.Parse(reader, innerContext);
var key = StringConverter.Parse(reader, innerContext);
var length = LongConverter.Parse(reader);
var name = StringConverter.Parse(reader, innerContext);
var mimeType = StringConverter.Parse(reader, innerContext);
var metadata = HstoreConverter.Parse(reader, innerContext);
for (int i = 0; i < context; i++)
reader.Read();
return new S3 { Bucket = bucket, Key = key, Length = length, Name = name, MimeType = mimeType, Metadata = metadata };
}
示例13: DeserializeColorNullableCollection
public static void DeserializeColorNullableCollection(BufferedTextReader sr, int nextToken, ICollection<Color?> res)
{
if (nextToken == 'n')
{
if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l')
res.Add(null);
else throw new SerializationException("Invalid value found at position " + JsonSerialization.PositionInStream(sr) + " for Color value. Expecting number, string or null");
nextToken = sr.Read();
}
else res.Add(DeserializeColor(sr, ref nextToken));
while ((nextToken = JsonSerialization.MoveToNextToken(sr, nextToken)) == ',')
{
nextToken = JsonSerialization.GetNextToken(sr);
if (nextToken == 'n')
{
if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l')
res.Add(null);
else throw new SerializationException("Invalid value found at position " + JsonSerialization.PositionInStream(sr) + " for Color value. Expecting number, string or null");
nextToken = sr.Read();
}
else res.Add(DeserializeColor(sr, ref nextToken));
}
if (nextToken != ']')
{
if (nextToken == -1) throw new SerializationException("Unexpected end of json in collection.");
else throw new SerializationException("Expecting ']' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
}
}
示例14: Parse
public static string Parse(BufferedTextReader reader, int context)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
if (cur != '"' && cur != '\\')
{
reader.InitBuffer((char)cur);
reader.FillUntil(',', ')');
reader.Read();
return reader.BufferToString();
}
return ParseEscapedString(reader, context, ref cur, ')');
}
示例15: ParseNullableCollection
public static List<bool?> 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<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(null);
}
cur = reader.Read();
}
if (espaced)
reader.Read(context + 1);
else
reader.Read();
return list;
}