Exemple #1
0
        public static void Generate(this POGenerator @this, StringBuilder output, POCatalog catalog)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            using (var writer = new StringWriter(output))
                @this.Generate(writer, catalog);
        }
Exemple #2
0
        internal POParseResult(POCatalog catalog, DiagnosticCollection diagnostics)
        {
            if (diagnostics == null)
            {
                throw new ArgumentNullException(nameof(diagnostics));
            }

            Catalog      = catalog;
            _diagnostics = diagnostics;
        }
Exemple #3
0
        public POParseResult Parse(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _reader = reader;

            _diagnostics = new DiagnosticCollection();
            _catalog     = new POCatalog();

            _line      = null;
            _lineIndex = -1;

            // resets _commentBuffer and _columnIndex
            SeekNextToken();

            try
            {
                if (!TryReadEntry(allowEmptyId: true, result: out IPOEntry entry))
                {
                    return(new POParseResult(_catalog, _diagnostics));
                }

                var isHeader = CheckHeader(entry);
                if (isHeader)
                {
                    ParseHeader((POSingularEntry)entry);
                }

                if (!_flags.HasFlag(Flags.ReadHeaderOnly))
                {
                    if (!isHeader)
                    {
                        _catalog.Add(entry);
                    }

                    while (TryReadEntry(allowEmptyId: false, result: out entry))
                    {
                        _catalog.Add(entry);
                    }
                }

                return(new POParseResult(_catalog, _diagnostics));
            }
            finally
            {
                _builder.Clear();
                if (_builder.Capacity > 1024)
                {
                    _builder.Capacity = 1024;
                }
            }
        }
Exemple #4
0
        public void Generate(TextWriter writer, POCatalog catalog)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (catalog == null)
            {
                throw new ArgumentNullException(nameof(catalog));
            }

            if (!HasFlags(Flags.IgnoreEncoding))
            {
                if (writer.Encoding.GetByteCount(" ") > 1)
                {
                    throw new ArgumentException(Resources.EncodingNotSingleByte, nameof(writer));
                }

                if (catalog.Encoding == null || Encoding.GetEncoding(catalog.Encoding).WebName != writer.Encoding.WebName)
                {
                    throw new ArgumentException(Resources.EncodingMismatch, nameof(writer));
                }
            }

            _writer  = writer;
            _catalog = catalog;

            _stringBreak    = "\"" + _writer.NewLine + "\"";
            _lineStartIndex = 0;

            try
            {
                IPOEntry entry = CreateHeaderEntry();
                if (entry != null)
                {
                    WriteEntry(entry);
                }

                var n = catalog.Count;
                for (var i = 0; i < n; i++)
                {
                    _writer.WriteLine();
                    WriteEntry(catalog[i]);
                }
            }
            finally
            {
                _builder.Clear();
                if (_builder.Capacity > 1024)
                {
                    _builder.Capacity = 1024;
                }
            }
        }
Exemple #5
0
        public void Generate(TextWriter writer, POCatalog catalog)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (catalog == null)
            {
                throw new ArgumentNullException(nameof(catalog));
            }

            if ((_flags & Flags.IgnoreEncoding) == Flags.None)
            {
                if (writer.Encoding.GetByteCount(" ") > 1)
                {
                    throw new InvalidOperationException(Resources.EncodingNotSingleByte);
                }

                if (catalog.Encoding == null || Encoding.GetEncoding(catalog.Encoding).WebName != writer.Encoding.WebName)
                {
                    throw new InvalidOperationException(Resources.EncodingMismatch);
                }
            }

            _writer  = writer;
            _catalog = catalog;

            try
            {
                _lineStartIndex = 0;

                var entry = CreateHeaderEntry();
                if (entry != null)
                {
                    WriteEntry(entry);
                }

                var n = catalog.Count;
                for (var i = 0; i < n; i++)
                {
                    _writer.WriteLine();
                    WriteEntry(catalog[i]);
                }
            }
            finally
            {
                _builder.Clear();
                if (_builder.Capacity > 1024)
                {
                    _builder.Capacity = 1024;
                }
            }
        }
Exemple #6
0
        public POCatalog(POCatalog catalog) : this()
        {
            if (catalog == null)
            {
                throw new ArgumentNullException(nameof(catalog));
            }

            foreach (var item in catalog)
            {
                Add(item);
            }
        }
Exemple #7
0
        public static void Generate(this POGenerator @this, Stream output, POCatalog catalog)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var writer = new StreamWriter(output);

            @this.Generate(writer, catalog);
            writer.Flush();
        }
Exemple #8
0
        public static void Generate(this POGenerator generator, Stream output, POCatalog catalog, Encoding encoding)
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var writer = new StreamWriter(output, encoding);

            generator.Generate(writer, catalog);
            writer.Flush();
        }
Exemple #9
0
 public POCatalog(POCatalog catalog)
     : this((catalog ?? throw new ArgumentNullException(nameof(catalog))).AsEnumerable <IPOEntry>())