本文整理汇总了C#中System.IO.StringReader.ReadToBeforeChar方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.ReadToBeforeChar方法的具体用法?C# StringReader.ReadToBeforeChar怎么用?C# StringReader.ReadToBeforeChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.ReadToBeforeChar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseStyle
private static void ParseStyle(string styleContent, Dictionary<string, Dictionary<string, string>> styles)
{
StringReader reader = new StringReader(styleContent);
while (reader.Peek() != -1)
{
string names = reader.ReadToBeforeChar(CurlyBraceOpen).Trim();
// Consume {
reader.Read();
string block = reader.ReadToBeforeChar(CurlyBraceClose);
Dictionary<string, string> styleValues = new Dictionary<string, string>(strComp);
foreach (var keyValue in block.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
var idxColumn = keyValue.IndexOf(':');
if (idxColumn == -1)
continue;
var name = keyValue.Substring(0, idxColumn).Trim();
var value = idxColumn + 1 < keyValue.Length ? keyValue.Substring(idxColumn + 1).Trim() : string.Empty;
styleValues[name] = value;
}
// Consume }
reader.Read();
foreach (var n in names.Split(','))
{
var name = n.Trim();
Dictionary<string, string> currentValues;
if (styles.TryGetValue(n, out currentValues))
{
foreach (var item in styleValues)
{
currentValues[item.Key] = item.Value;
}
}
else
{
styles[n] = styleValues;
}
}
}
}
示例2: ReadMarkup
public static MarkupType ReadMarkup(this StringReader reader, out MarkupContent content, StringComparer comparer)
{
content = null;
if (!reader.PeekIsMarkup())
{
if (content != null)
content.Type = MarkupType.Raw;
return MarkupType.Raw;
}
//Skip Markup
reader.Read();
int intChar = reader.Peek();
if (intChar == -1)
{
if (content != null)
content.Type = MarkupType.Raw;
return MarkupType.Raw;
}
var isClosingMarkup = intChar == slash;
if (isClosingMarkup)
{
// Consume /
reader.Read();
var name = reader.ReadToBeforeChar(gt);
content = new MarkupContent { Name = name };
// Consume >
reader.Read();
content.Type = MarkupType.ClosingNode;
return content.Type;
}
else
{
bool isComment = false;
StringBuilder data = new StringBuilder();
data.Append(reader.ReadToBeforeChar(gt));
if (data.Length > 3 && data.ToString(0, 3) == "!--")
{
isComment = true;
while (data.ToString(data.Length - 2, 2) != "--")
{
char[] cBuffer = new char[1];
if (reader.Read(cBuffer, 0, 1) == 0)
break;
data.Append(cBuffer[0]);
if (reader.Peek() != -1)
data.Append(reader.ReadToBeforeChar(gt));
}
}
// Consume >
reader.Read();
if (isComment)
{
content = new MarkupContent { Content = data.ToString(3, data.Length - 5).Trim(), Name = "!--" };
content.Type = MarkupType.Comment;
return content.Type;
}
else
{
bool isClosed = false;
if(data[data.Length - 1] == slash)
{
data.Remove(data.Length - 1, 1);
isClosed = true;
}
content = new MarkupContent { Content = data.ToString() };
StringReader elementReader = new StringReader(content.Content);
string elementName = elementReader.ReadToBeforeChar(space);
content.Name = elementName;
content.Parameters = attributesRegex.Matches(elementReader.ReadToEnd()).OfType<Match>().ToDictionary(
(e) => e.Groups["key"].Value,
(e) => e.Groups["value"].Value,
comparer);
content.Type = isClosed ? MarkupType.Node : MarkupType.StartNode;
return content.Type;
}
}
}