| 3885 | } |
| 3886 | |
| 3887 | TextPosition TextDocument::getMatchingBracket( TextPosition sp, |
| 3888 | const String::StringBaseType& openBracket, |
| 3889 | const String::StringBaseType& closeBracket, |
| 3890 | MatchDirection dir, bool allowDepth, Time timeout ) { |
| 3891 | SyntaxHighlighter* highlighter = getHighlighter(); |
| 3892 | int depth = 0; |
| 3893 | Clock c; |
| 3894 | while ( sp.isValid() && ( timeout == Time::Zero || c.getElapsedTime() < timeout ) ) { |
| 3895 | auto byte = getCharFromUnsanitizedPosition( sp ); |
| 3896 | if ( byte == openBracket ) { |
| 3897 | changeDepth( highlighter, depth, sp, 1 ); |
| 3898 | if ( depth == 0 ) |
| 3899 | return sp; |
| 3900 | if ( !allowDepth && depth > 1 ) |
| 3901 | return {}; |
| 3902 | } else if ( byte == closeBracket ) { |
| 3903 | changeDepth( highlighter, depth, sp, -1 ); |
| 3904 | if ( depth == 0 ) |
| 3905 | return sp; |
| 3906 | if ( !allowDepth && depth > 1 ) |
| 3907 | return {}; |
| 3908 | } |
| 3909 | |
| 3910 | auto prevPos = sp; |
| 3911 | sp = positionOffset( sp, dir == MatchDirection::Forward ? 1 : -1, false ); |
| 3912 | if ( sp == prevPos ) |
| 3913 | return {}; |
| 3914 | } |
| 3915 | return {}; |
| 3916 | } |
| 3917 | |
| 3918 | TextRange TextDocument::getMatchingBracket( TextPosition start, const String& openBracket, |
| 3919 | const String& closeBracket, MatchDirection dir, |
no test coverage detected