16
16
17
17
namespace AK {
18
18
19
- // DeprecatedString is a convenience wrapper around StringImpl, suitable for passing
19
+ // ByteString is a convenience wrapper around StringImpl, suitable for passing
20
20
// around as a value type. It's basically the same as passing around a
21
21
// RefPtr<StringImpl const>, with a bit of syntactic sugar.
22
22
//
23
23
// Note that StringImpl is an immutable object that cannot shrink or grow.
24
24
// Its allocation size is snugly tailored to the specific string it contains.
25
- // Copying a DeprecatedString is very efficient, since the internal StringImpl is
25
+ // Copying a ByteString is very efficient, since the internal StringImpl is
26
26
// retainable and so copying only requires modifying the ref count.
27
27
//
28
- // There are three main ways to construct a new DeprecatedString :
28
+ // There are three main ways to construct a new ByteString :
29
29
//
30
- // s = DeprecatedString ("some literal");
30
+ // s = ByteString ("some literal");
31
31
//
32
- // s = DeprecatedString ::formatted("{} little piggies", m_piggies);
32
+ // s = ByteString ::formatted("{} little piggies", m_piggies);
33
33
//
34
34
// StringBuilder builder;
35
35
// builder.append("abc");
36
36
// builder.append("123");
37
- // s = builder.to_deprecated_string ();
37
+ // s = builder.to_byte_string ();
38
38
39
- class DeprecatedString {
39
+ class ByteString {
40
40
public:
41
- ~DeprecatedString () = default ;
41
+ ~ByteString () = default ;
42
42
43
- DeprecatedString ()
43
+ ByteString ()
44
44
: m_impl(StringImpl::the_empty_stringimpl())
45
45
{
46
46
}
47
47
48
- DeprecatedString (StringView view)
48
+ ByteString (StringView view)
49
49
: m_impl(*StringImpl::create (view.characters_without_null_termination(), view.length()))
50
50
{
51
51
}
52
52
53
- DeprecatedString (DeprecatedString const & other)
53
+ ByteString (ByteString const & other)
54
54
: m_impl(other.m_impl)
55
55
{
56
56
}
57
57
58
- DeprecatedString (DeprecatedString && other)
58
+ ByteString (ByteString && other)
59
59
: m_impl(move(other.m_impl))
60
60
{
61
61
other.m_impl = StringImpl::the_empty_stringimpl ();
62
62
}
63
63
64
- DeprecatedString (char const * cstring, ShouldChomp shouldChomp = NoChomp)
64
+ ByteString (char const * cstring, ShouldChomp shouldChomp = NoChomp)
65
65
: m_impl(*StringImpl::create (cstring, shouldChomp))
66
66
{
67
67
}
68
68
69
- DeprecatedString (char const * cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
69
+ ByteString (char const * cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
70
70
: m_impl(*StringImpl::create (cstring, length, shouldChomp))
71
71
{
72
72
}
73
73
74
- explicit DeprecatedString (ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
74
+ explicit ByteString (ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
75
75
: m_impl(*StringImpl::create (bytes, shouldChomp))
76
76
{
77
77
}
78
78
79
- DeprecatedString (StringImpl const & impl)
79
+ ByteString (StringImpl const & impl)
80
80
: m_impl(impl)
81
81
{
82
82
}
83
83
84
- DeprecatedString (NonnullRefPtr<StringImpl const >&& impl)
84
+ ByteString (NonnullRefPtr<StringImpl const >&& impl)
85
85
: m_impl(*move (impl))
86
86
{
87
87
}
88
88
89
- DeprecatedString (DeprecatedFlyString const &);
89
+ ByteString (DeprecatedFlyString const &);
90
90
91
- static ErrorOr<DeprecatedString > from_utf8 (ReadonlyBytes);
92
- static ErrorOr<DeprecatedString > from_utf8 (StringView string) { return from_utf8 (string.bytes ()); }
91
+ static ErrorOr<ByteString > from_utf8 (ReadonlyBytes);
92
+ static ErrorOr<ByteString > from_utf8 (StringView string) { return from_utf8 (string.bytes ()); }
93
93
94
- [[nodiscard]] static DeprecatedString repeated (char , size_t count);
95
- [[nodiscard]] static DeprecatedString repeated (StringView, size_t count);
94
+ [[nodiscard]] static ByteString repeated (char , size_t count);
95
+ [[nodiscard]] static ByteString repeated (StringView, size_t count);
96
96
97
- [[nodiscard]] static DeprecatedString bijective_base_from (size_t value, unsigned base = 26 , StringView map = {});
98
- [[nodiscard]] static DeprecatedString roman_number_from (size_t value);
97
+ [[nodiscard]] static ByteString bijective_base_from (size_t value, unsigned base = 26 , StringView map = {});
98
+ [[nodiscard]] static ByteString roman_number_from (size_t value);
99
99
100
100
template <class SeparatorType , class CollectionType >
101
- [[nodiscard]] static DeprecatedString join (SeparatorType const & separator, CollectionType const & collection, StringView fmtstr = " {}" sv)
101
+ [[nodiscard]] static ByteString join (SeparatorType const & separator, CollectionType const & collection, StringView fmtstr = " {}" sv)
102
102
{
103
103
StringBuilder builder;
104
104
builder.join (separator, collection, fmtstr);
105
- return builder.to_deprecated_string ();
105
+ return builder.to_byte_string ();
106
106
}
107
107
108
108
[[nodiscard]] bool matches (StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const ;
@@ -117,25 +117,25 @@ class DeprecatedString {
117
117
[[nodiscard]] Optional<float > to_float (TrimWhitespace = TrimWhitespace::Yes) const ;
118
118
#endif
119
119
120
- [[nodiscard]] DeprecatedString to_lowercase () const ;
121
- [[nodiscard]] DeprecatedString to_uppercase () const ;
122
- [[nodiscard]] DeprecatedString to_snakecase () const ;
123
- [[nodiscard]] DeprecatedString to_titlecase () const ;
124
- [[nodiscard]] DeprecatedString invert_case () const ;
120
+ [[nodiscard]] ByteString to_lowercase () const ;
121
+ [[nodiscard]] ByteString to_uppercase () const ;
122
+ [[nodiscard]] ByteString to_snakecase () const ;
123
+ [[nodiscard]] ByteString to_titlecase () const ;
124
+ [[nodiscard]] ByteString invert_case () const ;
125
125
126
126
[[nodiscard]] bool is_whitespace () const { return StringUtils::is_whitespace (*this ); }
127
127
128
128
[[nodiscard]] DeprecatedStringCodePointIterator code_points () const ;
129
129
130
- [[nodiscard]] DeprecatedString trim (StringView characters, TrimMode mode = TrimMode::Both) const
130
+ [[nodiscard]] ByteString trim (StringView characters, TrimMode mode = TrimMode::Both) const
131
131
{
132
132
auto trimmed_view = StringUtils::trim (view (), characters, mode);
133
133
if (view () == trimmed_view)
134
134
return *this ;
135
135
return trimmed_view;
136
136
}
137
137
138
- [[nodiscard]] DeprecatedString trim_whitespace (TrimMode mode = TrimMode::Both) const
138
+ [[nodiscard]] ByteString trim_whitespace (TrimMode mode = TrimMode::Both) const
139
139
{
140
140
auto trimmed_view = StringUtils::trim_whitespace (view (), mode);
141
141
if (view () == trimmed_view)
@@ -148,8 +148,8 @@ class DeprecatedString {
148
148
[[nodiscard]] bool contains (StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const ;
149
149
[[nodiscard]] bool contains (char , CaseSensitivity = CaseSensitivity::CaseSensitive) const ;
150
150
151
- [[nodiscard]] Vector<DeprecatedString > split_limit (char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const ;
152
- [[nodiscard]] Vector<DeprecatedString > split (char separator, SplitBehavior = SplitBehavior::Nothing) const ;
151
+ [[nodiscard]] Vector<ByteString > split_limit (char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const ;
152
+ [[nodiscard]] Vector<ByteString > split (char separator, SplitBehavior = SplitBehavior::Nothing) const ;
153
153
[[nodiscard]] Vector<StringView> split_view (char separator, SplitBehavior = SplitBehavior::Nothing) const ;
154
154
[[nodiscard]] Vector<StringView> split_view (Function<bool (char )> separator, SplitBehavior = SplitBehavior::Nothing) const ;
155
155
@@ -163,8 +163,8 @@ class DeprecatedString {
163
163
164
164
[[nodiscard]] StringView find_last_split_view (char separator) const { return view ().find_last_split_view (separator); }
165
165
166
- [[nodiscard]] DeprecatedString substring (size_t start, size_t length) const ;
167
- [[nodiscard]] DeprecatedString substring (size_t start) const ;
166
+ [[nodiscard]] ByteString substring (size_t start, size_t length) const ;
167
+ [[nodiscard]] ByteString substring (size_t start) const ;
168
168
[[nodiscard]] StringView substring_view (size_t start, size_t length) const ;
169
169
[[nodiscard]] StringView substring_view (size_t start) const ;
170
170
@@ -190,7 +190,7 @@ class DeprecatedString {
190
190
return bit_cast<u8>((*m_impl)[i]);
191
191
}
192
192
193
- using ConstIterator = SimpleIterator<const DeprecatedString , char const >;
193
+ using ConstIterator = SimpleIterator<const ByteString , char const >;
194
194
195
195
[[nodiscard]] constexpr ConstIterator begin () const { return ConstIterator::begin (*this ); }
196
196
[[nodiscard]] constexpr ConstIterator end () const { return ConstIterator::end (*this ); }
@@ -200,47 +200,47 @@ class DeprecatedString {
200
200
[[nodiscard]] bool starts_with (char ) const ;
201
201
[[nodiscard]] bool ends_with (char ) const ;
202
202
203
- bool operator ==(DeprecatedString const &) const ;
203
+ bool operator ==(ByteString const &) const ;
204
204
205
205
bool operator ==(StringView) const ;
206
206
207
207
bool operator ==(DeprecatedFlyString const &) const ;
208
208
209
- bool operator <(DeprecatedString const &) const ;
210
- bool operator >=(DeprecatedString const & other) const { return !(*this < other); }
209
+ bool operator <(ByteString const &) const ;
210
+ bool operator >=(ByteString const & other) const { return !(*this < other); }
211
211
bool operator >=(char const * other) const { return !(*this < other); }
212
212
213
- bool operator >(DeprecatedString const &) const ;
214
- bool operator <=(DeprecatedString const & other) const { return !(*this > other); }
213
+ bool operator >(ByteString const &) const ;
214
+ bool operator <=(ByteString const & other) const { return !(*this > other); }
215
215
bool operator <=(char const * other) const { return !(*this > other); }
216
216
217
217
bool operator ==(char const * cstring) const ;
218
218
219
- [[nodiscard]] DeprecatedString isolated_copy () const ;
219
+ [[nodiscard]] ByteString isolated_copy () const ;
220
220
221
- [[nodiscard]] static DeprecatedString empty ()
221
+ [[nodiscard]] static ByteString empty ()
222
222
{
223
223
return StringImpl::the_empty_stringimpl ();
224
224
}
225
225
226
226
[[nodiscard]] StringImpl const * impl () const { return m_impl.ptr (); }
227
227
228
- DeprecatedString & operator =(DeprecatedString && other)
228
+ ByteString & operator =(ByteString && other)
229
229
{
230
230
if (this != &other)
231
231
m_impl = move (other.m_impl );
232
232
return *this ;
233
233
}
234
234
235
- DeprecatedString & operator =(DeprecatedString const & other)
235
+ ByteString & operator =(ByteString const & other)
236
236
{
237
237
if (this != &other)
238
- m_impl = const_cast <DeprecatedString &>(other).m_impl ;
238
+ m_impl = const_cast <ByteString &>(other).m_impl ;
239
239
return *this ;
240
240
}
241
241
242
242
template <OneOf<ReadonlyBytes, Bytes> T>
243
- DeprecatedString & operator =(T bytes)
243
+ ByteString & operator =(T bytes)
244
244
{
245
245
m_impl = *StringImpl::create (bytes);
246
246
return *this ;
@@ -254,24 +254,24 @@ class DeprecatedString {
254
254
[[nodiscard]] ByteBuffer to_byte_buffer () const ;
255
255
256
256
template <typename BufferType>
257
- [[nodiscard]] static DeprecatedString copy (BufferType const & buffer, ShouldChomp should_chomp = NoChomp)
257
+ [[nodiscard]] static ByteString copy (BufferType const & buffer, ShouldChomp should_chomp = NoChomp)
258
258
{
259
259
if (buffer.is_empty ())
260
260
return empty ();
261
- return DeprecatedString (reinterpret_cast <char const *>(buffer.data ()), buffer.size (), should_chomp);
261
+ return ByteString (reinterpret_cast <char const *>(buffer.data ()), buffer.size (), should_chomp);
262
262
}
263
263
264
- [[nodiscard]] static DeprecatedString vformatted (StringView fmtstr, TypeErasedFormatParams&);
264
+ [[nodiscard]] static ByteString vformatted (StringView fmtstr, TypeErasedFormatParams&);
265
265
266
266
template <typename ... Parameters>
267
- [[nodiscard]] static DeprecatedString formatted (CheckedFormatString<Parameters...>&& fmtstr, Parameters const &... parameters)
267
+ [[nodiscard]] static ByteString formatted (CheckedFormatString<Parameters...>&& fmtstr, Parameters const &... parameters)
268
268
{
269
269
VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
270
270
return vformatted (fmtstr.view (), variadic_format_parameters);
271
271
}
272
272
273
273
template <Arithmetic T>
274
- [[nodiscard]] static DeprecatedString number (T value)
274
+ [[nodiscard]] static ByteString number (T value)
275
275
{
276
276
return formatted (" {}" , value);
277
277
}
@@ -281,9 +281,9 @@ class DeprecatedString {
281
281
return { characters (), length () };
282
282
}
283
283
284
- [[nodiscard]] DeprecatedString replace (StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace (*this , needle, replacement, replace_mode); }
284
+ [[nodiscard]] ByteString replace (StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace (*this , needle, replacement, replace_mode); }
285
285
[[nodiscard]] size_t count (StringView needle) const { return StringUtils::count (*this , needle); }
286
- [[nodiscard]] DeprecatedString reverse () const ;
286
+ [[nodiscard]] ByteString reverse () const ;
287
287
288
288
template <typename ... Ts>
289
289
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of (Ts&&... strings) const
@@ -308,17 +308,17 @@ class DeprecatedString {
308
308
};
309
309
310
310
template <>
311
- struct Traits <DeprecatedString > : public DefaultTraits<DeprecatedString > {
312
- static unsigned hash (DeprecatedString const & s) { return s.impl () ? s.impl ()->hash () : 0 ; }
311
+ struct Traits <ByteString > : public DefaultTraits<ByteString > {
312
+ static unsigned hash (ByteString const & s) { return s.impl () ? s.impl ()->hash () : 0 ; }
313
313
};
314
314
315
315
// FIXME: Rename this to indicate that it's about ASCII-only case insensitivity.
316
- struct CaseInsensitiveStringTraits : public Traits <DeprecatedString > {
317
- static unsigned hash (DeprecatedString const & s) { return s.impl () ? s.impl ()->case_insensitive_hash () : 0 ; }
318
- static bool equals (DeprecatedString const & a, DeprecatedString const & b) { return a.equals_ignoring_ascii_case (b); }
316
+ struct CaseInsensitiveStringTraits : public Traits <ByteString > {
317
+ static unsigned hash (ByteString const & s) { return s.impl () ? s.impl ()->case_insensitive_hash () : 0 ; }
318
+ static bool equals (ByteString const & a, ByteString const & b) { return a.equals_ignoring_ascii_case (b); }
319
319
};
320
320
321
- DeprecatedString escape_html_entities (StringView html);
321
+ ByteString escape_html_entities (StringView html);
322
322
323
323
}
324
324
0 commit comments