/// <summary> /// Tries to parse a text string for takeoff directions. When the text contains /// parenthesis, only the text in the parenthesis is parsed. The takeoff directions can /// be single directions, separated by comma, or direction ranges, separated by a dash, /// or a combination of both. /// </summary> /// <param name="text">text to parse</param> /// <param name="takeoffDirections">flag enum that contains all directions</param> /// <returns>true when parsing was successful, false when not</returns> public static bool TryParse(string text, out TakeoffDirections takeoffDirections) { takeoffDirections = TakeoffDirections.None; int startBracket = text.IndexOf("("); if (startBracket != -1) { int endBracket = text.IndexOf(")", startBracket + 1); if (endBracket != -1) { return(TryParse( text.Substring(startBracket + 1, endBracket - startBracket - 1), out takeoffDirections)); } } text = text.ToUpperInvariant().Replace(" ", string.Empty); if (text.Any((ch) => !IsValidTakeoffChar(ch))) { return(false); } text = text.Replace("O", "E"); // replace german east letter foreach (var range in text.Split(',')) { if (!TryParseDirectionOrRange(range, ref takeoffDirections)) { return(false); } } return(true); }
/// <summary> /// Tries to parse a start direction from given location description. Some locations, e.g. /// from the DHV Geländedatenbank, have the start directions in the description, after a /// certain text. /// </summary> /// <param name="description">location description</param> /// <param name="takeoffDirections">parsed takeoff directions</param> /// <returns>true when a takeoff direction could be parsed, or false when not</returns> private static bool TryParseStartDirectionFromDescription(string description, out TakeoffDirections takeoffDirections) { takeoffDirections = TakeoffDirections.None; const string StartDirectionText = "Startrichtung "; int posStartDirection = description.IndexOf(StartDirectionText); if (posStartDirection == -1) { return(false); } int posLineBreak = description.IndexOf("<br", posStartDirection); if (posLineBreak == -1) { posLineBreak = description.Length; } posStartDirection += StartDirectionText.Length; string direction = description.Substring(posStartDirection, posLineBreak - posStartDirection); return(TakeoffDirectionsHelper.TryParse(direction, out takeoffDirections)); }