MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / BraceMatch

Method BraceMatch

scintilla/src/Document.cxx:2029–2057  ·  view source on GitHub ↗

TODO: should be able to extend styled region to find matching brace

Source from the content-addressed store, hash-verified

2027
2028// TODO: should be able to extend styled region to find matching brace
2029int Document::BraceMatch(int position, int /*maxReStyle*/) {
2030 char chBrace = CharAt(position);
2031 char chSeek = BraceOpposite(chBrace);
2032 if (chSeek == '\0')
2033 return - 1;
2034 char styBrace = static_cast<char>(StyleAt(position) & stylingBitsMask);
2035 int direction = -1;
2036 if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<')
2037 direction = 1;
2038 int depth = 1;
2039 position = NextPosition(position, direction);
2040 while ((position >= 0) && (position < Length())) {
2041 char chAtPos = CharAt(position);
2042 char styAtPos = static_cast<char>(StyleAt(position) & stylingBitsMask);
2043 if ((position > GetEndStyled()) || (styAtPos == styBrace)) {
2044 if (chAtPos == chBrace)
2045 depth++;
2046 if (chAtPos == chSeek)
2047 depth--;
2048 if (depth == 0)
2049 return position;
2050 }
2051 int positionBeforeMove = position;
2052 position = NextPosition(position, direction);
2053 if (position == positionBeforeMove)
2054 break;
2055 }
2056 return - 1;
2057}
2058
2059/**
2060 * Implementation of RegexSearchBase for the default built-in regular expression engine

Callers 1

WndProcMethod · 0.80

Calls 1

BraceOppositeFunction · 0.85

Tested by

no test coverage detected