Skip to content

Commit 5e1499d

Browse files
committed
Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
1 parent 38d6256 commit 5e1499d

File tree

1,615 files changed

+10269
-10269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,615 files changed

+10269
-10269
lines changed

AK/DeprecatedString.cpp AK/ByteString.cpp

+68-68
Large diffs are not rendered by default.

AK/DeprecatedString.h AK/ByteString.h

+62-62
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,93 @@
1616

1717
namespace AK {
1818

19-
// DeprecatedString is a convenience wrapper around StringImpl, suitable for passing
19+
// ByteString is a convenience wrapper around StringImpl, suitable for passing
2020
// around as a value type. It's basically the same as passing around a
2121
// RefPtr<StringImpl const>, with a bit of syntactic sugar.
2222
//
2323
// Note that StringImpl is an immutable object that cannot shrink or grow.
2424
// 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
2626
// retainable and so copying only requires modifying the ref count.
2727
//
28-
// There are three main ways to construct a new DeprecatedString:
28+
// There are three main ways to construct a new ByteString:
2929
//
30-
// s = DeprecatedString("some literal");
30+
// s = ByteString("some literal");
3131
//
32-
// s = DeprecatedString::formatted("{} little piggies", m_piggies);
32+
// s = ByteString::formatted("{} little piggies", m_piggies);
3333
//
3434
// StringBuilder builder;
3535
// builder.append("abc");
3636
// builder.append("123");
37-
// s = builder.to_deprecated_string();
37+
// s = builder.to_byte_string();
3838

39-
class DeprecatedString {
39+
class ByteString {
4040
public:
41-
~DeprecatedString() = default;
41+
~ByteString() = default;
4242

43-
DeprecatedString()
43+
ByteString()
4444
: m_impl(StringImpl::the_empty_stringimpl())
4545
{
4646
}
4747

48-
DeprecatedString(StringView view)
48+
ByteString(StringView view)
4949
: m_impl(*StringImpl::create(view.characters_without_null_termination(), view.length()))
5050
{
5151
}
5252

53-
DeprecatedString(DeprecatedString const& other)
53+
ByteString(ByteString const& other)
5454
: m_impl(other.m_impl)
5555
{
5656
}
5757

58-
DeprecatedString(DeprecatedString&& other)
58+
ByteString(ByteString&& other)
5959
: m_impl(move(other.m_impl))
6060
{
6161
other.m_impl = StringImpl::the_empty_stringimpl();
6262
}
6363

64-
DeprecatedString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
64+
ByteString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
6565
: m_impl(*StringImpl::create(cstring, shouldChomp))
6666
{
6767
}
6868

69-
DeprecatedString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
69+
ByteString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
7070
: m_impl(*StringImpl::create(cstring, length, shouldChomp))
7171
{
7272
}
7373

74-
explicit DeprecatedString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
74+
explicit ByteString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
7575
: m_impl(*StringImpl::create(bytes, shouldChomp))
7676
{
7777
}
7878

79-
DeprecatedString(StringImpl const& impl)
79+
ByteString(StringImpl const& impl)
8080
: m_impl(impl)
8181
{
8282
}
8383

84-
DeprecatedString(NonnullRefPtr<StringImpl const>&& impl)
84+
ByteString(NonnullRefPtr<StringImpl const>&& impl)
8585
: m_impl(*move(impl))
8686
{
8787
}
8888

89-
DeprecatedString(DeprecatedFlyString const&);
89+
ByteString(DeprecatedFlyString const&);
9090

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()); }
9393

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);
9696

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);
9999

100100
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)
102102
{
103103
StringBuilder builder;
104104
builder.join(separator, collection, fmtstr);
105-
return builder.to_deprecated_string();
105+
return builder.to_byte_string();
106106
}
107107

108108
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
@@ -117,25 +117,25 @@ class DeprecatedString {
117117
[[nodiscard]] Optional<float> to_float(TrimWhitespace = TrimWhitespace::Yes) const;
118118
#endif
119119

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;
125125

126126
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
127127

128128
[[nodiscard]] DeprecatedStringCodePointIterator code_points() const;
129129

130-
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
130+
[[nodiscard]] ByteString trim(StringView characters, TrimMode mode = TrimMode::Both) const
131131
{
132132
auto trimmed_view = StringUtils::trim(view(), characters, mode);
133133
if (view() == trimmed_view)
134134
return *this;
135135
return trimmed_view;
136136
}
137137

138-
[[nodiscard]] DeprecatedString trim_whitespace(TrimMode mode = TrimMode::Both) const
138+
[[nodiscard]] ByteString trim_whitespace(TrimMode mode = TrimMode::Both) const
139139
{
140140
auto trimmed_view = StringUtils::trim_whitespace(view(), mode);
141141
if (view() == trimmed_view)
@@ -148,8 +148,8 @@ class DeprecatedString {
148148
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
149149
[[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
150150

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;
153153
[[nodiscard]] Vector<StringView> split_view(char separator, SplitBehavior = SplitBehavior::Nothing) const;
154154
[[nodiscard]] Vector<StringView> split_view(Function<bool(char)> separator, SplitBehavior = SplitBehavior::Nothing) const;
155155

@@ -163,8 +163,8 @@ class DeprecatedString {
163163

164164
[[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
165165

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;
168168
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
169169
[[nodiscard]] StringView substring_view(size_t start) const;
170170

@@ -190,7 +190,7 @@ class DeprecatedString {
190190
return bit_cast<u8>((*m_impl)[i]);
191191
}
192192

193-
using ConstIterator = SimpleIterator<const DeprecatedString, char const>;
193+
using ConstIterator = SimpleIterator<const ByteString, char const>;
194194

195195
[[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
196196
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
@@ -200,47 +200,47 @@ class DeprecatedString {
200200
[[nodiscard]] bool starts_with(char) const;
201201
[[nodiscard]] bool ends_with(char) const;
202202

203-
bool operator==(DeprecatedString const&) const;
203+
bool operator==(ByteString const&) const;
204204

205205
bool operator==(StringView) const;
206206

207207
bool operator==(DeprecatedFlyString const&) const;
208208

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); }
211211
bool operator>=(char const* other) const { return !(*this < other); }
212212

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); }
215215
bool operator<=(char const* other) const { return !(*this > other); }
216216

217217
bool operator==(char const* cstring) const;
218218

219-
[[nodiscard]] DeprecatedString isolated_copy() const;
219+
[[nodiscard]] ByteString isolated_copy() const;
220220

221-
[[nodiscard]] static DeprecatedString empty()
221+
[[nodiscard]] static ByteString empty()
222222
{
223223
return StringImpl::the_empty_stringimpl();
224224
}
225225

226226
[[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); }
227227

228-
DeprecatedString& operator=(DeprecatedString&& other)
228+
ByteString& operator=(ByteString&& other)
229229
{
230230
if (this != &other)
231231
m_impl = move(other.m_impl);
232232
return *this;
233233
}
234234

235-
DeprecatedString& operator=(DeprecatedString const& other)
235+
ByteString& operator=(ByteString const& other)
236236
{
237237
if (this != &other)
238-
m_impl = const_cast<DeprecatedString&>(other).m_impl;
238+
m_impl = const_cast<ByteString&>(other).m_impl;
239239
return *this;
240240
}
241241

242242
template<OneOf<ReadonlyBytes, Bytes> T>
243-
DeprecatedString& operator=(T bytes)
243+
ByteString& operator=(T bytes)
244244
{
245245
m_impl = *StringImpl::create(bytes);
246246
return *this;
@@ -254,24 +254,24 @@ class DeprecatedString {
254254
[[nodiscard]] ByteBuffer to_byte_buffer() const;
255255

256256
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)
258258
{
259259
if (buffer.is_empty())
260260
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);
262262
}
263263

264-
[[nodiscard]] static DeprecatedString vformatted(StringView fmtstr, TypeErasedFormatParams&);
264+
[[nodiscard]] static ByteString vformatted(StringView fmtstr, TypeErasedFormatParams&);
265265

266266
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)
268268
{
269269
VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
270270
return vformatted(fmtstr.view(), variadic_format_parameters);
271271
}
272272

273273
template<Arithmetic T>
274-
[[nodiscard]] static DeprecatedString number(T value)
274+
[[nodiscard]] static ByteString number(T value)
275275
{
276276
return formatted("{}", value);
277277
}
@@ -281,9 +281,9 @@ class DeprecatedString {
281281
return { characters(), length() };
282282
}
283283

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); }
285285
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); }
286-
[[nodiscard]] DeprecatedString reverse() const;
286+
[[nodiscard]] ByteString reverse() const;
287287

288288
template<typename... Ts>
289289
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
@@ -308,17 +308,17 @@ class DeprecatedString {
308308
};
309309

310310
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; }
313313
};
314314

315315
// 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); }
319319
};
320320

321-
DeprecatedString escape_html_entities(StringView html);
321+
ByteString escape_html_entities(StringView html);
322322

323323
}
324324

AK/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(AK_SOURCES
66
CountingStream.cpp
77
DOSPackedTime.cpp
88
DeprecatedFlyString.cpp
9-
DeprecatedString.cpp
9+
ByteString.cpp
1010
Error.cpp
1111
FloatingPointStringConversions.cpp
1212
FlyString.cpp

AK/Demangle.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
#ifndef KERNEL
1010

11-
# include <AK/DeprecatedString.h>
11+
# include <AK/ByteString.h>
1212
# include <AK/StringView.h>
1313
# include <cxxabi.h>
1414

1515
namespace AK {
1616

17-
inline DeprecatedString demangle(StringView name)
17+
inline ByteString demangle(StringView name)
1818
{
1919
int status = 0;
20-
auto* demangled_name = abi::__cxa_demangle(name.to_deprecated_string().characters(), nullptr, nullptr, &status);
21-
auto string = DeprecatedString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
20+
auto* demangled_name = abi::__cxa_demangle(name.to_byte_string().characters(), nullptr, nullptr, &status);
21+
auto string = ByteString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
2222
if (status == 0)
2323
free(demangled_name);
2424
return string;

AK/DeprecatedFlyString.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7+
#include <AK/ByteString.h>
78
#include <AK/DeprecatedFlyString.h>
8-
#include <AK/DeprecatedString.h>
99
#include <AK/HashTable.h>
1010
#include <AK/Optional.h>
1111
#include <AK/Singleton.h>
@@ -36,7 +36,7 @@ void DeprecatedFlyString::did_destroy_impl(Badge<StringImpl>, StringImpl& impl)
3636
fly_impls().remove(&impl);
3737
}
3838

39-
DeprecatedFlyString::DeprecatedFlyString(DeprecatedString const& string)
39+
DeprecatedFlyString::DeprecatedFlyString(ByteString const& string)
4040
{
4141
if (string.impl()->is_fly()) {
4242
m_impl = string.impl();
@@ -61,7 +61,7 @@ DeprecatedFlyString::DeprecatedFlyString(StringView string)
6161
return string == *candidate;
6262
});
6363
if (it == fly_impls().end()) {
64-
auto new_string = string.to_deprecated_string();
64+
auto new_string = string.to_byte_string();
6565
fly_impls().set(new_string.impl());
6666
new_string.impl()->set_fly({}, true);
6767
m_impl = new_string.impl();
@@ -122,10 +122,10 @@ bool DeprecatedFlyString::ends_with(StringView str, CaseSensitivity case_sensiti
122122

123123
DeprecatedFlyString DeprecatedFlyString::to_lowercase() const
124124
{
125-
return DeprecatedString(*m_impl).to_lowercase();
125+
return ByteString(*m_impl).to_lowercase();
126126
}
127127

128-
bool DeprecatedFlyString::operator==(DeprecatedString const& other) const
128+
bool DeprecatedFlyString::operator==(ByteString const& other) const
129129
{
130130
return m_impl == other.impl() || view() == other.view();
131131
}

0 commit comments

Comments
 (0)