Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: third_party/re2/re2/stringpiece.cc

Issue 1516543002: Update re2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated update instructions Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/re2/stringpiece.h ('k') | third_party/re2/re2/testing/backtrack.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/re2/stringpiece.cc
diff --git a/third_party/re2/util/stringpiece.cc b/third_party/re2/re2/stringpiece.cc
similarity index 64%
rename from third_party/re2/util/stringpiece.cc
rename to third_party/re2/re2/stringpiece.cc
index 37895b01e861454981ab9969e7608449d8a69b35..00f478a54ee056f2ffe8e65dff2d9e70c63b9835 100644
--- a/third_party/re2/util/stringpiece.cc
+++ b/third_party/re2/re2/stringpiece.cc
@@ -33,23 +33,33 @@ void StringPiece::CopyToString(string* target) const {
target->assign(ptr_, length_);
}
-int StringPiece::copy(char* buf, size_type n, size_type pos) const {
- int ret = min(length_ - pos, n);
+void StringPiece::AppendToString(string* target) const {
+ target->append(ptr_, length_);
+}
+
+StringPiece::size_type StringPiece::copy(char* buf, size_type n,
+ size_type pos) const {
+ size_type ret = min(length_ - pos, n);
memcpy(buf, ptr_ + pos, ret);
return ret;
}
-int StringPiece::find(const StringPiece& s, size_type pos) const {
+bool StringPiece::contains(StringPiece s) const {
+ return find(s, 0) != npos;
+}
+
+StringPiece::size_type StringPiece::find(const StringPiece& s,
+ size_type pos) const {
if (length_ < 0 || pos > static_cast<size_type>(length_))
return npos;
const char* result = std::search(ptr_ + pos, ptr_ + length_,
s.ptr_, s.ptr_ + s.length_);
const size_type xpos = result - ptr_;
- return xpos + s.length_ <= length_ ? xpos : npos;
+ return xpos + s.length_ <= static_cast<size_type>(length_) ? xpos : npos;
}
-int StringPiece::find(char c, size_type pos) const {
+StringPiece::size_type StringPiece::find(char c, size_type pos) const {
if (length_ <= 0 || pos >= static_cast<size_type>(length_)) {
return npos;
}
@@ -57,9 +67,10 @@ int StringPiece::find(char c, size_type pos) const {
return result != ptr_ + length_ ? result - ptr_ : npos;
}
-int StringPiece::rfind(const StringPiece& s, size_type pos) const {
+StringPiece::size_type StringPiece::rfind(const StringPiece& s,
+ size_type pos) const {
if (length_ < s.length_) return npos;
- const size_t ulen = length_;
+ const size_type ulen = length_;
if (s.length_ == 0) return min(ulen, pos);
const char* last = ptr_ + min(ulen - s.length_, pos) + s.length_;
@@ -67,9 +78,9 @@ int StringPiece::rfind(const StringPiece& s, size_type pos) const {
return result != last ? result - ptr_ : npos;
}
-int StringPiece::rfind(char c, size_type pos) const {
+StringPiece::size_type StringPiece::rfind(char c, size_type pos) const {
if (length_ <= 0) return npos;
- for (int i = min(pos, static_cast<size_type>(length_ - 1));
+ for (int i = static_cast<int>(min(pos, static_cast<size_type>(length_ - 1)));
i >= 0; --i) {
if (ptr_[i] == c) {
return i;
@@ -79,9 +90,9 @@ int StringPiece::rfind(char c, size_type pos) const {
}
StringPiece StringPiece::substr(size_type pos, size_type n) const {
- if (pos > length_) pos = length_;
+ if (pos > static_cast<size_type>(length_)) pos = static_cast<size_type>(length_);
if (n > length_ - pos) n = length_ - pos;
- return StringPiece(ptr_ + pos, n);
+ return StringPiece(ptr_ + pos, static_cast<int>(n));
}
const StringPiece::size_type StringPiece::npos = size_type(-1);
« no previous file with comments | « third_party/re2/re2/stringpiece.h ('k') | third_party/re2/re2/testing/backtrack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698