private static CAutamata.Point[] parseNeighborhood(string first, StreamReader reader) { string neighborhood = parseBrackets(first, reader); string[] points = neighborhood.Split(new char[] {';'}); CAutamata.Point[] ret = new CAutamata.Point[points.Length]; for(int i = 0; i < points.Length; i++) { string p = points[i]; string[] parts = p.Split(new char[] {'(',',',')'}); ret[i] = new CAutamata.Point(Int32.Parse(parts[1]), Int32.Parse(parts[2])); } return ret; }
/** * Parse a neighborhood string into an array of points * * First parse the brackets. * Then split by semicolon * Now split each of these by ( ) and , * Each point should have 4 parts. If not the string is incorrectly formatted. Return null. * * @param first The first line * @param reader A Reader to pull subsequent lines from * * @return The neighborhood as a Point[] **/ private static CAutamata.Point[] parseNeighborhood(string first, StreamReader reader) { string neighborhood = parseBrackets(first, reader); string[] points = neighborhood.Split(new char[] {';'}); CAutamata.Point[] ret = new CAutamata.Point[points.Length]; for(int i = 0; i < points.Length; i++) { string p = points[i]; string[] parts = p.Split(new char[] {'(',',',')'}); if (parts.Length != 4) { return null; } int x; int y; if (!int.TryParse(parts[1], out x) || !int.TryParse(parts[2], out y)) { return null; } ret[i] = new CAutamata.Point(x, y); } return ret; }