// // Internal Exceptions End // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // Grammar // // // POData = POItem * // POItem = MessageId String MessageString String // String = ( Quote OriginalString Quote ) + // POData ParseData() { POData poData = new POData(); while (LookAhead().Name != TokenName.End) { var item = ParseItem(); if (item.Key == "") { if (poData.Header.Count != 0) { throw new ItemDuplicateException(_currentLine, _currentColumn); } else { poData.Header = ParseHeader(item.Value); } } else { if (poData.Content.Keys.Contains(item.Key)) { throw new ItemDuplicateException(_currentLine, _currentColumn); } else { poData.Content.Add(item.Key, item.Value); } } } return(poData); }
public static string WriteToString(POData poData, string lineEnding = "\r\n") { string poText = ""; poText += GetHeaderString(poData.Header, lineEnding) + lineEnding; foreach (var pair in poData.Content) { poText += GetItemString(pair.Key, pair.Value, lineEnding) + lineEnding; } return(poText); }
public static void WriteToFile(POData poData, string poFile, bool writeBom = false, string lineEnding = "\r\n") { string poText = WriteToString(poData, lineEnding); byte[] bytes = Encoding.UTF8.GetBytes(poText); FileStream fs = new FileStream(poFile, FileMode.Create, FileAccess.Write, FileShare.None); if (writeBom) { byte[] bom = { 0xef, 0xbb, 0xbf }; fs.Write(bom, 0, bom.Length); } fs.Write(bytes, 0, bytes.Length); fs.Close(); }