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

Side by Side Diff: base/string_piece.h

Issue 552004: Style cleanup in preparation for auto-linting base/. (Closed)
Patch Set: Created 10 years, 11 months 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/stats_table_unittest.cc ('k') | base/sync_socket_posix.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // data() may return a pointer to a buffer with embedded NULs, and the 49 // data() may return a pointer to a buffer with embedded NULs, and the
50 // returned buffer may or may not be null terminated. Therefore it is 50 // returned buffer may or may not be null terminated. Therefore it is
51 // typically a mistake to pass data() to a routine that expects a NUL 51 // typically a mistake to pass data() to a routine that expects a NUL
52 // terminated string. 52 // terminated string.
53 const char* data() const { return ptr_; } 53 const char* data() const { return ptr_; }
54 size_type size() const { return length_; } 54 size_type size() const { return length_; }
55 size_type length() const { return length_; } 55 size_type length() const { return length_; }
56 bool empty() const { return length_ == 0; } 56 bool empty() const { return length_ == 0; }
57 57
58 void clear() { ptr_ = NULL; length_ = 0; } 58 void clear() {
59 void set(const char* data, size_type len) { ptr_ = data; length_ = len; } 59 ptr_ = NULL;
60 length_ = 0;
61 }
62 void set(const char* data, size_type len) {
63 ptr_ = data;
64 length_ = len;
65 }
60 void set(const char* str) { 66 void set(const char* str) {
61 ptr_ = str; 67 ptr_ = str;
62 length_ = str ? strlen(str) : 0; 68 length_ = str ? strlen(str) : 0;
63 } 69 }
64 void set(const void* data, size_type len) { 70 void set(const void* data, size_type len) {
65 ptr_ = reinterpret_cast<const char*>(data); 71 ptr_ = reinterpret_cast<const char*>(data);
66 length_ = len; 72 length_ = len;
67 } 73 }
68 74
69 char operator[](size_type i) const { return ptr_[i]; } 75 char operator[](size_type i) const { return ptr_[i]; }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 inline bool operator>=(const StringPiece& x, const StringPiece& y) { 185 inline bool operator>=(const StringPiece& x, const StringPiece& y) {
180 return !(x < y); 186 return !(x < y);
181 } 187 }
182 188
183 // allow StringPiece to be logged (needed for unit testing). 189 // allow StringPiece to be logged (needed for unit testing).
184 extern std::ostream& operator<<(std::ostream& o, const StringPiece& piece); 190 extern std::ostream& operator<<(std::ostream& o, const StringPiece& piece);
185 191
186 } // namespace base 192 } // namespace base
187 193
188 #endif // BASE_STRING_PIECE_H_ 194 #endif // BASE_STRING_PIECE_H_
OLDNEW
« no previous file with comments | « base/stats_table_unittest.cc ('k') | base/sync_socket_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698