OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 | 10 |
| 11 namespace base { |
| 12 |
11 typedef StringPiece::size_type size_type; | 13 typedef StringPiece::size_type size_type; |
12 | 14 |
13 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { | 15 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { |
14 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); | 16 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); |
15 return o; | 17 return o; |
16 } | 18 } |
17 | 19 |
18 bool operator==(const StringPiece& x, const StringPiece& y) { | 20 bool operator==(const StringPiece& x, const StringPiece& y) { |
19 if (x.size() != y.size()) | 21 if (x.size() != y.size()) |
20 return false; | 22 return false; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return npos; | 208 return npos; |
207 } | 209 } |
208 | 210 |
209 StringPiece StringPiece::substr(size_type pos, size_type n) const { | 211 StringPiece StringPiece::substr(size_type pos, size_type n) const { |
210 if (pos > length_) pos = length_; | 212 if (pos > length_) pos = length_; |
211 if (n > length_ - pos) n = length_ - pos; | 213 if (n > length_ - pos) n = length_ - pos; |
212 return StringPiece(ptr_ + pos, n); | 214 return StringPiece(ptr_ + pos, n); |
213 } | 215 } |
214 | 216 |
215 const StringPiece::size_type StringPiece::npos = size_type(-1); | 217 const StringPiece::size_type StringPiece::npos = size_type(-1); |
| 218 |
| 219 } // namespace base |
OLD | NEW |