本文整理汇总了C#中BufferedTextReader.FillUntil方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedTextReader.FillUntil方法的具体用法?C# BufferedTextReader.FillUntil怎么用?C# BufferedTextReader.FillUntil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedTextReader
的用法示例。
在下文中一共展示了BufferedTextReader.FillUntil方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: Skip
public static void Skip(BufferedTextReader reader, int context)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return;
if (cur != '"' && cur != '\\')
{
reader.InitBuffer();
reader.FillUntil(',', ')');
reader.Read();
}
else
{
cur = reader.Read(context);
while (cur != -1)
{
if (cur == '\\' || cur == '"')
{
cur = reader.Read(context);
if (cur == ',' || cur == ')')
return;
cur = reader.Read(context);
}
else cur = reader.Read();
}
throw new FrameworkException("Unable to find end of string");
}
}
示例3: ParseDouble
private static double ParseDouble(BufferedTextReader reader, ref int cur, char matchEnd)
{
reader.InitBuffer((char)cur);
reader.FillUntil(',', matchEnd);
cur = reader.Read();
//TODO: optimize
return double.Parse(reader.BufferToString(), NumberStyles.Float, CultureInfo.InvariantCulture);
}
示例4: Deserialize
public static TreePath Deserialize(BufferedTextReader sr, int nextToken)
{
if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
sr.InitBuffer();
nextToken = sr.FillUntil('"');
sr.Read();
return TreePath.Create(sr.BufferToString());
}
示例5: 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, ')');
}
示例6: ParseCollection
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;
}
示例7: ParseEscapedString
private static string ParseEscapedString(BufferedTextReader reader, int context, ref int cur, char matchEnd)
{
cur = reader.Read(context);
reader.InitBuffer();
do
{
if (cur == '\\' || cur == '"')
{
cur = reader.Read(context);
if (cur == ',' || cur == matchEnd)
return reader.BufferToString();
for (int i = 0; i < context - 1; i++)
cur = reader.Read();
}
reader.AddToBuffer((char)cur);
reader.FillUntil('\\', '"');
cur = reader.Read();
} while (cur != -1);
throw new FrameworkException("Unable to find end of string");
}
示例8: ParseStream
public static Stream ParseStream(BufferedTextReader reader, int context)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
var cms = ChunkedMemoryStream.Create();
var sw = cms.GetWriter();
if (cur != '"' && cur != '\\')
{
sw.Write((char)cur);
reader.FillUntil(sw, ',', ')');
}
else
{
cur = reader.Read(context);
while (cur != -1)
{
if (cur == '\\' || cur == '"')
{
cur = reader.Read(context);
if (cur == ',' || cur == ')')
{
sw.Flush();
cms.Position = 0;
return cms;
}
for (int i = 0; i < context - 1; i++)
cur = reader.Read();
}
sw.Write((char)cur);
cur = reader.Read();
}
reader.Read(context);
}
sw.Flush();
cms.Position = 0;
return cms;
}
示例9: ParseDictionary
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;
}
示例10: Deserialize
public static string Deserialize(BufferedTextReader sr, int nextToken)
{
if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
sr.InitBuffer();
nextToken = sr.FillUntil('"', '\\');
if (nextToken == '"')
{
sr.Read();
return sr.BufferToString();
}
var tmp = sr.SmallBuffer;
do
{
nextToken = sr.Read(2);
switch (nextToken)
{
case 'b': sr.AddToBuffer('\b'); break;
case 't': sr.AddToBuffer('\t'); break;
case 'r': sr.AddToBuffer('\r'); break;
case 'n': sr.AddToBuffer('\n'); break;
case 'f': sr.AddToBuffer('\f'); break;
case 'u':
var len = sr.Read(tmp, 0, 4);
if (len < 4) sr.Read(tmp, len, 4 - len);//the second one must succeed
sr.AddToBuffer((char)Convert.ToInt32(new string(tmp, 0, 4), 16));//TODO: optimize to no allocation
break;
default:
sr.AddToBuffer((char)nextToken);
break;
}
nextToken = sr.FillUntil('"', '\\');
} while (nextToken == '\\');
sr.Read();
return sr.BufferToString();
}