public TextGridItem(TextGridItem item) { Sanity.Requires(Type == item.Type, "The two TextGridItem are different."); TierIndex = item.TierIndex; Index = item.Index; Name = item.Name; IsSet = item.IsSet; Text = item.Text; }
public TextGridPoint(TextGridItem item) : base(item) { Type = TextGridItemType.Point; }
public TextGridInterval(TextGridItem item) : base(item) { Type = TextGridItemType.Interval; }
private IEnumerable <TextGridItem> Parse(IEnumerable <string> list) { TextGridItem currentItem = new TextGridItem(); TextGridInterval currentInterval = new TextGridInterval(); TextGridPoint currentText = new TextGridPoint(); int currentTier = 0; string currentName = string.Empty; bool inInterval = false; bool inHeader = true; foreach (string line in list) { if (InItemListReg.IsMatch(line)) { currentTier = int.Parse(InItemListReg.Match(line).Groups[1].Value); currentItem.TierIndex = currentTier; inHeader = false; continue; } if (inHeader) { Header.Add(line); } if (NameReg.IsMatch(line)) { currentName = NameReg.Match(line).Groups[1].Value; currentItem.Name = currentName; continue; } if (IntervalReg.IsMatch(line)) { inInterval = true; currentItem.Index = int.Parse(IntervalReg.Match(line).Groups[1].Value); currentInterval = new TextGridInterval(currentItem); currentInterval.IsSet = true; currentItem = new TextGridItem { Name = currentName, TierIndex = currentTier }; continue; } if (line.Trim().StartsWith("xmin") && inInterval) { Sanity.Requires(currentInterval.IsSet, "Invalid format."); currentInterval.XMin = double.Parse(line.Split('=')[1].Trim()); continue; } if (line.Trim().StartsWith("xmax") && inInterval) { Sanity.Requires(currentInterval.IsSet, "Invalid format."); currentInterval.XMax = double.Parse(line.Split('=')[1].Trim()); continue; } if (line.Trim().StartsWith("text")) { Sanity.Requires(currentInterval.IsSet, "Invalid format."); currentInterval.Text = line.Split('=')[1].Trim(Trims); inInterval = false; yield return(currentInterval); continue; } if (PointReg.IsMatch(line)) { currentItem.Index = int.Parse(PointReg.Match(line).Groups[1].Value); currentText = new TextGridPoint(currentItem); currentText.IsSet = true; currentItem = new TextGridItem { Name = currentName, TierIndex = currentTier }; } if (line.Trim().StartsWith("number")) { Sanity.Requires(currentText.IsSet, "Invalid format"); currentText.Point = double.Parse(line.Split('=')[1].Trim(Trims)); continue; } if (line.Trim().StartsWith("mark")) { Sanity.Requires(currentText.IsSet, "Invalid format"); currentText.Text = line.Split('=')[1].Trim(Trims); yield return(currentText); continue; } } }