| 344 | }; |
| 345 | |
| 346 | std::vector<SpellerWordData> SpellChecker::check_text(const MappedWstring &text_to_check) const { |
| 347 | if (text_to_check.str.empty()) |
| 348 | return {}; |
| 349 | auto sv = std::wstring_view(text_to_check.str); |
| 350 | std::vector<std::wstring_view> tokens; |
| 351 | m_settings.do_with_tokenizer(sv, [&](const auto &tokenizer) { tokens = tokenizer.get_all_tokens(); }); |
| 352 | |
| 353 | std::vector<bool> results(tokens.size()); |
| 354 | std::vector<SpellerWordData> words_to_check; |
| 355 | words_to_check.clear(); |
| 356 | std::vector<WordForSpeller> words_for_speller; |
| 357 | for (auto token : tokens) { |
| 358 | SpellCheckerHelpers::cut_apostrophes(m_settings, token); |
| 359 | auto word_start = text_to_check.to_original_index(token.data() - text_to_check.str.data()); |
| 360 | auto word_end = text_to_check.to_original_index( |
| 361 | static_cast<TextPosition>(token.data() - text_to_check.str.data() + token.length())); |
| 362 | if (is_spellchecking_needed(token, word_start)) { |
| 363 | words_to_check.emplace_back(); |
| 364 | auto &w = words_to_check.back(); |
| 365 | w.word_for_speller = to_word_for_speller(token); |
| 366 | w.word_start = word_start; |
| 367 | w.word_end = word_end; |
| 368 | w.token = token; |
| 369 | } |
| 370 | } |
| 371 | words_for_speller.resize(words_to_check.size()); |
| 372 | std::transform(words_to_check.begin(), words_to_check.end(), |
| 373 | words_for_speller.begin(), [](auto &word) -> auto&& { return std::move(word.word_for_speller); }); |
| 374 | auto spellcheck_result = m_speller_container.active_speller().check_words(words_for_speller); |
| 375 | if (!spellcheck_result.empty()) { |
| 376 | for (int i = 0; i < static_cast<int>(words_for_speller.size()); ++i) |
| 377 | words_to_check[i].is_correct = spellcheck_result[i]; |
| 378 | } else |
| 379 | for (auto &w : words_to_check) |
| 380 | w.is_correct = true; |
| 381 | return words_to_check; |
| 382 | } |
| 383 | |
| 384 | void SpellChecker::underline_misspelled_words(const MappedWstring &text_to_check) const { |
| 385 | std::vector<TextPosition> underline_buffer; |
nothing calls this directly
no test coverage detected