Beispiel #1
0
        internal static DataLine CreateNew(PO.Entry entry, DataLine.Kinds kind, int?index, bool isContinuation, IO.TextLine addRelativeTo, bool addRelativeToBefore, string text)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            if (addRelativeTo == null)
            {
                throw new ArgumentNullException("addRelativeTo");
            }
            int insertAt = entry.File.TextFile.Lines.IndexOf(addRelativeTo);

            if (insertAt < 0)
            {
                throw new ArgumentOutOfRangeException("addRelativeTo");
            }
            if (!addRelativeToBefore)
            {
                insertAt++;
            }
            IO.TextLine textLine = new IO.TextLine(BuildTextFileData(kind, index, isContinuation, text));
            entry.File.TextFile.Lines.Insert(insertAt, textLine);
            DataLine result;

            if (index.HasValue)
            {
                result = new IndexedDataLine(entry.File, textLine, isContinuation, kind, text, index.Value);
            }
            else
            {
                result = new DataLine(entry.File, textLine, isContinuation, kind, text);
            }
            entry.LineAdded(result);
            return(result);
        }
Beispiel #2
0
        private static string BuildTextFileData(DataLine.Kinds kind, int?index, bool isContinuation, string text)
        {
            StringBuilder res = new StringBuilder();

            if (!isContinuation)
            {
                switch (kind)
                {
                case Kinds.Context:
                    res.Append("msgctxt ");
                    break;

                case Kinds.ID:
                    res.Append("msgid ");
                    break;

                case Kinds.IDPlural:
                    res.Append("msgid_plural ");
                    break;

                case Kinds.Translated:
                    res.Append("msgstr ");
                    break;

                case Kinds.TranslatedIndexed:
                    res.Append("msgstr[").Append(index.Value).Append("] ");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            res.Append('"');
            if (!string.IsNullOrEmpty(text))
            {
                res.Append(text);
            }
            res.Append('"');
            return(res.ToString());
        }
Beispiel #3
0
 internal IndexedDataLine(POFile file, IO.TextLine source, bool isContinuation, DataLine.Kinds kind, string text, int index)
     : base(file, source, isContinuation, kind, text)
 {
     this._index = index;
 }
Beispiel #4
0
 protected DataLine(POFile file, IO.TextLine source, bool isContinuation, DataLine.Kinds kind, string text)
     : base(file, source, Line.Types.Data, isContinuation, text)
 {
     this._kind = kind;
 }
Beispiel #5
0
 protected DataLine(POFile file, IO.TextLine source, bool isContinuation, DataLine.Kinds kind, string text)
     : base(file, source, Line.Types.Data, isContinuation, text)
 {
     this._kind = kind;
 }