Exemple #1
0
        public InfoLine(string line, InfoSection section)
        {
            _section = section;

            // line should look like either
            //    foo=bar
            //    foo,bar=baz

            // remove any comments at the end
            int comment = line.IndexOf("//");

            if (comment >= 0)
            {
                line = line.Substring(0, comment).Trim();
            }

            // break apart the line
            //MatchCollection matches = Regex.Matches(line, @"([\w]+={[^}]+}?)|[^,]+");
            MatchCollection matches = Regex.Matches(line, @"([\w\.\t ]+={[^}]+})|([\w\.\t ]+=[^,]+)|([\w\.\-]+)");

            // each match represents a piece of data, either a single 'key'
            // or something like 'key=value' (where value could be something
            // like '{1,2,3}')
            foreach (Match match in matches)
            {
                if (match.Success == false)
                {
                    throw new InfoResourceException("??", line + " failed regex");
                }

                int equals = match.Value.IndexOf('=');

                // check for a value sitting at the beginning of the line without a '='
                if (equals == -1 && _attributes.Count == 0 && _value == null)
                {
                    _value = match.Value;
                }
                else
                {
                    KeyValuePair <string, string> keyvalue;

                    if (equals == -1)
                    {
                        // assume it's a boolean flag thingy
                        keyvalue = new KeyValuePair <string, string>(match.Value, "true");
                    }
                    else
                    {
                        keyvalue = new KeyValuePair <string, string>
                                   (
                            match.Value.Substring(0, equals).Trim(),
                            match.Value.Substring(equals + 1).Trim()
                                   );
                    }

                    _attributes.Add(keyvalue);
                }
            }
        }
Exemple #2
0
        public InfoResource(string name, System.IO.Stream stream)
            : base(name, stream)
        {
            int currentIndex = 0;

            string[] lines = Text.Split('\n');

            // parse the global section
            _globalSection = new InfoSection(lines, ref currentIndex, true);

            // parse the rest
            while (currentIndex < lines.Length - 1)
            {
                InfoSection section = new InfoSection(lines, ref currentIndex, false);

                _sections.Add(section);
            }
        }