Nintenlord.Event_Assembler.Core.Code.PreprocessingInputStream.ReadLine C# (CSharp) Method

ReadLine() public method

public ReadLine ( ) : string
return string
        public string ReadLine()
        {
            if (positions.Count == 0)
                return null;

            if (unreadLines.Count > 0)
            {
                string line = unreadLines.First;
                unreadLines.RemoveFirst();
                return line;
            }
            else
            {
                PrimitiveStream currentData = positions.Peek();
                string line;

                if (currentData.ReadLine(out line))
                {
                    string pros = preprocessor.Process(line, this);
                    var codes = pros.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 1; i < codes.Length; i++)
                    {
                        unreadLines.Add(codes[0]);
                    }

                    return codes.Length == 0 ? ReadLine() : codes[0];
                }
                else //End of file
                {
                    positions.Pop();
                    if (positions.Count > 0)
                    {
                        currentData.Close();
                    }
                    return ReadLine();
                }
            }
        }

Usage Example

Exemplo n.º 1
0
        public static void Preprocess(string originalFile, string outputFile, string game, ILog messageLog)
        {
            EACodeLanguage language = languages[game];

            var predefined = new[]
            {
                "_" + game + "_",
                "_EA_"
            };

            using (var preprocessor = new Preprocessor(messageLog))
            {
                preprocessor.AddReserved(language.GetCodeNames());
                preprocessor.AddDefined(predefined);

                using (var reader = File.OpenText(originalFile))
                {
                    var stream = new PreprocessingInputStream(reader, preprocessor);

                    var writer = new StringWriter();
                    while (true)
                    {
                        string line = stream.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        writer.WriteLine(line);
                    }
                    messageLog.AddMessage("Processed code:\n" + writer + "\nEnd processed code");
                    //File.WriteAllText(outputFile, writer.ToString());

                }
            }
        }