| 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.h with modifications | 4 // Copied from strings/stringpiece.h with modifications |
| 5 // | 5 // |
| 6 // A string-like object that points to a sized piece of memory. | 6 // A string-like object that points to a sized piece of memory. |
| 7 // | 7 // |
| 8 // Functions or methods may use const StringPiece& parameters to accept either | 8 // Functions or methods may use const StringPiece& parameters to accept either |
| 9 // a "const char*" or a "string" value that will be implicitly converted to | 9 // a "const char*" or a "string" value that will be implicitly converted to |
| 10 // a StringPiece. The implicit conversion means that it is often appropriate | 10 // a StringPiece. The implicit conversion means that it is often appropriate |
| 11 // to include this .h file in other files rather than forward-declaring | 11 // to include this .h file in other files rather than forward-declaring |
| 12 // StringPiece as would be appropriate for most other Google classes. | 12 // StringPiece as would be appropriate for most other Google classes. |
| 13 // | 13 // |
| 14 // Systematic usage of StringPiece is encouraged as it will reduce unnecessary | 14 // Systematic usage of StringPiece is encouraged as it will reduce unnecessary |
| 15 // conversions from "const char*" to "string" and back again. | 15 // conversions from "const char*" to "string" and back again. |
| 16 // | 16 // |
| 17 | 17 |
| 18 #ifndef BASE_STRING_PIECE_H_ | 18 #ifndef BASE_STRING_PIECE_H_ |
| 19 #define BASE_STRING_PIECE_H_ | 19 #define BASE_STRING_PIECE_H_ |
| 20 | 20 |
| 21 #include <algorithm> | 21 #include <algorithm> |
| 22 #include <iosfwd> | 22 #include <iosfwd> |
| 23 #include <string> | 23 #include <string> |
| 24 | 24 |
| 25 #include "base/basictypes.h" | 25 #include "base/basictypes.h" |
| 26 | 26 |
| 27 namespace base { |
| 28 |
| 27 class StringPiece { | 29 class StringPiece { |
| 28 public: | 30 public: |
| 29 typedef size_t size_type; | 31 typedef size_t size_type; |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 const char* ptr_; | 34 const char* ptr_; |
| 33 size_type length_; | 35 size_type length_; |
| 34 | 36 |
| 35 public: | 37 public: |
| 36 // We provide non-explicit singleton constructors so users can pass | 38 // We provide non-explicit singleton constructors so users can pass |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return !(x > y); | 176 return !(x > y); |
| 175 } | 177 } |
| 176 | 178 |
| 177 inline bool operator>=(const StringPiece& x, const StringPiece& y) { | 179 inline bool operator>=(const StringPiece& x, const StringPiece& y) { |
| 178 return !(x < y); | 180 return !(x < y); |
| 179 } | 181 } |
| 180 | 182 |
| 181 // allow StringPiece to be logged (needed for unit testing). | 183 // allow StringPiece to be logged (needed for unit testing). |
| 182 extern std::ostream& operator<<(std::ostream& o, const StringPiece& piece); | 184 extern std::ostream& operator<<(std::ostream& o, const StringPiece& piece); |
| 183 | 185 |
| 186 } // namespace base |
| 187 |
| 184 #endif // BASE_STRING_PIECE_H_ | 188 #endif // BASE_STRING_PIECE_H_ |
| OLD | NEW |