public LanguageEntry ParseLine(int lineNumber, string line) { var reader = new StringReader(line); ParseWhitespace(reader, lineNumber, 0); char c; if (reader.TryPeek(out c)) { switch (c) { case '#': return(null); case '[': ParseGroupObject(reader, lineNumber); return(null); case '<': ParseGroupScenario(reader, lineNumber); return(null); default: { ParseEntry(reader, lineNumber); LanguageEntry entry; if (LanguageEntry.TryParse(line, out entry)) { return(entry); } } break; } } return(null); }
public static LanguagePack LoadFromFile(string path, IErrorLogger logger) { var parser = new LanguageParser(logger); using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var sr = new StreamReader(fs); var entries = new List <LanguageEntry>(); int lineNumber = 1; string line; while ((line = sr.ReadLine()) != null) { LanguageEntry entry = parser.ParseLine(lineNumber, line); if (entry != null) { entries.Add(entry); } lineNumber++; } return(new LanguagePack(entries)); } }
public static bool TryParse(string line, out LanguageEntry entry) { entry = null; if (line.Length > 8) { string l = line.Substring(4, 4); int id; if (Int32.TryParse(l, out id)) { int colonOffset = line.IndexOf(':'); if (colonOffset != 0) { string text = line.Substring(colonOffset + 1); entry = new LanguageEntry() { Id = id, Text = text }; return true; } } } return false; }
public static bool TryParse(string line, out LanguageEntry entry) { entry = null; if (line.Length > 8) { string l = line.Substring(4, 4); int id; if (Int32.TryParse(l, out id)) { int colonOffset = line.IndexOf(':'); if (colonOffset != 0) { string text = line.Substring(colonOffset + 1); entry = new LanguageEntry() { Id = id, Text = text }; return(true); } } } return(false); }