Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: base/string_piece.h

Issue 8984007: Revert 114929 - Standardize StringToInt{,64} interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // We provide non-explicit singleton constructors so users can pass 53 // We provide non-explicit singleton constructors so users can pass
54 // in a "const char*" or a "string" wherever a "StringPiece" is 54 // in a "const char*" or a "string" wherever a "StringPiece" is
55 // expected. 55 // expected.
56 StringPiece() : ptr_(NULL), length_(0) { } 56 StringPiece() : ptr_(NULL), length_(0) { }
57 StringPiece(const char* str) 57 StringPiece(const char* str)
58 : ptr_(str), length_((str == NULL) ? 0 : strlen(str)) { } 58 : ptr_(str), length_((str == NULL) ? 0 : strlen(str)) { }
59 StringPiece(const std::string& str) 59 StringPiece(const std::string& str)
60 : ptr_(str.data()), length_(str.size()) { } 60 : ptr_(str.data()), length_(str.size()) { }
61 StringPiece(const char* offset, size_type len) 61 StringPiece(const char* offset, size_type len)
62 : ptr_(offset), length_(len) { } 62 : ptr_(offset), length_(len) { }
63 StringPiece(const std::string::const_iterator& begin,
64 const std::string::const_iterator& end)
65 : ptr_((end > begin) ? &(*begin) : NULL),
66 length_((end > begin) ? (size_type)(end - begin) : 0) { }
67 63
68 // data() may return a pointer to a buffer with embedded NULs, and the 64 // data() may return a pointer to a buffer with embedded NULs, and the
69 // returned buffer may or may not be null terminated. Therefore it is 65 // returned buffer may or may not be null terminated. Therefore it is
70 // typically a mistake to pass data() to a routine that expects a NUL 66 // typically a mistake to pass data() to a routine that expects a NUL
71 // terminated string. 67 // terminated string.
72 const char* data() const { return ptr_; } 68 const char* data() const { return ptr_; }
73 size_type size() const { return length_; } 69 size_type size() const { return length_; }
74 size_type length() const { return length_; } 70 size_type length() const { return length_; }
75 bool empty() const { return length_ == 0; } 71 bool empty() const { return length_ == 0; }
76 72
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // in a "const char16*" or a "string16" wherever a "StringPiece16" is 190 // in a "const char16*" or a "string16" wherever a "StringPiece16" is
195 // expected. 191 // expected.
196 StringPiece16() : ptr_(NULL), length_(0) { } 192 StringPiece16() : ptr_(NULL), length_(0) { }
197 StringPiece16(const char16* str) 193 StringPiece16(const char16* str)
198 : ptr_(str), 194 : ptr_(str),
199 length_((str == NULL) ? 0 : string16::traits_type::length(str)) { } 195 length_((str == NULL) ? 0 : string16::traits_type::length(str)) { }
200 StringPiece16(const string16& str) 196 StringPiece16(const string16& str)
201 : ptr_(str.data()), length_(str.size()) { } 197 : ptr_(str.data()), length_(str.size()) { }
202 StringPiece16(const char16* offset, size_type len) 198 StringPiece16(const char16* offset, size_type len)
203 : ptr_(offset), length_(len) { } 199 : ptr_(offset), length_(len) { }
204 StringPiece16(const string16::const_iterator& begin,
205 const string16::const_iterator& end)
206 : ptr_((end > begin) ? &(*begin) : NULL),
207 length_((end > begin) ? (size_type)(end - begin) : 0) { }
208 200
209 // data() may return a pointer to a buffer with embedded NULs, and the 201 // data() may return a pointer to a buffer with embedded NULs, and the
210 // returned buffer may or may not be null terminated. Therefore it is 202 // returned buffer may or may not be null terminated. Therefore it is
211 // typically a mistake to pass data() to a routine that expects a NUL 203 // typically a mistake to pass data() to a routine that expects a NUL
212 // terminated string. 204 // terminated string.
213 const char16* data() const { return ptr_; } 205 const char16* data() const { return ptr_; }
214 size_type size() const { return length_; } 206 size_type size() const { return length_; }
215 size_type length() const { return length_; } 207 size_type length() const { return length_; }
216 bool empty() const { return length_ == 0; } 208 bool empty() const { return length_ == 0; }
217 209
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 340 }
349 inline size_t hash_value(const base::StringPiece16& sp16) { 341 inline size_t hash_value(const base::StringPiece16& sp16) {
350 HASH_STRING_PIECE(base::StringPiece16, sp16); 342 HASH_STRING_PIECE(base::StringPiece16, sp16);
351 } 343 }
352 344
353 #endif // COMPILER 345 #endif // COMPILER
354 346
355 } // namespace BASE_HASH_NAMESPACE 347 } // namespace BASE_HASH_NAMESPACE
356 348
357 #endif // BASE_STRING_PIECE_H_ 349 #endif // BASE_STRING_PIECE_H_
OLDNEW
« no previous file with comments | « base/string_number_conversions_unittest.cc ('k') | chrome/browser/autocomplete_history_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698