本文整理汇总了C#中Reader.MarkFromNext方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.MarkFromNext方法的具体用法?C# Reader.MarkFromNext怎么用?C# Reader.MarkFromNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reader
的用法示例。
在下文中一共展示了Reader.MarkFromNext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseString
private static Token ParseString(Reader reader, char quote)
{
Debug.Assert(reader != null);
//
// TODO Support full string syntax!
//
// string {string1}|{string2}
// string1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*\"
// string2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*\'
// nonascii [^\0-\177]
// escape {unicode}|\\[^\n\r\f0-9a-f]
// unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
//
var strpos = reader.Position;
reader.MarkFromNext(); // skipping quote
char? ch;
StringBuilder sb = null;
while ((ch = reader.Read()) != quote)
{
if (ch == null)
throw new FormatException(string.Format("Unterminated string at position {0}.", strpos));
if (ch == '\\')
{
ch = reader.Read();
//
// NOTE: Only escaping of quote and backslash supported!
//
if (ch != quote && ch != '\\')
throw new FormatException(string.Format("Invalid escape sequence at position {0} in a string at position {1}.", reader.Position, strpos));
if (sb == null)
sb = new StringBuilder();
sb.Append(reader.MarkedExceptLast());
reader.Mark();
}
}
var text = reader.Marked();
if (sb != null)
text = sb.Append(text).ToString();
return Token.String(text);
}
示例2: ParseHash
private static string ParseHash(Reader reader)
{
Debug.Assert(reader != null);
reader.MarkFromNext(); // skipping #
while (IsNmChar(reader.Read())) { /* NOP */ }
var text = reader.MarkedWithUnread();
if (text.Length == 0)
throw new FormatException(string.Format("Invalid hash at position {0}.", reader.Position));
return text;
}