public static TextRegion ParseBuffer(SnapshotParser parser, TextRegion parent)
{
for (; !parser.AtEnd(); parser.MoveNext())
{
TextRegion r = TextRegion.TryCreateRegion(parser);
if (r != null)
{
parser.MoveNext();
//found the start of the region
if (!r.Complete)
{
//searching for child regions
while (TextRegion.ParseBuffer(parser, r) != null) ;
//found everything
r.ExtendStartPoint();
}
//adding to children or merging with last child
r.Parent = parent;
parent.Children.Add(r);
return r;
}
//found parent's end - terminating parsing
if (parent.TryComplete(parser))
{
parser.MoveNext();
return null;
}
}
return null;
}