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

Side by Side Diff: base/string_piece.h

Issue 8921006: Standardize StringToInt{,64} interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix call syntax of StringToInt() in Chrome OS code. 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
« no previous file with comments | « base/string_number_conversions_unittest.cc ('k') | base/sys_info_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) { }
63 67
64 // data() may return a pointer to a buffer with embedded NULs, and the 68 // data() may return a pointer to a buffer with embedded NULs, and the
65 // returned buffer may or may not be null terminated. Therefore it is 69 // returned buffer may or may not be null terminated. Therefore it is
66 // typically a mistake to pass data() to a routine that expects a NUL 70 // typically a mistake to pass data() to a routine that expects a NUL
67 // terminated string. 71 // terminated string.
68 const char* data() const { return ptr_; } 72 const char* data() const { return ptr_; }
69 size_type size() const { return length_; } 73 size_type size() const { return length_; }
70 size_type length() const { return length_; } 74 size_type length() const { return length_; }
71 bool empty() const { return length_ == 0; } 75 bool empty() const { return length_ == 0; }
72 76
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // in a "const char16*" or a "string16" wherever a "StringPiece16" is 194 // in a "const char16*" or a "string16" wherever a "StringPiece16" is
191 // expected. 195 // expected.
192 StringPiece16() : ptr_(NULL), length_(0) { } 196 StringPiece16() : ptr_(NULL), length_(0) { }
193 StringPiece16(const char16* str) 197 StringPiece16(const char16* str)
194 : ptr_(str), 198 : ptr_(str),
195 length_((str == NULL) ? 0 : string16::traits_type::length(str)) { } 199 length_((str == NULL) ? 0 : string16::traits_type::length(str)) { }
196 StringPiece16(const string16& str) 200 StringPiece16(const string16& str)
197 : ptr_(str.data()), length_(str.size()) { } 201 : ptr_(str.data()), length_(str.size()) { }
198 StringPiece16(const char16* offset, size_type len) 202 StringPiece16(const char16* offset, size_type len)
199 : ptr_(offset), length_(len) { } 203 : 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) { }
200 208
201 // data() may return a pointer to a buffer with embedded NULs, and the 209 // data() may return a pointer to a buffer with embedded NULs, and the
202 // returned buffer may or may not be null terminated. Therefore it is 210 // returned buffer may or may not be null terminated. Therefore it is
203 // typically a mistake to pass data() to a routine that expects a NUL 211 // typically a mistake to pass data() to a routine that expects a NUL
204 // terminated string. 212 // terminated string.
205 const char16* data() const { return ptr_; } 213 const char16* data() const { return ptr_; }
206 size_type size() const { return length_; } 214 size_type size() const { return length_; }
207 size_type length() const { return length_; } 215 size_type length() const { return length_; }
208 bool empty() const { return length_ == 0; } 216 bool empty() const { return length_ == 0; }
209 217
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 348 }
341 inline size_t hash_value(const base::StringPiece16& sp16) { 349 inline size_t hash_value(const base::StringPiece16& sp16) {
342 HASH_STRING_PIECE(base::StringPiece16, sp16); 350 HASH_STRING_PIECE(base::StringPiece16, sp16);
343 } 351 }
344 352
345 #endif // COMPILER 353 #endif // COMPILER
346 354
347 } // namespace BASE_HASH_NAMESPACE 355 } // namespace BASE_HASH_NAMESPACE
348 356
349 #endif // BASE_STRING_PIECE_H_ 357 #endif // BASE_STRING_PIECE_H_
OLDNEW
« no previous file with comments | « base/string_number_conversions_unittest.cc ('k') | base/sys_info_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698