summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/i18n/break_iterator.cc21
-rw-r--r--base/i18n/break_iterator.h6
2 files changed, 27 insertions, 0 deletions
diff --git a/base/i18n/break_iterator.cc b/base/i18n/break_iterator.cc
index afa1fd8..eae531c 100644
--- a/base/i18n/break_iterator.cc
+++ b/base/i18n/break_iterator.cc
@@ -92,6 +92,27 @@ bool BreakIterator::IsWord() const {
return (break_type_ == BREAK_WORD && status != UBRK_WORD_NONE);
}
+bool BreakIterator::IsEndOfWord(size_t position) const {
+ if (break_type_ != BREAK_WORD)
+ return false;
+
+ UBreakIterator* iter = static_cast<UBreakIterator*>(iter_);
+ UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position));
+ int32_t status = ubrk_getRuleStatus(iter);
+ return (!!boundary && status != UBRK_WORD_NONE);
+}
+
+bool BreakIterator::IsStartOfWord(size_t position) const {
+ if (break_type_ != BREAK_WORD)
+ return false;
+
+ UBreakIterator* iter = static_cast<UBreakIterator*>(iter_);
+ UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position));
+ ubrk_next(iter);
+ int32_t next_status = ubrk_getRuleStatus(iter);
+ return (!!boundary && next_status != UBRK_WORD_NONE);
+}
+
string16 BreakIterator::GetString() const {
DCHECK(prev_ != npos && pos_ != npos);
return string_.substr(prev_, pos_ - prev_);
diff --git a/base/i18n/break_iterator.h b/base/i18n/break_iterator.h
index f375962..3207256 100644
--- a/base/i18n/break_iterator.h
+++ b/base/i18n/break_iterator.h
@@ -88,6 +88,12 @@ class BASE_I18N_EXPORT BreakIterator {
// this distinction doesn't apply and it always retuns false.
bool IsWord() const;
+ // Under BREAK_WORD mode, returns true if |position| is at the end of word or
+ // at the start of word. It always retuns false under BREAK_LINE and
+ // BREAK_NEWLINE modes.
+ bool IsEndOfWord(size_t position) const;
+ bool IsStartOfWord(size_t position) const;
+
// Returns the string between prev() and pos().
// Advance() must have been called successfully at least once for pos() to
// have advanced to somewhere useful.