TextParser/TextSymbolsParserExtensionMethods.cs
/// <summary>
/// Parses a symbol that might be enclosed in braces. For example if the value of <see cref="ITextSymbolsParserState.PositionInText"/> is 1 in the two texts
/// below " [Table1] (..." Table1 (...", the parsed symbol will be Table1, and the value of <see cref="ITextSymbolsParserState.PositionInText"/> after the method is called will
/// be the position of "(" character.
/// </summary>
Parses a symbol that might be enclosed in braces.
Parses a symbol that might be enclosed in braces .
public static bool ReadSymbolEnclosedInBraces([NotNull] this ITextSymbolsParser textSymbolsParser, bool enclosingBracesAreOptional,
                                                      char openingBrace, char closingBrace,
                                                      [CanBeNull] IsValidSymbolCharacterDelegate isValidSymbolCharacterDelegate = null)
        {
            var startedWithBraces = false;
            if (textSymbolsParser.CurrentChar == openingBrace)
            {
                startedWithBraces = true;
                if (!textSymbolsParser.SkipCurrentCharacterAndSpaces())
                    return false;
            }
            else if (!enclosingBracesAreOptional)
            {
                throw new ParseTextException(new ParseTextErrorDetails(textSymbolsParser.PositionInText, $"Invalid character. Expected '{openingBrace}'."));
            }
            if (!textSymbolsParser.ReadSymbol(isValidSymbolCharacterDelegate))
                return false;
            if (startedWithBraces)
            {
                if (!textSymbolsParser.SkipSpaces())
                    return false;
                if (textSymbolsParser.CurrentChar != closingBrace)
                    return false;
                textSymbolsParser.SkipCurrentCharacterAndSpaces();
            }
            return true;
        }
public static bool ReadSymbolEnclosedInBraces ( [ NotNull ] this ITextSymbolsParser textSymbolsParser , bool enclosingBracesAreOptional , char openingBrace , char closingBrace , [ CanBeNull ] IsValidSymbolCharacterDelegate isValidSymbolCharacterDelegate = null ) { var startedWithBraces = false ; if ( textSymbolsParser . CurrentChar == openingBrace ) { startedWithBraces = true ; if ( ! textSymbolsParser . SkipCurrentCharacterAndSpaces ( ) ) return false ; } else if ( ! enclosingBracesAreOptional ) { throw new ParseTextException ( new ParseTextErrorDetails ( textSymbolsParser . PositionInText , $" Invalid character. Expected ' { openingBrace } '. " ) ) ; } if ( ! textSymbolsParser . ReadSymbol ( isValidSymbolCharacterDelegate ) ) return false ; if ( startedWithBraces ) { if ( ! textSymbolsParser . SkipSpaces ( ) ) return false ; if ( textSymbolsParser . CurrentChar != closingBrace ) return false ; textSymbolsParser . SkipCurrentCharacterAndSpaces ( ) ; } return true ; }
Parses a symbol that might be enclosed in braces.
Parses a symbol that might be enclosed in braces .
this
[NotNull]
enclosingBracesAreOptional
bool
openingBrace
char
closingBrace
char
IsValidSymbolCharacterDelegate
[CanBeNull]