Example #1
0
        private static void ParseSingleLineProperties(string text, TopicPropertyCollection properties)
        {
            Regex propertyPattern = new Regex(c_propertyPattern, RegexOptions.Multiline);

            foreach (Match match in propertyPattern.Matches(text))
            {
                string name = match.Groups["name"].Value;
                string rawValue = match.Groups["val"].Value.Trim();

                TopicProperty topicProperty = null;
                if (!properties.Contains(name))
                {
                    topicProperty = new TopicProperty(name);
                    properties.Add(topicProperty);
                }
                else
                {
                    topicProperty = properties[name];
                }

                TopicPropertyValue value = new TopicPropertyValue(rawValue);

                topicProperty.Values.Add(value);

            }
        }
Example #2
0
        private static void ParseMultiLineProperties(string text, TopicPropertyCollection properties)
        {
            string[] lines = text.Split('\n');

            Regex propertyPattern = s_multilinePropertyRegex;
            bool inMultilineProperty = false;

            string currentProperty = null;
            string endDelimiter = null;

            StringBuilder rawValueBuilder = new StringBuilder();

            foreach (string line in lines)
            {
                if (inMultilineProperty)
                {
                    if (endDelimiter != null && line.Trim() == endDelimiter)
                    {
                        inMultilineProperty = false;

                        TopicProperty property = new TopicProperty(currentProperty);
                        property.Values.Add(new TopicPropertyValue(rawValueBuilder.ToString()));

                        properties.Add(property);
                    }
                    else
                    {
                        rawValueBuilder.Append(line);
                        rawValueBuilder.Append("\n");
                    }
                }
                else
                {
                    Match match = propertyPattern.Match(line);
                    if (match.Success)
                    {
                        inMultilineProperty = true;
                        currentProperty = match.Groups["name"].Value;
                        string delimiter = match.Groups["delim"].Value;

                        switch (delimiter)
                        {
                            case "[":
                                endDelimiter = "]";
                                break;
                            case "{":
                                endDelimiter = "}";
                                break;
                            default:
                                endDelimiter = null;
                                break;
                        }

                        string rawValue = match.Groups["val"].Value.Trim();

                        rawValueBuilder.Length = 0;
                        rawValueBuilder.Append(rawValue);
                    }
                }
            }
        }