本文整理汇总了C#中KeyValue.ClearChildParents方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValue.ClearChildParents方法的具体用法?C# KeyValue.ClearChildParents怎么用?C# KeyValue.ClearChildParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValue
的用法示例。
在下文中一共展示了KeyValue.ClearChildParents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseAllKeyValues
//.........这里部分代码省略.........
while (i < contents.Length && contents[i] != '\n')
{
i++;
}
}
}
}
else
{
throw new KeyValueParsingException("Unexpected '" + contents[i].ToString() + "' at position " + i.ToString(), null);
}
break;
case parseEnum.lookingForValue:
if (contents[i] == '{')
{
// it's a list of children
// thankfully, we don't actually need to handle this!
parseState = parseEnum.lookingForKey;
}
else if (contents[i] == '"' || contents[i] == '\'')
{
//quoted value
int j = i + 1;
while (contents[j] != contents[i])
{
// handle escaped quotes
if (contents[j] == '\\')
{
j++;
}
j++;
if (j > contents.Length)
{
throw new KeyValueParsingException("Couldn't find terminating '" + contents[i].ToString() + "' for key started at position " + i.ToString(), null);
}
}
//ok, now contents[i] and contents[j] are the same character, on either end of the value
curparent.Set(contents.Substring(i + 1, j - (i + 1)));
curparent = curparent.Parent;
parseState = parseEnum.lookingForKey;
i = j;
}
else if (contents[i] == '/')
{
if (i + 1 < contents.Length && contents[i + 1] == '/')
{
// we're in a comment! throw stuff away until the next \n
while (i < contents.Length && contents[i] != '\n')
{
i++;
}
}
}
else if (!Char.IsWhiteSpace(contents[i]))
{
int j = i;
while (contents[j] != ' ' && contents[j] != '\t' && contents[j] != '\n' && contents[j] != '\r')
{
j++;
if (j > contents.Length)
{
// a value ending the file counts as ending the value
break;
}
}
curparent.Set(contents.Substring(i, j - i));
curparent = curparent.Parent;
parseState = parseEnum.lookingForKey;
i = j;
}
else
{
throw new KeyValueParsingException("Unexpected '" + contents[i].ToString() + "' at position " + i.ToString(), null);
}
break;
}
}
// At the end of the file, we should be looking for another key
if (parseState != parseEnum.lookingForKey)
{
throw new KeyNotFoundException("File ended while looking for value", null);
}
// At the end of the file, all block values should be closed
if (curparent != basekv)
{
throw new KeyNotFoundException("Unterminated child blocks", null);
}
KeyValue[] ret = basekv.Children.ToArray<KeyValue>();
basekv.ClearChildParents();
return ret;
}
catch (KeyValueParsingException e)
{
throw e;
}
catch (Exception e)
{
throw new KeyValueParsingException("Hit an exception while parsing kv data!", e);
}
}