@@ -89,30 +89,26 @@ class SmallString : public SmallVector<char, InternalLen> {
89
89
90
90
// / Check for string equality. This is more efficient than compare() when
91
91
// / the relative ordering of inequal strings isn't needed.
92
- bool equals (StringRef RHS) const {
93
- return str ().equals (RHS);
94
- }
92
+ [[nodiscard]] bool equals (StringRef RHS) const { return str ().equals (RHS); }
95
93
96
94
// / Check for string equality, ignoring case.
97
- bool equals_insensitive (StringRef RHS) const {
95
+ [[nodiscard]] bool equals_insensitive (StringRef RHS) const {
98
96
return str ().equals_insensitive (RHS);
99
97
}
100
98
101
99
// / compare - Compare two strings; the result is negative, zero, or positive
102
100
// / if this string is lexicographically less than, equal to, or greater than
103
101
// / the \p RHS.
104
- int compare (StringRef RHS) const {
105
- return str ().compare (RHS);
106
- }
102
+ [[nodiscard]] int compare (StringRef RHS) const { return str ().compare (RHS); }
107
103
108
104
// / compare_insensitive - Compare two strings, ignoring case.
109
- int compare_insensitive (StringRef RHS) const {
105
+ [[nodiscard]] int compare_insensitive (StringRef RHS) const {
110
106
return str ().compare_insensitive (RHS);
111
107
}
112
108
113
109
// / compare_numeric - Compare two strings, treating sequences of digits as
114
110
// / numbers.
115
- int compare_numeric (StringRef RHS) const {
111
+ [[nodiscard]] int compare_numeric (StringRef RHS) const {
116
112
return str ().compare_numeric (RHS);
117
113
}
118
114
@@ -121,10 +117,14 @@ class SmallString : public SmallVector<char, InternalLen> {
121
117
// / @{
122
118
123
119
// / starts_with - Check if this string starts with the given \p Prefix.
124
- bool starts_with (StringRef Prefix) const { return str ().starts_with (Prefix); }
120
+ [[nodiscard]] bool starts_with (StringRef Prefix) const {
121
+ return str ().starts_with (Prefix);
122
+ }
125
123
126
124
// / ends_with - Check if this string ends with the given \p Suffix.
127
- bool ends_with (StringRef Suffix) const { return str ().ends_with (Suffix); }
125
+ [[nodiscard]] bool ends_with (StringRef Suffix) const {
126
+ return str ().ends_with (Suffix);
127
+ }
128
128
129
129
// / @}
130
130
// / @name String Searching
@@ -134,74 +134,74 @@ class SmallString : public SmallVector<char, InternalLen> {
134
134
// /
135
135
// / \return - The index of the first occurrence of \p C, or npos if not
136
136
// / found.
137
- size_t find (char C, size_t From = 0 ) const {
137
+ [[nodiscard]] size_t find (char C, size_t From = 0 ) const {
138
138
return str ().find (C, From);
139
139
}
140
140
141
141
// / Search for the first string \p Str in the string.
142
142
// /
143
143
// / \returns The index of the first occurrence of \p Str, or npos if not
144
144
// / found.
145
- size_t find (StringRef Str, size_t From = 0 ) const {
145
+ [[nodiscard]] size_t find (StringRef Str, size_t From = 0 ) const {
146
146
return str ().find (Str, From);
147
147
}
148
148
149
149
// / Search for the last character \p C in the string.
150
150
// /
151
151
// / \returns The index of the last occurrence of \p C, or npos if not
152
152
// / found.
153
- size_t rfind (char C, size_t From = StringRef::npos) const {
153
+ [[nodiscard]] size_t rfind (char C, size_t From = StringRef::npos) const {
154
154
return str ().rfind (C, From);
155
155
}
156
156
157
157
// / Search for the last string \p Str in the string.
158
158
// /
159
159
// / \returns The index of the last occurrence of \p Str, or npos if not
160
160
// / found.
161
- size_t rfind (StringRef Str) const {
162
- return str ().rfind (Str);
163
- }
161
+ [[nodiscard]] size_t rfind (StringRef Str) const { return str ().rfind (Str); }
164
162
165
163
// / Find the first character in the string that is \p C, or npos if not
166
164
// / found. Same as find.
167
- size_t find_first_of (char C, size_t From = 0 ) const {
165
+ [[nodiscard]] size_t find_first_of (char C, size_t From = 0 ) const {
168
166
return str ().find_first_of (C, From);
169
167
}
170
168
171
169
// / Find the first character in the string that is in \p Chars, or npos if
172
170
// / not found.
173
171
// /
174
172
// / Complexity: O(size() + Chars.size())
175
- size_t find_first_of (StringRef Chars, size_t From = 0 ) const {
173
+ [[nodiscard]] size_t find_first_of (StringRef Chars, size_t From = 0 ) const {
176
174
return str ().find_first_of (Chars, From);
177
175
}
178
176
179
177
// / Find the first character in the string that is not \p C or npos if not
180
178
// / found.
181
- size_t find_first_not_of (char C, size_t From = 0 ) const {
179
+ [[nodiscard]] size_t find_first_not_of (char C, size_t From = 0 ) const {
182
180
return str ().find_first_not_of (C, From);
183
181
}
184
182
185
183
// / Find the first character in the string that is not in the string
186
184
// / \p Chars, or npos if not found.
187
185
// /
188
186
// / Complexity: O(size() + Chars.size())
189
- size_t find_first_not_of (StringRef Chars, size_t From = 0 ) const {
187
+ [[nodiscard]] size_t find_first_not_of (StringRef Chars,
188
+ size_t From = 0 ) const {
190
189
return str ().find_first_not_of (Chars, From);
191
190
}
192
191
193
192
// / Find the last character in the string that is \p C, or npos if not
194
193
// / found.
195
- size_t find_last_of (char C, size_t From = StringRef::npos) const {
194
+ [[nodiscard]] size_t find_last_of (char C,
195
+ size_t From = StringRef::npos) const {
196
196
return str ().find_last_of (C, From);
197
197
}
198
198
199
199
// / Find the last character in the string that is in \p C, or npos if not
200
200
// / found.
201
201
// /
202
202
// / Complexity: O(size() + Chars.size())
203
- size_t find_last_of (
204
- StringRef Chars, size_t From = StringRef::npos) const {
203
+ [[nodiscard]] size_t find_last_of (StringRef Chars,
204
+ size_t From = StringRef::npos) const {
205
205
return str ().find_last_of (Chars, From);
206
206
}
207
207
@@ -210,15 +210,11 @@ class SmallString : public SmallVector<char, InternalLen> {
210
210
// / @{
211
211
212
212
// / Return the number of occurrences of \p C in the string.
213
- size_t count (char C) const {
214
- return str ().count (C);
215
- }
213
+ [[nodiscard]] size_t count (char C) const { return str ().count (C); }
216
214
217
215
// / Return the number of non-overlapped occurrences of \p Str in the
218
216
// / string.
219
- size_t count (StringRef Str) const {
220
- return str ().count (Str);
221
- }
217
+ [[nodiscard]] size_t count (StringRef Str) const { return str ().count (Str); }
222
218
223
219
// / @}
224
220
// / @name Substring Operations
@@ -233,7 +229,8 @@ class SmallString : public SmallVector<char, InternalLen> {
233
229
// / \param N The number of characters to included in the substring. If \p N
234
230
// / exceeds the number of characters remaining in the string, the string
235
231
// / suffix (starting with \p Start) will be returned.
236
- StringRef substr (size_t Start, size_t N = StringRef::npos) const {
232
+ [[nodiscard]] StringRef substr (size_t Start,
233
+ size_t N = StringRef::npos) const {
237
234
return str ().substr (Start, N);
238
235
}
239
236
@@ -247,14 +244,16 @@ class SmallString : public SmallVector<char, InternalLen> {
247
244
// / substring. If this is npos, or less than \p Start, or exceeds the
248
245
// / number of characters remaining in the string, the string suffix
249
246
// / (starting with \p Start) will be returned.
250
- StringRef slice (size_t Start, size_t End) const {
247
+ [[nodiscard]] StringRef slice (size_t Start, size_t End) const {
251
248
return str ().slice (Start, End);
252
249
}
253
250
254
251
// Extra methods.
255
252
256
253
// / Explicit conversion to StringRef.
257
- StringRef str () const { return StringRef (this ->data (), this ->size ()); }
254
+ [[nodiscard]] StringRef str () const {
255
+ return StringRef (this ->data (), this ->size ());
256
+ }
258
257
259
258
// TODO: Make this const, if it's safe...
260
259
const char * c_str () {
0 commit comments