| 3238 | } |
| 3239 | |
| 3240 | static FindTypeResult findLastType( const String& str, const String& findStr, |
| 3241 | const TextDocument::FindReplaceType& type, |
| 3242 | bool caseSensitive ) { |
| 3243 | switch ( type ) { |
| 3244 | case TextDocument::FindReplaceType::RegEx: { |
| 3245 | // TODO: Implement findLastType for RegEx |
| 3246 | RegEx words( findStr.toUtf8(), |
| 3247 | static_cast<RegEx::Options>( RegEx::Options::Utf | |
| 3248 | ( !caseSensitive ? RegEx::Options::Caseless |
| 3249 | : RegEx::Options::None ) ) ); |
| 3250 | if ( !words.isValid() ) |
| 3251 | return { String::StringType::npos, String::StringType::npos }; |
| 3252 | RegEx::Range matches[MAX_CAPTURES]; |
| 3253 | if ( words.matches( str, matches ) ) { |
| 3254 | FindTypeResult result{ static_cast<size_t>( matches[0].start ), |
| 3255 | static_cast<size_t>( matches[0].end ) }; |
| 3256 | if ( words.getNumMatches() > 1 ) { |
| 3257 | std::vector<TextPosition> captures; |
| 3258 | captures.reserve( words.getNumMatches() - 1 ); |
| 3259 | for ( size_t i = 1; i < words.getNumMatches(); i++ ) { |
| 3260 | result.captures.emplace_back( |
| 3261 | PatternMatcher::Range{ matches[i].start, matches[i].end } ); |
| 3262 | } |
| 3263 | } |
| 3264 | return result; |
| 3265 | } else { |
| 3266 | return { String::StringType::npos, String::StringType::npos }; |
| 3267 | } |
| 3268 | } |
| 3269 | case TextDocument::FindReplaceType::LuaPattern: { |
| 3270 | // TODO: Implement findLastType for Lua patterns |
| 3271 | LuaPatternStorage words( findStr.toUtf8() ); |
| 3272 | PatternMatcher::Range matches[MAX_CAPTURES]; |
| 3273 | if ( words.matches( str, matches ) ) { |
| 3274 | FindTypeResult result{ static_cast<size_t>( matches[0].start ), |
| 3275 | static_cast<size_t>( matches[0].end ) }; |
| 3276 | if ( words.getNumMatches() > 1 ) { |
| 3277 | std::vector<TextPosition> captures; |
| 3278 | captures.reserve( words.getNumMatches() - 1 ); |
| 3279 | for ( size_t i = 1; i < words.getNumMatches(); i++ ) { |
| 3280 | result.captures.emplace_back( |
| 3281 | PatternMatcher::Range{ matches[i].start, matches[i].end } ); |
| 3282 | } |
| 3283 | } |
| 3284 | return result; |
| 3285 | } else { |
| 3286 | return { String::StringType::npos, String::StringType::npos }; |
| 3287 | } |
| 3288 | } |
| 3289 | case TextDocument::FindReplaceType::Normal: |
| 3290 | default: { |
| 3291 | size_t res = str.rfind( findStr ); |
| 3292 | return { res, String::InvalidPos == res ? res : res + findStr.size() }; |
| 3293 | } |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | TextDocument::SearchResult toSearchResult( TextDocument* doc, const Int64 line, |