Example #1
0
 /// <summary>
 /// Parses a given stream and applies an action to each token found
 /// </summary>
 /// <param name="data">Stream to parse</param>
 /// <param name="parseStrategy">Action to be performed on found tokens</param>
 public static void Parse(Stream data, Action <ParadoxParser, string> parseStrategy)
 {
     using (ParadoxParser parser = new ParadoxParser(data))
     {
         while (!parser.EndOfStream)
         {
             parseStrategy(parser, parser.ReadString());
         }
     }
 }
Example #2
0
        /// <summary>
        /// Given a stream, the function will deserialize it into a
        /// specific type.
        /// </summary>
        /// <typeparam name="T">The type to deserialize</typeparam>
        /// <param name="data">The stream to extract the object</param>
        /// <returns>The object deserialized from the stream</returns>
        public static T Deserialize <T>(Stream data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (var reader = new StreamReader(data, Globals.ParadoxEncoding, false, MaxByteBuffer))
            {
                FnPtr         ptr    = Deserializer.Parse(typeof(T));
                ParadoxParser parser = new ParadoxParser(reader);
                return((T)ptr(parser));
            }
        }
Example #3
0
        /// <summary>
        /// Parses a given stream and applies an action to each token found
        /// </summary>
        /// <param name="data">Stream to parse</param>
        /// <param name="parseStrategy">Action to be performed on found tokens</param>
        public static void Parse(Stream data, Action <ParadoxParser, string> parseStrategy)
        {
            using (ParadoxParser parser = new ParadoxParser(data))
            {
                while (!parser.EndOfStream)
                {
                    string val = parser.ReadString();

                    // if val is the null string then nothing of importance
                    // was found between the last token and the end of the stream
                    if (val != "\0")
                    {
                        parseStrategy(parser, val);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Parses a given stream and applies an action to each token found
        /// </summary>
        /// <param name="data">Stream to parse</param>
        /// <param name="parseStrategy">Action to be performed on found tokens</param>
        public static void Parse(Stream data, Action <ParadoxParser, string> parseStrategy)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (var reader = new StreamReader(data, Globals.ParadoxEncoding, false, MaxByteBuffer))
            {
                ParadoxParser parser = new ParadoxParser(reader);
                while (!parser.EndOfStream)
                {
                    string val = parser.ReadString();

                    // if val is the null string then nothing of importance
                    // was found between the last token and the end of the stream
                    if (val != "\0")
                    {
                        parseStrategy(parser, val);
                    }
                }
            }
        }