当前位置: 首页>>代码示例>>C#>>正文


C# KeyValue.ClearChildParents方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:GoeGaming,项目名称:KVLib,代码行数:101,代码来源:PenguinParser.cs


注:本文中的KeyValue.ClearChildParents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。