コード例 #1
0
        public CondenserTextReader(PreprocessorTextReader sourceTextReader, bool stripCommentsOnly) {
            Debug.Assert(sourceTextReader != null);
            _sourceTextReader = sourceTextReader;
            _stripCommentsOnly = stripCommentsOnly;

            _peekedCharacter = -1;
            _lastCharacter = ' ';
        }
コード例 #2
0
        public CondenserTextReader(PreprocessorTextReader sourceTextReader, bool stripCommentsOnly)
        {
            Debug.Assert(sourceTextReader != null);
            _sourceTextReader  = sourceTextReader;
            _stripCommentsOnly = stripCommentsOnly;

            _peekedCharacter = -1;
            _lastCharacter   = ' ';
        }
コード例 #3
0
        public void Preprocess(PreprocessorOptions options) {
            Stream outputStream = options.TargetFile.GetStream();
            StreamWriter outputWriter = null;

            PreprocessorTextReader preprocessor = null;
            try {
                if (outputStream != null) {
                    outputWriter = new StreamWriter(outputStream);
                    preprocessor = new PreprocessorTextReader(options.SourceFile,
                                                              options.PreprocessorVariables,
                                                              _includeResolver,
                                                              _scriptInfo);

                    TextReader contentReader = preprocessor;
                    if (options.Minimize) {
                        contentReader = new CondenserTextReader(preprocessor, options.StripCommentsOnly);
                    }

                    if (preprocessor.Initialize(outputWriter)) {
                        int ch;
                        while ((ch = contentReader.Read()) != -1) {
                            if (options.UseWindowsLineBreaks && (ch == '\n')) {
                                outputWriter.Write('\r');
                            }
                            outputWriter.Write((char)ch);
                        }
                    }
                }
            }
            catch (PreprocessorException pe) {
                if (_errorHandler != null) {
                    _errorHandler.ReportError(pe.Message, pe.SourceFile + " (" + pe.Line + ", 1)");
                }

                if (pe.InnerException != null) {
                    throw pe.InnerException;
                }
            }
            finally {
                if (preprocessor != null) {
                    preprocessor.Close();
                }
                if (outputWriter != null) {
                    outputWriter.Flush();
                }
                if (outputStream != null) {
                    options.TargetFile.CloseStream(outputStream);
                }
            }
        }