| OLD | NEW | 
|---|
| 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.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 // StringPiece16 is similar to StringPiece but for base::string16 instead of | 17 // StringPiece16 is similar to StringPiece but for base::string16 instead of | 
| 18 // std::string. We do not define as large of a subset of the STL functions | 18 // std::string. We do not define as large of a subset of the STL functions | 
| 19 // from basic_string as in StringPiece, but this can be changed if these | 19 // from basic_string as in StringPiece, but this can be changed if these | 
| 20 // functions (find, find_first_of, etc.) are found to be useful in this context. | 20 // functions (find, find_first_of, etc.) are found to be useful in this context. | 
| 21 // | 21 // | 
| 22 | 22 | 
| 23 #ifndef BASE_STRING_PIECE_H_ | 23 #ifndef BASE_STRING_PIECE_H_ | 
| 24 #define BASE_STRING_PIECE_H_ | 24 #define BASE_STRING_PIECE_H_ | 
| 25 #pragma once | 25 #pragma once | 
| 26 | 26 | 
|  | 27 #include <iosfwd> | 
| 27 #include <string> | 28 #include <string> | 
| 28 | 29 | 
| 29 #include "base/base_export.h" | 30 #include "base/base_export.h" | 
| 30 #include "base/basictypes.h" | 31 #include "base/basictypes.h" | 
| 31 #include "base/hash_tables.h" | 32 #include "base/hash_tables.h" | 
| 32 #include "base/string16.h" | 33 #include "base/string16.h" | 
| 33 | 34 | 
| 34 namespace base { | 35 namespace base { | 
| 35 | 36 | 
| 36 template <typename STRING_TYPE> class BasicStringPiece; | 37 template <typename STRING_TYPE> class BasicStringPiece; | 
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 392 } | 393 } | 
| 393 | 394 | 
| 394 inline bool operator<=(const StringPiece16& x, const StringPiece16& y) { | 395 inline bool operator<=(const StringPiece16& x, const StringPiece16& y) { | 
| 395   return !(x > y); | 396   return !(x > y); | 
| 396 } | 397 } | 
| 397 | 398 | 
| 398 inline bool operator>=(const StringPiece16& x, const StringPiece16& y) { | 399 inline bool operator>=(const StringPiece16& x, const StringPiece16& y) { | 
| 399   return !(x < y); | 400   return !(x < y); | 
| 400 } | 401 } | 
| 401 | 402 | 
|  | 403 BASE_EXPORT std::ostream& operator<<(std::ostream& o, | 
|  | 404                                      const StringPiece& piece); | 
|  | 405 | 
| 402 }  // namespace base | 406 }  // namespace base | 
| 403 | 407 | 
| 404 // We provide appropriate hash functions so StringPiece and StringPiece16 can | 408 // We provide appropriate hash functions so StringPiece and StringPiece16 can | 
| 405 // be used as keys in hash sets and maps. | 409 // be used as keys in hash sets and maps. | 
| 406 | 410 | 
| 407 // This hash function is copied from base/hash_tables.h. We don't use the | 411 // This hash function is copied from base/hash_tables.h. We don't use the | 
| 408 // ones already defined for string and string16 directly because it would | 412 // ones already defined for string and string16 directly because it would | 
| 409 // require the string constructors to be called, which we don't want. | 413 // require the string constructors to be called, which we don't want. | 
| 410 #define HASH_STRING_PIECE(StringPieceType, string_piece)                \ | 414 #define HASH_STRING_PIECE(StringPieceType, string_piece)                \ | 
| 411   std::size_t result = 0;                                               \ | 415   std::size_t result = 0;                                               \ | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 437 } | 441 } | 
| 438 inline size_t hash_value(const base::StringPiece16& sp16) { | 442 inline size_t hash_value(const base::StringPiece16& sp16) { | 
| 439   HASH_STRING_PIECE(base::StringPiece16, sp16); | 443   HASH_STRING_PIECE(base::StringPiece16, sp16); | 
| 440 } | 444 } | 
| 441 | 445 | 
| 442 #endif  // COMPILER | 446 #endif  // COMPILER | 
| 443 | 447 | 
| 444 }  // namespace BASE_HASH_NAMESPACE | 448 }  // namespace BASE_HASH_NAMESPACE | 
| 445 | 449 | 
| 446 #endif  // BASE_STRING_PIECE_H_ | 450 #endif  // BASE_STRING_PIECE_H_ | 
| OLD | NEW | 
|---|