OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 length_ = CheckedSsizeTFromSizeT(strlen(str)); | 215 length_ = CheckedSsizeTFromSizeT(strlen(str)); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 template <class Allocator> | 219 template <class Allocator> |
220 StringPiece( // NOLINT(runtime/explicit) | 220 StringPiece( // NOLINT(runtime/explicit) |
221 const std::basic_string<char, std::char_traits<char>, Allocator>& str) | 221 const std::basic_string<char, std::char_traits<char>, Allocator>& str) |
222 : ptr_(str.data()), length_(0) { | 222 : ptr_(str.data()), length_(0) { |
223 length_ = CheckedSsizeTFromSizeT(str.size()); | 223 length_ = CheckedSsizeTFromSizeT(str.size()); |
224 } | 224 } |
225 #if defined(HAS_GLOBAL_STRING) | |
226 template <class Allocator> | |
227 StringPiece( // NOLINT(runtime/explicit) | |
228 const basic_string<char, std::char_traits<char>, Allocator>& str) | |
229 : ptr_(str.data()), length_(0) { | |
230 length_ = CheckedSsizeTFromSizeT(str.size()); | |
231 } | |
232 #endif | |
233 | 225 |
234 StringPiece(const char* offset, stringpiece_ssize_type len) | 226 StringPiece(const char* offset, stringpiece_ssize_type len) |
235 : ptr_(offset), length_(len) { | 227 : ptr_(offset), length_(len) { |
236 assert(len >= 0); | 228 assert(len >= 0); |
237 } | 229 } |
238 | 230 |
239 // Substring of another StringPiece. | 231 // Substring of another StringPiece. |
240 // pos must be non-negative and <= x.length(). | 232 // pos must be non-negative and <= x.length(). |
241 StringPiece(StringPiece x, stringpiece_ssize_type pos); | 233 StringPiece(StringPiece x, stringpiece_ssize_type pos); |
242 // Substring of another StringPiece. | 234 // Substring of another StringPiece. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 size_t result = 0; | 474 size_t result = 0; |
483 for (const char *str = s.data(), *end = str + s.size(); str < end; str++) {
| 475 for (const char *str = s.data(), *end = str + s.size(); str < end; str++) {
|
484 result = 5 * result + *str; | 476 result = 5 * result + *str; |
485 } | 477 } |
486 return result; | 478 return result; |
487 } | 479 } |
488 }; | 480 }; |
489 GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END | 481 GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END |
490 | 482 |
491 #endif // STRINGS_STRINGPIECE_H_ | 483 #endif // STRINGS_STRINGPIECE_H_ |
OLD | NEW |