本文整理汇总了C#中BufferedTextReader.AddToBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedTextReader.AddToBuffer方法的具体用法?C# BufferedTextReader.AddToBuffer怎么用?C# BufferedTextReader.AddToBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedTextReader
的用法示例。
在下文中一共展示了BufferedTextReader.AddToBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
示例2: 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;
}
示例3: 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();
}