Commit 0b162a3a authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Introduce FindNextWord{Backward,Forward}() as replacement of FindNextWordFromIndex()

This patch introduces |FindNextWord{Backward,Forward}()| as replacement of
|FindNextWordFromIndex()| to avoid |bool| parameter |forward| since all call
sites pass constant value for improving code health.

Change-Id: Ife6fe6bc355b17985d3c16c8f4fa4f5605cfb7c6
Reviewed-on: https://chromium-review.googlesource.com/900565Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534907}
parent 344d7238
......@@ -89,7 +89,7 @@ unsigned NextWordPositionBoundary(
return length;
}
need_more_context = false;
return FindNextWordFromIndex(characters, length, offset, true);
return FindNextWordForward(characters, length, offset);
}
unsigned PreviousWordPositionBoundary(
......@@ -104,7 +104,7 @@ unsigned PreviousWordPositionBoundary(
return 0;
}
need_more_context = false;
return FindNextWordFromIndex(characters, length, offset, false);
return FindNextWordBackward(characters, length, offset);
}
unsigned StartWordBoundary(
......
......@@ -227,10 +227,10 @@ inline bool SearchBuffer::IsWordStartMatch(size_t start, size_t length) const {
return true;
size_t word_break_search_start = start + length;
while (word_break_search_start > start)
word_break_search_start =
FindNextWordFromIndex(buffer_.data(), buffer_.size(),
word_break_search_start, false /* backwards */);
while (word_break_search_start > start) {
word_break_search_start = FindNextWordBackward(
buffer_.data(), buffer_.size(), word_break_search_start);
}
if (word_break_search_start != start)
return false;
if (options_ & kWholeWord)
......
......@@ -54,13 +54,9 @@ int StartOfLastWordBoundaryContext(const UChar* characters, int length) {
return 0;
}
int FindNextWordFromIndex(const UChar* chars,
int len,
int position,
bool forward) {
int FindNextWordForward(const UChar* chars, int len, int position) {
TextBreakIterator* it = WordBreakIterator(chars, len);
if (forward) {
position = it->following(position);
while (position != kTextBreakDone) {
// We stop searching when the character preceeding the break
......@@ -74,20 +70,23 @@ int FindNextWordFromIndex(const UChar* chars,
}
return len;
} else {
position = it->preceding(position);
while (position != kTextBreakDone) {
// We stop searching when the character following the break
// is alphanumeric or underscore.
if (position > 0 && (WTF::Unicode::IsAlphanumeric(chars[position]) ||
chars[position] == kLowLineCharacter))
return position;
}
position = it->preceding(position);
}
int FindNextWordBackward(const UChar* chars, int len, int position) {
TextBreakIterator* it = WordBreakIterator(chars, len);
position = it->preceding(position);
while (position != kTextBreakDone) {
// We stop searching when the character following the break
// is alphanumeric or underscore.
if (position > 0 && (WTF::Unicode::IsAlphanumeric(chars[position]) ||
chars[position] == kLowLineCharacter))
return position;
return 0;
position = it->preceding(position);
}
return 0;
}
int FindWordStartBoundary(const UChar* chars, int len, int position) {
......
......@@ -44,10 +44,8 @@ PLATFORM_EXPORT int StartOfLastWordBoundaryContext(const UChar* characters,
// |FindWordBoundary()| uses ICU, which works on logical order strings
PLATFORM_EXPORT int FindWordStartBoundary(const UChar*, int len, int position);
PLATFORM_EXPORT int FindWordEndBoundary(const UChar*, int len, int position);
PLATFORM_EXPORT int FindNextWordFromIndex(const UChar*,
int len,
int position,
bool forward);
PLATFORM_EXPORT int FindNextWordBackward(const UChar*, int len, int position);
PLATFORM_EXPORT int FindNextWordForward(const UChar*, int len, int position);
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment