static void findMisspellings(TextCheckerClient* client, const UChar* text, int start, int length, Vector<TextCheckingResult>& results) { TextBreakIterator* iterator = wordBreakIterator(text + start, length); if (!iterator) return; int wordStart = textBreakCurrent(iterator); while (0 <= wordStart) { int wordEnd = textBreakNext(iterator); if (wordEnd < 0) break; int wordLength = wordEnd - wordStart; int misspellingLocation = -1; int misspellingLength = 0; client->checkSpellingOfString(text + start + wordStart, wordLength, &misspellingLocation, &misspellingLength); if (0 < misspellingLength) { ASSERT(0 <= misspellingLocation && misspellingLocation <= wordLength); ASSERT(0 < misspellingLength && misspellingLocation + misspellingLength <= wordLength); TextCheckingResult misspelling; misspelling.type = TextCheckingTypeSpelling; misspelling.location = start + wordStart + misspellingLocation; misspelling.length = misspellingLength; misspelling.replacement = client->getAutoCorrectSuggestionForMisspelledWord(String(text + misspelling.location, misspelling.length)); results.append(misspelling); } wordStart = wordEnd; } }
static void findMisspellings(TextCheckerClient& client, StringView text, Vector<TextCheckingResult>& results) { TextBreakIterator* iterator = wordBreakIterator(text); if (!iterator) return; for (int wordStart = textBreakCurrent(iterator); wordStart > 0; ) { int wordEnd = textBreakNext(iterator); if (wordEnd < 0) break; int wordLength = wordEnd - wordStart; int misspellingLocation = -1; int misspellingLength = 0; client.checkSpellingOfString(text.substring(wordStart, wordLength), &misspellingLocation, &misspellingLength); if (misspellingLength > 0) { ASSERT(misspellingLocation >= 0); ASSERT(misspellingLocation <= wordLength); ASSERT(misspellingLength > 0); ASSERT(misspellingLocation + misspellingLength <= wordLength); TextCheckingResult misspelling; misspelling.type = TextCheckingTypeSpelling; misspelling.location = wordStart + misspellingLocation; misspelling.length = misspellingLength; misspelling.replacement = client.getAutoCorrectSuggestionForMisspelledWord(text.substring(misspelling.location, misspelling.length).toStringWithoutCopying()); results.append(misspelling); } wordStart = wordEnd; } }
unsigned String::numCharactersInGraphemeClusters(unsigned numGraphemeClusters) const { TextBreakIterator* it = characterBreakIterator(characters(), length()); if (!it) return min(length(), numGraphemeClusters); for (unsigned i = 0; i < numGraphemeClusters; ++i) { if (textBreakNext(it) == TextBreakDone) return length(); } return textBreakCurrent(it); }
unsigned numCharactersInGraphemeClusters(const String& s, unsigned numGraphemeClusters) { NonSharedCharacterBreakIterator it(s.characters(), s.length()); if (!it) return min(s.length(), numGraphemeClusters); for (unsigned i = 0; i < numGraphemeClusters; ++i) { if (textBreakNext(it) == TextBreakDone) return s.length(); } return textBreakCurrent(it); }
unsigned numCharactersInGraphemeClusters(const StringView& s, unsigned numGraphemeClusters) { unsigned stringLength = s.length(); if (!stringLength) return 0; // The only Latin-1 Extended Grapheme Cluster is CR LF if (s.is8Bit() && !s.contains('\r')) return std::min(stringLength, numGraphemeClusters); NonSharedCharacterBreakIterator it(s); if (!it) return std::min(stringLength, numGraphemeClusters); for (unsigned i = 0; i < numGraphemeClusters; ++i) { if (textBreakNext(it) == TextBreakDone) return stringLength; } return textBreakCurrent(it); }