| OLD | NEW |
| 1 // Copyright (c) 2012 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #ifndef BASE_STRINGS_STRING_PIECE_H_ | 23 #ifndef BASE_STRINGS_STRING_PIECE_H_ |
| 24 #define BASE_STRINGS_STRING_PIECE_H_ | 24 #define BASE_STRINGS_STRING_PIECE_H_ |
| 25 | 25 |
| 26 #include <stddef.h> | 26 #include <stddef.h> |
| 27 | 27 |
| 28 #include <iosfwd> | 28 #include <iosfwd> |
| 29 #include <string> | 29 #include <string> |
| 30 | 30 |
| 31 #include "base/base_export.h" | 31 #include "base/base_export.h" |
| 32 #include "base/basictypes.h" | 32 #include "base/basictypes.h" |
| 33 #include "base/hash_tables.h" | 33 #include "base/containers/hash_tables.h" |
| 34 #include "base/strings/string16.h" | 34 #include "base/strings/string16.h" |
| 35 | 35 |
| 36 namespace base { | 36 namespace base { |
| 37 | 37 |
| 38 template <typename STRING_TYPE> class BasicStringPiece; | 38 template <typename STRING_TYPE> class BasicStringPiece; |
| 39 typedef BasicStringPiece<std::string> StringPiece; | 39 typedef BasicStringPiece<std::string> StringPiece; |
| 40 typedef BasicStringPiece<string16> StringPiece16; | 40 typedef BasicStringPiece<string16> StringPiece16; |
| 41 | 41 |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 402 } |
| 403 | 403 |
| 404 BASE_EXPORT std::ostream& operator<<(std::ostream& o, | 404 BASE_EXPORT std::ostream& operator<<(std::ostream& o, |
| 405 const StringPiece& piece); | 405 const StringPiece& piece); |
| 406 | 406 |
| 407 } // namespace base | 407 } // namespace base |
| 408 | 408 |
| 409 // We provide appropriate hash functions so StringPiece and StringPiece16 can | 409 // We provide appropriate hash functions so StringPiece and StringPiece16 can |
| 410 // be used as keys in hash sets and maps. | 410 // be used as keys in hash sets and maps. |
| 411 | 411 |
| 412 // This hash function is copied from base/hash_tables.h. We don't use the | 412 // This hash function is copied from base/containers/hash_tables.h. We don't |
| 413 // ones already defined for string and string16 directly because it would | 413 // use the ones already defined for string and string16 directly because it |
| 414 // require the string constructors to be called, which we don't want. | 414 // would require the string constructors to be called, which we don't want. |
| 415 #define HASH_STRING_PIECE(StringPieceType, string_piece) \ | 415 #define HASH_STRING_PIECE(StringPieceType, string_piece) \ |
| 416 std::size_t result = 0; \ | 416 std::size_t result = 0; \ |
| 417 for (StringPieceType::const_iterator i = string_piece.begin(); \ | 417 for (StringPieceType::const_iterator i = string_piece.begin(); \ |
| 418 i != string_piece.end(); ++i) \ | 418 i != string_piece.end(); ++i) \ |
| 419 result = (result * 131) + *i; \ | 419 result = (result * 131) + *i; \ |
| 420 return result; \ | 420 return result; \ |
| 421 | 421 |
| 422 namespace BASE_HASH_NAMESPACE { | 422 namespace BASE_HASH_NAMESPACE { |
| 423 #if defined(COMPILER_GCC) | 423 #if defined(COMPILER_GCC) |
| 424 | 424 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 442 } | 442 } |
| 443 inline size_t hash_value(const base::StringPiece16& sp16) { | 443 inline size_t hash_value(const base::StringPiece16& sp16) { |
| 444 HASH_STRING_PIECE(base::StringPiece16, sp16); | 444 HASH_STRING_PIECE(base::StringPiece16, sp16); |
| 445 } | 445 } |
| 446 | 446 |
| 447 #endif // COMPILER | 447 #endif // COMPILER |
| 448 | 448 |
| 449 } // namespace BASE_HASH_NAMESPACE | 449 } // namespace BASE_HASH_NAMESPACE |
| 450 | 450 |
| 451 #endif // BASE_STRINGS_STRING_PIECE_H_ | 451 #endif // BASE_STRINGS_STRING_PIECE_H_ |
| OLD | NEW |