diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 00:05:57 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 00:05:57 +0000 |
commit | c0797f01d3ed8bf441e7368c2179781f0292ee7b (patch) | |
tree | f07f403337341dcfdc26880688f151817d4b12ee | |
parent | b229fb588dc49059a4bf303d7504310cbff6629d (diff) | |
download | chromium_src-c0797f01d3ed8bf441e7368c2179781f0292ee7b.zip chromium_src-c0797f01d3ed8bf441e7368c2179781f0292ee7b.tar.gz chromium_src-c0797f01d3ed8bf441e7368c2179781f0292ee7b.tar.bz2 |
base/i18n: Make BreakIterator::IsWord() more readable.
Unrelated changes:
- Remove unnecessary {} around if clause.
- Tweak some comments in the header file.
- Move prev() and pos() getters to the end of public section.
BUG=None
TEST=out/Debug/base_unittests --gtest_filter=BreakIteratorTest.*
R=tsepez@chromium.org,evan@chromium.org
Review URL: http://codereview.chromium.org/6979019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86747 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/i18n/break_iterator.cc | 8 | ||||
-rw-r--r-- | base/i18n/break_iterator.h | 29 |
2 files changed, 18 insertions, 19 deletions
diff --git a/base/i18n/break_iterator.cc b/base/i18n/break_iterator.cc index 224bb51..afa1fd8 100644 --- a/base/i18n/break_iterator.cc +++ b/base/i18n/break_iterator.cc @@ -71,9 +71,8 @@ bool BreakIterator::Advance() { case BREAK_NEWLINE: do { pos = ubrk_next(static_cast<UBreakIterator*>(iter_)); - if (pos == UBRK_DONE) { + if (pos == UBRK_DONE) break; - } pos_ = static_cast<size_t>(pos); status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); } while (status >= UBRK_LINE_SOFT && status < UBRK_LINE_SOFT_LIMIT); @@ -89,9 +88,8 @@ bool BreakIterator::Advance() { } bool BreakIterator::IsWord() const { - return (break_type_ == BREAK_WORD && - ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)) != - UBRK_WORD_NONE); + int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); + return (break_type_ == BREAK_WORD && status != UBRK_WORD_NONE); } string16 BreakIterator::GetString() const { diff --git a/base/i18n/break_iterator.h b/base/i18n/break_iterator.h index 82e8092..e49b46e 100644 --- a/base/i18n/break_iterator.h +++ b/base/i18n/break_iterator.h @@ -41,12 +41,13 @@ // breaks are at the periods in ".foo\n.bar\n.\n."). // // To extract the words from a string, move a BREAK_WORD BreakIterator -// through the string and test whether IsWord() is true. E.g., -// BreakIterator iter(&str, BreakIterator::BREAK_WORD); -// if (!iter.Init()) return false; +// through the string and test whether IsWord() is true. E.g., +// BreakIterator iter(str, BreakIterator::BREAK_WORD); +// if (!iter.Init()) +// return false; // while (iter.Advance()) { // if (iter.IsWord()) { -// // region [iter.prev(),iter.pos()) contains a word. +// // Region [iter.prev(), iter.pos()) contains a word. // VLOG(1) << "word: " << iter.GetString(); // } // } @@ -74,13 +75,6 @@ class BreakIterator { // Returns false if ICU failed to initialize. bool Init(); - // Return the current break position within the string, - // or BreakIterator::npos when done. - size_t pos() const { return pos_; } - - // Return the value of pos() returned before Advance() was last called. - size_t prev() const { return prev_; } - // Advance to the next break. Returns false if we've run past the end of // the string. (Note that the very last "break" is after the final // character in the string, and when we advance to that position it's the @@ -93,11 +87,18 @@ class BreakIterator { // this distinction doesn't apply and it always retuns false. bool IsWord() const; - // Return the string between prev() and pos(). - // Advance() must have been called successfully at least once - // for pos() to have advanced to somewhere useful. + // Returns the string between prev() and pos(). + // Advance() must have been called successfully at least once for pos() to + // have advanced to somewhere useful. string16 GetString() const; + // Returns the value of pos() returned before Advance() was last called. + size_t prev() const { return prev_; } + + // Returns the current break position within the string, + // or BreakIterator::npos when done. + size_t pos() const { return pos_; } + private: // ICU iterator, avoiding ICU ubrk.h dependence. // This is actually an ICU UBreakiterator* type, which turns out to be |