コード例 #1
0
ファイル: YamlNode.cs プロジェクト: Interreto/.net
 public YamlNode(String name)
 {
     _mName = name;
     _mType = typeof(String);
     _mParameters = new Dictionary<string, string>();
     _mChilds = null;
     _mParrent = null;
 }
コード例 #2
0
ファイル: Operations.cs プロジェクト: Interreto/.net
        private void Parse(ref TextReader reader)
        {
            YamlNode node = null;

            String sequence = string.Empty;
            String name = string.Empty;

            bool isParametr = false;

            var line = new StringBuilder();
            while (reader.Peek() >= 0)
            {
                line.Remove(0, line.Length);
                line.AppendLine(reader.ReadLine());

                var match = Regex.Match(line.ToString(), @"^(.*?):", RegexOptions.Compiled);
                if (match.Success)
                {
                    name = match.Value.Replace(":", string.Empty).Trim();
                    if ((match.Value.Substring(0, 1) != " ") && (match.Value.Substring(0, 1) != "-"))
                    {
                        sequence = name;
                        continue;
                    }
                }

                var value = line.Remove(match.Index, match.Length).ToString();
                if (match.Success)
                {
                    if (name.Contains("-"))
                    {
                        isParametr = true;

                        if (node != null) 
                            node.Parameters.Add(name.Replace("-", string.Empty).Trim(), value.Trim());
                    }
                    else
                    {
                        isParametr = false;

                        node = new YamlNode(name) {Value = value.Trim()};

                        switch (sequence)
                        {
                            case "Settings":
                                m_Settings.Add(node.Name, node);
                                break;
                            case "Operations":
                                _mOperations.Add(node);
                                break;
                        }
                    }
                }
                else
                {
                    if (node != null)
                        if (isParametr)
                            node.Parameters[name.Replace("-", string.Empty).Trim()] += value;
                        else
                            node.Value += value;
                }
                line.Remove(0, line.Length);
            } //while (reader.Peek() >= 0)
        }