summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 00:47:58 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-03 00:47:58 +0000
commitc29962f2b123f4d22798046022ad91b8c1774d32 (patch)
treeceec4b9a5c2b331fe6eae0023c5c132e5b90e8e3 /base
parent5819e220c4bb4bc2f48df4f071deb068bbbbca60 (diff)
downloadchromium_src-c29962f2b123f4d22798046022ad91b8c1774d32.zip
chromium_src-c29962f2b123f4d22798046022ad91b8c1774d32.tar.gz
chromium_src-c29962f2b123f4d22798046022ad91b8c1774d32.tar.bz2
Make WordIterator and Snippet::MatchPositions use size_t instead of int for offsets into strings. This avoids some casts. I also added a typedef for Snippet::MatchPosition which cleans up a bit of the calling code a little.
Review URL: http://codereview.chromium.org/13064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6260 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/word_iterator.cc6
-rw-r--r--base/word_iterator.h9
2 files changed, 6 insertions, 9 deletions
diff --git a/base/word_iterator.cc b/base/word_iterator.cc
index 9137f71..1e59a2f 100644
--- a/base/word_iterator.cc
+++ b/base/word_iterator.cc
@@ -8,7 +8,7 @@
#include "unicode/ubrk.h"
#include "unicode/ustring.h"
-const int WordIterator::npos = -1;
+const size_t npos = -1;
WordIterator::WordIterator(const std::wstring& str, BreakType break_type)
: iter_(NULL),
@@ -72,7 +72,7 @@ bool WordIterator::Advance() {
pos_ = npos;
return false;
} else {
- pos_ = static_cast<int>(pos);
+ pos_ = static_cast<size_t>(pos);
return true;
}
}
@@ -82,7 +82,7 @@ bool WordIterator::IsWord() const {
}
std::wstring WordIterator::GetWord() const {
- DCHECK(prev_ >= 0 && pos_ >= 0);
+ DCHECK(prev_ != npos && pos_ != npos);
return string_.substr(prev_, pos_ - prev_);
}
diff --git a/base/word_iterator.h b/base/word_iterator.h
index f41d767..d69b327 100644
--- a/base/word_iterator.h
+++ b/base/word_iterator.h
@@ -45,12 +45,9 @@ class WordIterator {
// Return the current break position within the string,
// or WordIterator::npos when done.
- int pos() const { return pos_; }
+ size_t pos() const { return pos_; }
// Return the value of pos() returned before Advance() was last called.
- int prev() const { return prev_; }
-
- // A special position value indicating "end of string".
- static const int npos;
+ 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 "word break" is after the final
@@ -82,7 +79,7 @@ class WordIterator {
BreakType break_type_;
// Previous and current iterator positions.
- int prev_, pos_;
+ size_t prev_, pos_;
DISALLOW_EVIL_CONSTRUCTORS(WordIterator);
};