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( ...@@ -89,7 +89,7 @@ unsigned NextWordPositionBoundary(
return length; return length;
} }
need_more_context = false; need_more_context = false;
return FindNextWordFromIndex(characters, length, offset, true); return FindNextWordForward(characters, length, offset);
} }
unsigned PreviousWordPositionBoundary( unsigned PreviousWordPositionBoundary(
...@@ -104,7 +104,7 @@ unsigned PreviousWordPositionBoundary( ...@@ -104,7 +104,7 @@ unsigned PreviousWordPositionBoundary(
return 0; return 0;
} }
need_more_context = false; need_more_context = false;
return FindNextWordFromIndex(characters, length, offset, false); return FindNextWordBackward(characters, length, offset);
} }
unsigned StartWordBoundary( unsigned StartWordBoundary(
......
...@@ -227,10 +227,10 @@ inline bool SearchBuffer::IsWordStartMatch(size_t start, size_t length) const { ...@@ -227,10 +227,10 @@ inline bool SearchBuffer::IsWordStartMatch(size_t start, size_t length) const {
return true; return true;
size_t word_break_search_start = start + length; size_t word_break_search_start = start + length;
while (word_break_search_start > start) while (word_break_search_start > start) {
word_break_search_start = word_break_search_start = FindNextWordBackward(
FindNextWordFromIndex(buffer_.data(), buffer_.size(), buffer_.data(), buffer_.size(), word_break_search_start);
word_break_search_start, false /* backwards */); }
if (word_break_search_start != start) if (word_break_search_start != start)
return false; return false;
if (options_ & kWholeWord) if (options_ & kWholeWord)
......
...@@ -54,13 +54,9 @@ int StartOfLastWordBoundaryContext(const UChar* characters, int length) { ...@@ -54,13 +54,9 @@ int StartOfLastWordBoundaryContext(const UChar* characters, int length) {
return 0; return 0;
} }
int FindNextWordFromIndex(const UChar* chars, int FindNextWordForward(const UChar* chars, int len, int position) {
int len,
int position,
bool forward) {
TextBreakIterator* it = WordBreakIterator(chars, len); TextBreakIterator* it = WordBreakIterator(chars, len);
if (forward) {
position = it->following(position); position = it->following(position);
while (position != kTextBreakDone) { while (position != kTextBreakDone) {
// We stop searching when the character preceeding the break // We stop searching when the character preceeding the break
...@@ -74,7 +70,11 @@ int FindNextWordFromIndex(const UChar* chars, ...@@ -74,7 +70,11 @@ int FindNextWordFromIndex(const UChar* chars,
} }
return len; return len;
} else { }
int FindNextWordBackward(const UChar* chars, int len, int position) {
TextBreakIterator* it = WordBreakIterator(chars, len);
position = it->preceding(position); position = it->preceding(position);
while (position != kTextBreakDone) { while (position != kTextBreakDone) {
// We stop searching when the character following the break // We stop searching when the character following the break
...@@ -87,7 +87,6 @@ int FindNextWordFromIndex(const UChar* chars, ...@@ -87,7 +87,6 @@ int FindNextWordFromIndex(const UChar* chars,
} }
return 0; return 0;
}
} }
int FindWordStartBoundary(const UChar* chars, int len, int position) { int FindWordStartBoundary(const UChar* chars, int len, int position) {
......
...@@ -44,10 +44,8 @@ PLATFORM_EXPORT int StartOfLastWordBoundaryContext(const UChar* characters, ...@@ -44,10 +44,8 @@ PLATFORM_EXPORT int StartOfLastWordBoundaryContext(const UChar* characters,
// |FindWordBoundary()| uses ICU, which works on logical order strings // |FindWordBoundary()| uses ICU, which works on logical order strings
PLATFORM_EXPORT int FindWordStartBoundary(const UChar*, int len, int position); PLATFORM_EXPORT int FindWordStartBoundary(const UChar*, int len, int position);
PLATFORM_EXPORT int FindWordEndBoundary(const UChar*, int len, int position); PLATFORM_EXPORT int FindWordEndBoundary(const UChar*, int len, int position);
PLATFORM_EXPORT int FindNextWordFromIndex(const UChar*, PLATFORM_EXPORT int FindNextWordBackward(const UChar*, int len, int position);
int len, PLATFORM_EXPORT int FindNextWordForward(const UChar*, int len, int position);
int position,
bool forward);
} // namespace blink } // 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