Example #1
0
        /// <summary>
        /// Loads property values from a given character stream.
        /// </summary>
        /// <param name="propertyStream">A stream providing text, like that of a file.</param>
        public void Load(Stream propertyStream)
        {
            // Open the stream for reading
            using (StreamReader reader = new StreamReader(propertyStream, Encoding.GetEncoding("ISO-8859-1")))
            {
                // open the lexers/parsers to generate key-value pairs
                AntlrInputStream  inputStream = new AntlrInputStream(reader);
                JPropertiesLexer  lexer       = new JPropertiesLexer(inputStream);
                CommonTokenStream tokenStream = new CommonTokenStream(lexer);
                JPropertiesParser parser      = new JPropertiesParser(tokenStream);

                // See the grammar spec for more information
                JPropertiesParser.FileContext file = parser.file();
                if (file != null)
                {
                    // Grab all natural lines in the properties
                    JPropertiesParser.LineContext[] lines = file.line();
                    if (lines != null)
                    {
                        // Not all lines have a key-value pair as per spec
                        foreach (var line in lines)
                        {
                            JPropertiesParser.PropertyContext prop = line.property();
                            if (prop != null)
                            {
                                // Store key-value pair
                                JPropertiesParser.KeyContext   key   = prop.key();
                                JPropertiesParser.ValueContext value = prop.value();
                                base.Add(key.GetText(), value == null ? "" : Regex.Unescape(value.GetText()));
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Exit a parse tree produced by <see cref="JPropertiesParser.value"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitValue([NotNull] JPropertiesParser.ValueContext context)
 {
 }