CSharpOutline.TextRegion.TryCreateRegion C# (CSharp) Method

TryCreateRegion() public static method

parses input buffer, searches for region start
public static TryCreateRegion ( SnapshotParser parser ) : TextRegion
parser SnapshotParser
return TextRegion
        public static TextRegion TryCreateRegion(SnapshotParser parser)
        {
            SnapshotPoint point = parser.CurrentPoint;
            ClassificationSpan span = parser.CurrentSpan;
            if (span == null)
            {
                char c = point.GetChar();
                switch (c)
                {
                    case '{':
                        return new TextRegion(point, TextRegionType.Block);
                }
            }
            return null;
        }

Usage Example

Example #1
0
        /// <summary>
        /// parses buffer
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="parent">parent region or null</param>
        /// <returns>a region with its children or null</returns>
        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);
        }