private static List <Field> ParseField(string p) { string[] num = p.Split(new char[] { '-' }); if (num.Length == 1) // single field such as A R * 1 2 5 { if (num[0].Contains("+")) { return(ParseAppend(num[0])); } else if (ParseClass.IsAllDigits(num[0])) { return(new List <Field>() { new Field(Int32.Parse(num[0]) - 1) }); } else if (IsValidField(num[0])) { return(new List <Field>() { new Field(num[0]) }); } else { throw new Exception(String.Format("Unable to parse fields |{0}| (Expected A R * 1 2 1+2, etc)", p)); } } else if (num.Length == 2) // multiple such as 1-10 3-4 6-1 { if (ParseClass.IsAllDigits(num[0]) && ParseClass.IsAllDigits(num[1])) { List <Field> list = new List <Field>(); int n1 = Int32.Parse(num[0]); int n2 = Int32.Parse(num[1]); int diff = (n1 < n2 ? 1 : -1); for (int i = n1; i != (n2 + diff); i += diff) { Field f = new Field(i - 1); list.Add(f); } return(list); } else { throw new Exception(String.Format("Unable to parse fields |{0}| (Expected two numbers in range?)", p)); } } throw new Exception(String.Format("Unable to parse fields |{0}|", p)); }
private static List <Field> ParseAppend(string p) { string[] num = p.Split(new char[] { '+' }); if (num.Length < 2) { throw new Exception(String.Format("Unable to parse the append fields |{0}| (Expected multiple fields?)", p)); } Field app = new Field(); for (int i = 0; i < num.Length; ++i) { if (ParseClass.IsAllDigits(num[i])) { int fn = Int32.Parse(num[i]); app.FieldNums.Add(fn - 1); } } return(new List <Field>() { app }); }