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

Side by Side Diff: base/string_piece.cc

Issue 9159005: Move operator<< for StringPiece into string_piece.{h,cc} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix license Created 8 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/string_piece.h ('k') | chrome/renderer/extensions/chrome_v8_extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // Copied from strings/stringpiece.cc with modifications 4 // Copied from strings/stringpiece.cc with modifications
5 5
6 #include <algorithm> 6 #include <algorithm>
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 // MSVC doesn't like complex extern templates and DLLs. 13 // MSVC doesn't like complex extern templates and DLLs.
14 #if !defined(COMPILER_MSVC) 14 #if !defined(COMPILER_MSVC)
15 namespace internal { 15 namespace internal {
16 template class StringPieceDetail<std::string>; 16 template class StringPieceDetail<std::string>;
17 template class StringPieceDetail<string16>; 17 template class StringPieceDetail<string16>;
18 } // namespace internal 18 } // namespace internal
19 19
20 template class BasicStringPiece<string16>; 20 template class BasicStringPiece<string16>;
21 #endif 21 #endif
22 22
23 bool operator==(const StringPiece& x, const StringPiece& y) { 23 bool operator==(const StringPiece& x, const StringPiece& y) {
24 if (x.size() != y.size()) 24 if (x.size() != y.size())
25 return false; 25 return false;
26 26
27 return StringPiece::wordmemcmp(x.data(), y.data(), x.size()) == 0; 27 return StringPiece::wordmemcmp(x.data(), y.data(), x.size()) == 0;
28 } 28 }
29 29
30 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
31 o.write(piece.data(), static_cast<std::streamsize>(piece.size()));
32 return o;
33 }
34
30 namespace internal { 35 namespace internal {
31 void CopyToString(const StringPiece& self, std::string* target) { 36 void CopyToString(const StringPiece& self, std::string* target) {
32 target->assign(!self.empty() ? self.data() : "", self.size()); 37 target->assign(!self.empty() ? self.data() : "", self.size());
33 } 38 }
34 39
35 void AppendToString(const StringPiece& self, std::string* target) { 40 void AppendToString(const StringPiece& self, std::string* target) {
36 if (!self.empty()) 41 if (!self.empty())
37 target->append(self.data(), self.size()); 42 target->append(self.data(), self.size());
38 } 43 }
39 44
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 StringPiece substr(const StringPiece& self, 246 StringPiece substr(const StringPiece& self,
242 StringPiece::size_type pos, 247 StringPiece::size_type pos,
243 StringPiece::size_type n) { 248 StringPiece::size_type n) {
244 if (pos > self.size()) pos = self.size(); 249 if (pos > self.size()) pos = self.size();
245 if (n > self.size() - pos) n = self.size() - pos; 250 if (n > self.size() - pos) n = self.size() - pos;
246 return StringPiece(self.data() + pos, n); 251 return StringPiece(self.data() + pos, n);
247 } 252 }
248 253
249 } // namespace internal 254 } // namespace internal
250 } // namespace base 255 } // namespace base
OLDNEW
« no previous file with comments | « base/string_piece.h ('k') | chrome/renderer/extensions/chrome_v8_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698