示例#1
0
        public void addChild(KeyValue value)
        {
            if (!childrenIndex.ContainsKey(value.getKey()))
            {
                childrenIndex.Add(value.getKey(), new List <KeyValue>());
            }

            childrenIndex[value.getKey()].Add(value);
            children.Add(value);
        }
示例#2
0
        private static List <string> writeChunkFileTraverse(KeyValue node, int level, bool quotes)
        {
            List <string> lines = new List <string>();

            string tabs = string.Empty;

            for (int i = 0; i < level; i++)
            {
                tabs = tabs + "\t";
            }

            if (node.isParentKey()) // It's a parent key
            {
                if (node.key != string.Empty)
                {
                    lines.Add(tabs + (quotes ? "\"" : string.Empty) + node.key + (quotes ? "\"" : string.Empty));
                    lines.Add(tabs + "{");
                }

                foreach (KeyValue entry in node.getChildren())
                {
                    lines.AddRange(writeChunkFileTraverse(entry, level + 1, quotes));
                }

                if (node.key != string.Empty)
                {
                    lines.Add(tabs + "}");
                }
            }
            else if (node.getKey() != string.Empty && node.getValue() != null)   // It's a value key
            {
                string line = tabs;
                if (node.key != string.Empty)
                {
                    line = line +
                           (quotes ? "\"" : string.Empty) +
                           node.key +
                           (quotes ? "\"" : string.Empty) +
                           "\t\"" +
                           node.value +
                           "\"";
                }
                if (node.comment != string.Empty)
                {
                    if (node.key != string.Empty)
                    {
                        line = line + "\t";
                    }

                    line = line + "//" + node.comment;
                }

                lines.Add(line);
            }
            else if (node.comment != string.Empty)   // Comment line
            {
                string line = tabs + "//" + node.comment;
                lines.Add(line);
            }
            else if (node.key == string.Empty)      // Blank line
            {
                lines.Add("");
            }

            return(lines);
        }