本文整理汇总了C#中TextReader.SkipWhitespace方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.SkipWhitespace方法的具体用法?C# TextReader.SkipWhitespace怎么用?C# TextReader.SkipWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextReader
的用法示例。
在下文中一共展示了TextReader.SkipWhitespace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadPropertyValue
/// <summary>
/// Reads a property value that supports quotes and escaping.
/// </summary>
/// <param name="reader">The text reader.</param>
/// <returns>The property value as a string or null if there is no value.</returns>
private string ReadPropertyValue(TextReader reader)
{
reader.SkipWhitespace();
var result = new StringBuilder();
bool singleQuotes = false;
bool doubleQuotes = false;
bool quoted = false;
char c;
// First character
if (!reader.TryRead(out c))
return null;
;
if (c == '\'')
singleQuotes = quoted = true;
else if (c == '"')
doubleQuotes = quoted = true;
else
result.Append(c);
// Next characters
do {
if (!reader.TryRead(out c))
break;
if (c == '\\') {
// Not yet implemented in OpenRCT2
// result.Append(ReadEscapedCharacter(reader));
result.Append(c);
} else if ((c == ';' || c == '#') && !quoted) {
break;
} else if (c == '\'' && singleQuotes) {
singleQuotes = false;
break;
} else if (c == '"' && doubleQuotes) {
doubleQuotes = false;
break;
} else {
result.Append(c);
}
} while (true);
if (singleQuotes || doubleQuotes)
throw new Exception("No end quote(s)");
if (!quoted)
return result.ToString().TrimEnd();
return result.ToString();
}