public USFMDocument ParseFromString(string input) { Regex splitRegex = new Regex("\\\\([a-z0-9*]+)([^\\\\]*)"); USFMDocument output = new USFMDocument(); foreach (Match match in splitRegex.Matches(input)) { if (IgnoredTags.Contains(match.Groups[1].Value)) { continue; } ConvertToMarkerResult result = ConvertToMarker(match.Groups[1].Value, match.Groups[2].Value); if (result.marker is TRMarker && !output.GetTypesPathToLastMarker().Contains(typeof(TableBlock))) { output.Insert(new TableBlock()); } output.Insert(result.marker); if (!string.IsNullOrWhiteSpace(result.remainingText)) { output.Insert(new TextBlock(result.remainingText)); } } return(output); }
/// <summary> /// Parses a string into a USFMDocument /// </summary> /// <param name="input">A USFM string</param> /// <returns>A USFMDocument representing the input</returns> public USFMDocument ParseFromString(string input) { USFMDocument output = new USFMDocument(); var markers = TokenizeFromString(input); foreach (Marker marker in markers) { if (marker is TRMarker && !output.GetTypesPathToLastMarker().Contains(typeof(TableBlock))) { output.Insert(new TableBlock()); } var markerIndex = markers.IndexOf(marker); if (marker is QMarker && markerIndex != markers.Count - 1 && markers[markerIndex + 1] is VMarker) { ((QMarker)marker).IsPoetryBlock = true; } output.Insert(marker); } return(output); }