public static SatakamData ExtractSatakamFromFile(string fileName) { string[] Lines = File.ReadAllLines(fileName); SatakamData S = ExtractSatakam(Lines); return(S); }
public static void Write2File(string fileName, SatakamData SD) { StringBuilder sb = new StringBuilder(); switch (SD.Format) { case Format.Format1: sb.AppendLine("#FORMAT-1"); break; default: sb.AppendLine("#"); break; } sb.AppendLine("#" + SD.Title); foreach (string header in SD.Header) { sb.AppendLine((header.StartsWith("#") ? "" : "#") + header); } foreach (Poem poem in SD.Poems) { sb.AppendLine(poem.Text.Replace("\n", "\\n")); } foreach (string footer in SD.Footer) { sb.AppendLine((footer.StartsWith("#") ? "" : "#") + footer); } File.WriteAllText(fileName, sb.ToString()); }
public static string Build(SatakamData S, MatchOptions Options) { return(Build(S, Options, new OutputOptions { UseFullName = false, ErrorsOnly = false })); }
public static string Build(SatakamData S, MatchOptions Options, OutputOptions OO) { return(Build(S.Poems.ToArray(), S.Title, S.HeaderString, S.FooterString, Options, OO)); }
public static SatakamData ExtractSatakam(string[] Lines) { List <string> Header = new List <string>(); List <string> Footer = new List <string>(); bool dueFooter = false; SatakamData S = new SatakamData(); List <Poem> Poems = new List <Poem>(); for (int i = 0; i < Lines.Length; i++) { string line = Lines[i]; #region FirstLine-Format if (i == 0) { switch (line) { case "#FORMAT-1": S.Format = Format.Format1; continue; case "#FORMAT-2": S.Format = Format.Format2; continue; default: S.Format = Format.Unknown; continue; } } #endregion #region SecondLine-Title if (i == 1) { S.Title = line.Replace("#", ""); continue; } #endregion if (line.StartsWith("#")) { if (dueFooter) { Footer.Add(line.Replace("#", "")); } else { Header.Add(line.Replace("#", "")); } } else { dueFooter = true; switch (S.Format) { case Format.Format1: Poem P = new Poem(); P.Text = line.Replace("\\n", "\n"); Poems.Add(P); break; default: break; } } } S.Header = Header; S.Footer = Footer; S.Poems = Poems; return(S); }