private static void DoProcessStyle(Field[] fields, int i) { try { Log.Indent(); string name = fields[i++].Value; Log.WriteLine("Processing {0} style", name); var style = new Style(); while (i < fields.Length && fields[i].Name != "Name") { DoProcessField(style, fields[i++]); } if (!ms_styles.ContainsKey(name)) ms_styles.Add(name, style); else Log.WriteLine("Ignoring style {0} (it was already defined).", name); } catch (Exception e) { Log.WriteLine(e.Message); } finally { Log.Unndent(); } }
private static void DoProcessField(Style style, Field field) { switch (field.Name) { case "BackColor": style.BackColor = DoParseColor(field.Name, field.Value); break; case "Bold": style.Bold = DoParseBool(field.Name, field.Value); break; case "FontName": style.FontName = field.Value; break; case "ForeColor": style.ForeColor = DoParseColor(field.Name, field.Value); break; case "Italic": style.Italic = DoParseBool(field.Name, field.Value); break; case "PointSize": style.PointSize = DoParseDouble(field.Name, field.Value); break; default: Log.WriteLine("Ignoring field {0},", field.Name); break; } }
private static List<KeyValuePair<string, IClassificationType>> DoGetElements(Field[] fields) { var elements = new List<KeyValuePair<string, IClassificationType>>(); elements.Add(new KeyValuePair<string, IClassificationType>(null, ms_elements["Default"])); foreach (var entry in ms_elements) { var candidates = from f in fields where f.Name == entry.Key select f; foreach (Field candidate in candidates) { string regex = candidate.Value; elements.Add(new KeyValuePair<string, IClassificationType>(regex, entry.Value)); } } return elements; }
private static void DoUnusedCheck(Field[] fields) { foreach (Field field in fields) { if (field.Name != "Language" && field.Name != "Globs") if (!ms_elements.Keys.Contains(field.Name)) Log.WriteLine("Ignoring unused field {0}.", field.Name); } }
private static string DoGetField(Field[] fields, string name) { var candidates = from f in fields where f.Name == name select f; int count = candidates.Count(); if (count == 1) return candidates.First().Value; else if (count == 0) throw new Exception(name + " field is missing."); else throw new Exception(name + " field was defined more than once."); }
public static Field[] Parse(string[] lines, Filter filter) { var fields = new List<Item>(); bool canContinue = false; for (int i = 0; i < lines.Length; ++i) { string line = lines[i]; // field if (line.Length > 1 && char.IsLetter(line[0])) { fields.Add(DoParseField(line, i + 1, filter)); canContinue = true; } // continued else if (line.Length > 0 && line[0] == '\t') { if (!canContinue) throw new FormatException("Line " + (i + 1) + " is a continued line, but the previous line is not a field or continued line"); if (filter != null) line = filter(fields[fields.Count - 1].Name, line); fields[fields.Count - 1].Value.Append(line); canContinue = true; } // comment else if (line.Length >= 2 && line.StartsWith("#")) { canContinue = false; continue; } // blank else if (line == "\n" || line == "\r" || line == "\r\n" || line.Length == 0) { canContinue = false; continue; } // error else throw new FormatException("Couldn't parse line " + (i + 1)); } Field[] result = new Field[fields.Count]; for (int j = 0; j < fields.Count; ++j) result[j] = fields[j].ToField(); return result; }