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

Unified Diff: base/string_piece.cc

Issue 8933012: Revert "Extract common code from StringPiece and StringPiece16 into a templated base class.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | « base/string_piece.h ('k') | base/string_piece_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_piece.cc
diff --git a/base/string_piece.cc b/base/string_piece.cc
index 2960702275128a96f6bbcbb48e79de4904af8da8..bf6291c28075b9e06c0a3a960d1ac959c3408142 100644
--- a/base/string_piece.cc
+++ b/base/string_piece.cc
@@ -10,17 +10,6 @@
namespace base {
-// MSVC doesn't like complex extern templates and DLLs.
-#if !defined(COMPILER_MSVC)
-namespace internal {
-template class StringPieceDetail<std::string>;
-template class StringPieceDetail<string16>;
-} // namespace internal
-
-template class BasicStringPiece<std::string>;
-template class BasicStringPiece<string16>;
-#endif
-
typedef StringPiece::size_type size_type;
bool operator==(const StringPiece& x, const StringPiece& y) {
@@ -30,25 +19,22 @@ bool operator==(const StringPiece& x, const StringPiece& y) {
return StringPiece::wordmemcmp(x.data(), y.data(), x.size()) == 0;
}
-void BasicStringPiece<std::string>::CopyToString(std::string* target) const {
+void StringPiece::CopyToString(std::string* target) const {
target->assign(!empty() ? data() : "", size());
}
-void BasicStringPiece<std::string>::AppendToString(std::string* target) const {
+void StringPiece::AppendToString(std::string* target) const {
if (!empty())
target->append(data(), size());
}
-size_type BasicStringPiece<std::string>::copy(char* buf,
- size_type n,
- size_type pos) const {
+size_type StringPiece::copy(char* buf, size_type n, size_type pos) const {
size_type ret = std::min(length_ - pos, n);
memcpy(buf, ptr_ + pos, ret);
return ret;
}
-size_type BasicStringPiece<std::string>::find(const BasicStringPiece& s,
- size_type pos) const {
+size_type StringPiece::find(const StringPiece& s, size_type pos) const {
if (pos > length_)
return npos;
@@ -58,7 +44,7 @@ size_type BasicStringPiece<std::string>::find(const BasicStringPiece& s,
return xpos + s.length_ <= length_ ? xpos : npos;
}
-size_type BasicStringPiece<std::string>::find(char c, size_type pos) const {
+size_type StringPiece::find(char c, size_type pos) const {
if (pos >= length_)
return npos;
@@ -66,8 +52,7 @@ size_type BasicStringPiece<std::string>::find(char c, size_type pos) const {
return result != ptr_ + length_ ? static_cast<size_t>(result - ptr_) : npos;
}
-size_type BasicStringPiece<std::string>::rfind(const BasicStringPiece& s,
- size_type pos) const {
+size_type StringPiece::rfind(const StringPiece& s, size_type pos) const {
if (length_ < s.length_)
return npos;
@@ -79,7 +64,7 @@ size_type BasicStringPiece<std::string>::rfind(const BasicStringPiece& s,
return result != last ? static_cast<size_t>(result - ptr_) : npos;
}
-size_type BasicStringPiece<std::string>::rfind(char c, size_type pos) const {
+size_type StringPiece::rfind(char c, size_type pos) const {
if (length_ == 0)
return npos;
@@ -109,8 +94,8 @@ static inline void BuildLookupTable(const StringPiece& characters_wanted,
}
}
-size_type BasicStringPiece<std::string>::find_first_of(
- const BasicStringPiece& s, size_type pos) const {
+size_type StringPiece::find_first_of(const StringPiece& s,
+ size_type pos) const {
if (length_ == 0 || s.length_ == 0)
return npos;
@@ -128,8 +113,8 @@ size_type BasicStringPiece<std::string>::find_first_of(
return npos;
}
-size_type BasicStringPiece<std::string>::find_first_not_of(
- const BasicStringPiece& s, size_type pos) const {
+size_type StringPiece::find_first_not_of(const StringPiece& s,
+ size_type pos) const {
if (length_ == 0)
return npos;
@@ -150,8 +135,7 @@ size_type BasicStringPiece<std::string>::find_first_not_of(
return npos;
}
-size_type BasicStringPiece<std::string>::find_first_not_of(
- char c, size_type pos) const {
+size_type StringPiece::find_first_not_of(char c, size_type pos) const {
if (length_ == 0)
return npos;
@@ -163,8 +147,7 @@ size_type BasicStringPiece<std::string>::find_first_not_of(
return npos;
}
-size_type BasicStringPiece<std::string>::find_last_of(const StringPiece& s,
- size_type pos) const {
+size_type StringPiece::find_last_of(const StringPiece& s, size_type pos) const {
if (length_ == 0 || s.length_ == 0)
return npos;
@@ -183,8 +166,8 @@ size_type BasicStringPiece<std::string>::find_last_of(const StringPiece& s,
return npos;
}
-size_type BasicStringPiece<std::string>::find_last_not_of(
- const BasicStringPiece& s, size_type pos) const {
+size_type StringPiece::find_last_not_of(const StringPiece& s,
+ size_type pos) const {
if (length_ == 0)
return npos;
@@ -207,8 +190,7 @@ size_type BasicStringPiece<std::string>::find_last_not_of(
return npos;
}
-size_type BasicStringPiece<std::string>::find_last_not_of(char c,
- size_type pos) const {
+size_type StringPiece::find_last_not_of(char c, size_type pos) const {
if (length_ == 0)
return npos;
@@ -221,11 +203,12 @@ size_type BasicStringPiece<std::string>::find_last_not_of(char c,
return npos;
}
-BasicStringPiece<std::string> BasicStringPiece<std::string>::substr(
- size_type pos, size_type n) const {
+StringPiece StringPiece::substr(size_type pos, size_type n) const {
if (pos > length_) pos = length_;
if (n > length_ - pos) n = length_ - pos;
return StringPiece(ptr_ + pos, n);
}
+const StringPiece::size_type StringPiece::npos = size_type(-1);
+
} // namespace base
« no previous file with comments | « base/string_piece.h ('k') | base/string_piece_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698