1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:57:44 +00:00

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')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringBuilder.h>
#include <AK/Variant.h>
#include <LibRegex/Regex.h>
@ -23,7 +23,7 @@ struct internal_regex_t {
Optional<Variant<NonnullOwnPtr<Regex<PosixExtended>>, NonnullOwnPtr<Regex<PosixBasic>>>> re;
size_t re_pat_errpos;
ReError re_pat_err;
DeprecatedString re_pat;
ByteString re_pat;
};
static internal_regex_t* impl_from(regex_t* re)
@ -55,7 +55,7 @@ int regcomp(regex_t* reg, char const* pattern, int cflags)
preg->cflags = cflags;
DeprecatedString pattern_str(pattern);
ByteString pattern_str(pattern);
if (is_extended)
preg->re = make<Regex<PosixExtended>>(pattern_str, PosixOptions {} | (PosixFlags)cflags | PosixFlags::SkipTrimEmptyMatches);
else
@ -193,7 +193,7 @@ static StringView get_error(ReError errcode)
size_t regerror(int errcode, regex_t const* reg, char* errbuf, size_t errbuf_size)
{
DeprecatedString error;
ByteString error;
auto const* preg = impl_from(reg);
if (!preg)

View file

@ -381,7 +381,7 @@ ALWAYS_INLINE ExecutionResult OpCode_SaveRightCaptureGroup::execute(MatchInput c
auto view = input.view.substring_view(start_position, length);
if (input.regex_options & AllFlags::StringCopyMatches) {
match = { view.to_deprecated_string(), input.line, start_position, input.global_offset + start_position }; // create a copy of the original string
match = { view.to_byte_string(), input.line, start_position, input.global_offset + start_position }; // create a copy of the original string
} else {
match = { view, input.line, start_position, input.global_offset + start_position }; // take view to original string
}
@ -406,7 +406,7 @@ ALWAYS_INLINE ExecutionResult OpCode_SaveRightNamedCaptureGroup::execute(MatchIn
auto view = input.view.substring_view(start_position, length);
if (input.regex_options & AllFlags::StringCopyMatches) {
match = { view.to_deprecated_string(), name(), input.line, start_position, input.global_offset + start_position }; // create a copy of the original string
match = { view.to_byte_string(), name(), input.line, start_position, input.global_offset + start_position }; // create a copy of the original string
} else {
match = { view, name(), input.line, start_position, input.global_offset + start_position }; // take view to original string
}
@ -509,7 +509,7 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
if (input.view.length() < state.string_position + length)
return ExecutionResult::Failed_ExecuteLowPrioForks;
Optional<DeprecatedString> str;
Optional<ByteString> str;
Utf16Data utf16;
Vector<u32> data;
data.ensure_capacity(length);
@ -893,9 +893,9 @@ ALWAYS_INLINE void OpCode_Compare::compare_script_extension(MatchInput const& in
}
}
DeprecatedString OpCode_Compare::arguments_string() const
ByteString OpCode_Compare::arguments_string() const
{
return DeprecatedString::formatted("argc={}, args={} ", arguments_count(), arguments_size());
return ByteString::formatted("argc={}, args={} ", arguments_count(), arguments_size());
}
Vector<CompareTypeAndValuePair> OpCode_Compare::flat_compares() const
@ -941,16 +941,16 @@ Vector<CompareTypeAndValuePair> OpCode_Compare::flat_compares() const
return result;
}
Vector<DeprecatedString> OpCode_Compare::variable_arguments_to_deprecated_string(Optional<MatchInput const&> input) const
Vector<ByteString> OpCode_Compare::variable_arguments_to_byte_string(Optional<MatchInput const&> input) const
{
Vector<DeprecatedString> result;
Vector<ByteString> result;
size_t offset { state().instruction_position + 3 };
RegexStringView const& view = ((input.has_value()) ? input.value().view : StringView {});
for (size_t i = 0; i < arguments_count(); ++i) {
auto compare_type = (CharacterCompareType)m_bytecode->at(offset++);
result.empend(DeprecatedString::formatted("type={} [{}]", (size_t)compare_type, character_compare_type_name(compare_type)));
result.empend(ByteString::formatted("type={} [{}]", (size_t)compare_type, character_compare_type_name(compare_type)));
auto string_start_offset = state().string_position_before_match;
@ -958,39 +958,39 @@ Vector<DeprecatedString> OpCode_Compare::variable_arguments_to_deprecated_string
auto ch = m_bytecode->at(offset++);
auto is_ascii = is_ascii_printable(ch);
if (is_ascii)
result.empend(DeprecatedString::formatted(" value='{:c}'", static_cast<char>(ch)));
result.empend(ByteString::formatted(" value='{:c}'", static_cast<char>(ch)));
else
result.empend(DeprecatedString::formatted(" value={:x}", ch));
result.empend(ByteString::formatted(" value={:x}", ch));
if (!view.is_null() && view.length() > string_start_offset) {
if (is_ascii) {
result.empend(DeprecatedString::formatted(
result.empend(ByteString::formatted(
" compare against: '{}'",
view.substring_view(string_start_offset, string_start_offset > view.length() ? 0 : 1).to_deprecated_string()));
view.substring_view(string_start_offset, string_start_offset > view.length() ? 0 : 1).to_byte_string()));
} else {
auto str = view.substring_view(string_start_offset, string_start_offset > view.length() ? 0 : 1).to_deprecated_string();
auto str = view.substring_view(string_start_offset, string_start_offset > view.length() ? 0 : 1).to_byte_string();
u8 buf[8] { 0 };
__builtin_memcpy(buf, str.characters(), min(str.length(), sizeof(buf)));
result.empend(DeprecatedString::formatted(" compare against: {:x},{:x},{:x},{:x},{:x},{:x},{:x},{:x}",
result.empend(ByteString::formatted(" compare against: {:x},{:x},{:x},{:x},{:x},{:x},{:x},{:x}",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]));
}
}
} else if (compare_type == CharacterCompareType::Reference) {
auto ref = m_bytecode->at(offset++);
result.empend(DeprecatedString::formatted(" number={}", ref));
result.empend(ByteString::formatted(" number={}", ref));
if (input.has_value()) {
if (state().capture_group_matches.size() > input->match_index) {
auto& match = state().capture_group_matches[input->match_index];
if (match.size() > ref) {
auto& group = match[ref];
result.empend(DeprecatedString::formatted(" left={}", group.left_column));
result.empend(DeprecatedString::formatted(" right={}", group.left_column + group.view.length_in_code_units()));
result.empend(DeprecatedString::formatted(" contents='{}'", group.view));
result.empend(ByteString::formatted(" left={}", group.left_column));
result.empend(ByteString::formatted(" right={}", group.left_column + group.view.length_in_code_units()));
result.empend(ByteString::formatted(" contents='{}'", group.view));
} else {
result.empend(DeprecatedString::formatted(" (invalid ref, max={})", match.size() - 1));
result.empend(ByteString::formatted(" (invalid ref, max={})", match.size() - 1));
}
} else {
result.empend(DeprecatedString::formatted(" (invalid index {}, max={})", input->match_index, state().capture_group_matches.size() - 1));
result.empend(ByteString::formatted(" (invalid index {}, max={})", input->match_index, state().capture_group_matches.size() - 1));
}
}
} else if (compare_type == CharacterCompareType::String) {
@ -998,42 +998,42 @@ Vector<DeprecatedString> OpCode_Compare::variable_arguments_to_deprecated_string
StringBuilder str_builder;
for (size_t i = 0; i < length; ++i)
str_builder.append(m_bytecode->at(offset++));
result.empend(DeprecatedString::formatted(" value=\"{}\"", str_builder.string_view().substring_view(0, length)));
result.empend(ByteString::formatted(" value=\"{}\"", str_builder.string_view().substring_view(0, length)));
if (!view.is_null() && view.length() > state().string_position)
result.empend(DeprecatedString::formatted(
result.empend(ByteString::formatted(
" compare against: \"{}\"",
input.value().view.substring_view(string_start_offset, string_start_offset + length > view.length() ? 0 : length).to_deprecated_string()));
input.value().view.substring_view(string_start_offset, string_start_offset + length > view.length() ? 0 : length).to_byte_string()));
} else if (compare_type == CharacterCompareType::CharClass) {
auto character_class = (CharClass)m_bytecode->at(offset++);
result.empend(DeprecatedString::formatted(" ch_class={} [{}]", (size_t)character_class, character_class_name(character_class)));
result.empend(ByteString::formatted(" ch_class={} [{}]", (size_t)character_class, character_class_name(character_class)));
if (!view.is_null() && view.length() > state().string_position)
result.empend(DeprecatedString::formatted(
result.empend(ByteString::formatted(
" compare against: '{}'",
input.value().view.substring_view(string_start_offset, state().string_position > view.length() ? 0 : 1).to_deprecated_string()));
input.value().view.substring_view(string_start_offset, state().string_position > view.length() ? 0 : 1).to_byte_string()));
} else if (compare_type == CharacterCompareType::CharRange) {
auto value = (CharRange)m_bytecode->at(offset++);
result.empend(DeprecatedString::formatted(" ch_range={:x}-{:x}", value.from, value.to));
result.empend(ByteString::formatted(" ch_range={:x}-{:x}", value.from, value.to));
if (!view.is_null() && view.length() > state().string_position)
result.empend(DeprecatedString::formatted(
result.empend(ByteString::formatted(
" compare against: '{}'",
input.value().view.substring_view(string_start_offset, state().string_position > view.length() ? 0 : 1).to_deprecated_string()));
input.value().view.substring_view(string_start_offset, state().string_position > view.length() ? 0 : 1).to_byte_string()));
} else if (compare_type == CharacterCompareType::LookupTable) {
auto count = m_bytecode->at(offset++);
for (size_t j = 0; j < count; ++j) {
auto range = (CharRange)m_bytecode->at(offset++);
result.append(DeprecatedString::formatted(" {:x}-{:x}", range.from, range.to));
result.append(ByteString::formatted(" {:x}-{:x}", range.from, range.to));
}
if (!view.is_null() && view.length() > state().string_position)
result.empend(DeprecatedString::formatted(
result.empend(ByteString::formatted(
" compare against: '{}'",
input.value().view.substring_view(string_start_offset, state().string_position > view.length() ? 0 : 1).to_deprecated_string()));
input.value().view.substring_view(string_start_offset, state().string_position > view.length() ? 0 : 1).to_byte_string()));
} else if (compare_type == CharacterCompareType::GeneralCategory
|| compare_type == CharacterCompareType::Property
|| compare_type == CharacterCompareType::Script
|| compare_type == CharacterCompareType::ScriptExtension) {
auto value = m_bytecode->at(offset++);
result.empend(DeprecatedString::formatted(" value={}", value));
result.empend(ByteString::formatted(" value={}", value));
}
}
return result;

View file

@ -583,12 +583,12 @@ public:
return *m_state;
}
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
return DeprecatedString::formatted("[{:#02X}] {}", (int)opcode_id(), name(opcode_id()));
return ByteString::formatted("[{:#02X}] {}", (int)opcode_id(), name(opcode_id()));
}
virtual DeprecatedString arguments_string() const = 0;
virtual ByteString arguments_string() const = 0;
ALWAYS_INLINE ByteCode const& bytecode() const { return *m_bytecode; }
@ -602,7 +602,7 @@ public:
ExecutionResult execute(MatchInput const& input, MatchState& state) const override;
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Exit; }
ALWAYS_INLINE size_t size() const override { return 1; }
DeprecatedString arguments_string() const override { return DeprecatedString::empty(); }
ByteString arguments_string() const override { return ByteString::empty(); }
};
class OpCode_FailForks final : public OpCode {
@ -610,7 +610,7 @@ public:
ExecutionResult execute(MatchInput const& input, MatchState& state) const override;
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::FailForks; }
ALWAYS_INLINE size_t size() const override { return 1; }
DeprecatedString arguments_string() const override { return DeprecatedString::empty(); }
ByteString arguments_string() const override { return ByteString::empty(); }
};
class OpCode_Save final : public OpCode {
@ -618,7 +618,7 @@ public:
ExecutionResult execute(MatchInput const& input, MatchState& state) const override;
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Save; }
ALWAYS_INLINE size_t size() const override { return 1; }
DeprecatedString arguments_string() const override { return DeprecatedString::empty(); }
ByteString arguments_string() const override { return ByteString::empty(); }
};
class OpCode_Restore final : public OpCode {
@ -626,7 +626,7 @@ public:
ExecutionResult execute(MatchInput const& input, MatchState& state) const override;
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Restore; }
ALWAYS_INLINE size_t size() const override { return 1; }
DeprecatedString arguments_string() const override { return DeprecatedString::empty(); }
ByteString arguments_string() const override { return ByteString::empty(); }
};
class OpCode_GoBack final : public OpCode {
@ -635,7 +635,7 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::GoBack; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t count() const { return argument(0); }
DeprecatedString arguments_string() const override { return DeprecatedString::formatted("count={}", count()); }
ByteString arguments_string() const override { return ByteString::formatted("count={}", count()); }
};
class OpCode_Jump final : public OpCode {
@ -644,9 +644,9 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Jump; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
return DeprecatedString::formatted("offset={} [&{}]", offset(), state().instruction_position + size() + offset());
return ByteString::formatted("offset={} [&{}]", offset(), state().instruction_position + size() + offset());
}
};
@ -656,9 +656,9 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkJump; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
return DeprecatedString::formatted("offset={} [&{}], sp: {}", offset(), state().instruction_position + size() + offset(), state().string_position);
return ByteString::formatted("offset={} [&{}], sp: {}", offset(), state().instruction_position + size() + offset(), state().string_position);
}
};
@ -674,9 +674,9 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkStay; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
return DeprecatedString::formatted("offset={} [&{}], sp: {}", offset(), state().instruction_position + size() + offset(), state().string_position);
return ByteString::formatted("offset={} [&{}], sp: {}", offset(), state().instruction_position + size() + offset(), state().string_position);
}
};
@ -691,7 +691,7 @@ public:
ExecutionResult execute(MatchInput const& input, MatchState& state) const override;
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBegin; }
ALWAYS_INLINE size_t size() const override { return 1; }
DeprecatedString arguments_string() const override { return DeprecatedString::empty(); }
ByteString arguments_string() const override { return ByteString::empty(); }
};
class OpCode_CheckEnd final : public OpCode {
@ -699,7 +699,7 @@ public:
ExecutionResult execute(MatchInput const& input, MatchState& state) const override;
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckEnd; }
ALWAYS_INLINE size_t size() const override { return 1; }
DeprecatedString arguments_string() const override { return DeprecatedString::empty(); }
ByteString arguments_string() const override { return ByteString::empty(); }
};
class OpCode_CheckBoundary final : public OpCode {
@ -709,7 +709,7 @@ public:
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t arguments_count() const { return 1; }
ALWAYS_INLINE BoundaryCheckType type() const { return static_cast<BoundaryCheckType>(argument(0)); }
DeprecatedString arguments_string() const override { return DeprecatedString::formatted("kind={} ({})", (long unsigned int)argument(0), boundary_check_type_name(type())); }
ByteString arguments_string() const override { return ByteString::formatted("kind={} ({})", (long unsigned int)argument(0), boundary_check_type_name(type())); }
};
class OpCode_ClearCaptureGroup final : public OpCode {
@ -718,7 +718,7 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ClearCaptureGroup; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t id() const { return argument(0); }
DeprecatedString arguments_string() const override { return DeprecatedString::formatted("id={}", id()); }
ByteString arguments_string() const override { return ByteString::formatted("id={}", id()); }
};
class OpCode_SaveLeftCaptureGroup final : public OpCode {
@ -727,7 +727,7 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftCaptureGroup; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t id() const { return argument(0); }
DeprecatedString arguments_string() const override { return DeprecatedString::formatted("id={}", id()); }
ByteString arguments_string() const override { return ByteString::formatted("id={}", id()); }
};
class OpCode_SaveRightCaptureGroup final : public OpCode {
@ -736,7 +736,7 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightCaptureGroup; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t id() const { return argument(0); }
DeprecatedString arguments_string() const override { return DeprecatedString::formatted("id={}", id()); }
ByteString arguments_string() const override { return ByteString::formatted("id={}", id()); }
};
class OpCode_SaveRightNamedCaptureGroup final : public OpCode {
@ -747,9 +747,9 @@ public:
ALWAYS_INLINE StringView name() const { return { reinterpret_cast<char*>(argument(0)), length() }; }
ALWAYS_INLINE size_t length() const { return argument(1); }
ALWAYS_INLINE size_t id() const { return argument(2); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
return DeprecatedString::formatted("name={}, length={}", name(), length());
return ByteString::formatted("name={}, length={}", name(), length());
}
};
@ -760,8 +760,8 @@ public:
ALWAYS_INLINE size_t size() const override { return arguments_size() + 3; }
ALWAYS_INLINE size_t arguments_count() const { return argument(0); }
ALWAYS_INLINE size_t arguments_size() const { return argument(1); }
DeprecatedString arguments_string() const override;
Vector<DeprecatedString> variable_arguments_to_deprecated_string(Optional<MatchInput const&> input = {}) const;
ByteString arguments_string() const override;
Vector<ByteString> variable_arguments_to_byte_string(Optional<MatchInput const&> input = {}) const;
Vector<CompareTypeAndValuePair> flat_compares() const;
static bool matches_character_class(CharClass, u32, bool insensitive);
@ -784,10 +784,10 @@ public:
ALWAYS_INLINE size_t offset() const { return argument(0); }
ALWAYS_INLINE u64 count() const { return argument(1); }
ALWAYS_INLINE size_t id() const { return argument(2); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
auto reps = id() < state().repetition_marks.size() ? state().repetition_marks.at(id()) : 0;
return DeprecatedString::formatted("offset={} count={} id={} rep={}, sp: {}", offset(), count() + 1, id(), reps + 1, state().string_position);
return ByteString::formatted("offset={} count={} id={} rep={}, sp: {}", offset(), count() + 1, id(), reps + 1, state().string_position);
}
};
@ -797,10 +797,10 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ResetRepeat; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t id() const { return argument(0); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
auto reps = id() < state().repetition_marks.size() ? state().repetition_marks.at(id()) : 0;
return DeprecatedString::formatted("id={} rep={}", id(), reps + 1);
return ByteString::formatted("id={} rep={}", id(), reps + 1);
}
};
@ -810,7 +810,7 @@ public:
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Checkpoint; }
ALWAYS_INLINE size_t size() const override { return 2; }
ALWAYS_INLINE size_t id() const { return argument(0); }
DeprecatedString arguments_string() const override { return DeprecatedString::formatted("id={}", id()); }
ByteString arguments_string() const override { return ByteString::formatted("id={}", id()); }
};
class OpCode_JumpNonEmpty final : public OpCode {
@ -821,9 +821,9 @@ public:
ALWAYS_INLINE ssize_t offset() const { return argument(0); }
ALWAYS_INLINE ssize_t checkpoint() const { return argument(1); }
ALWAYS_INLINE OpCodeId form() const { return (OpCodeId)argument(2); }
DeprecatedString arguments_string() const override
ByteString arguments_string() const override
{
return DeprecatedString::formatted("{} offset={} [&{}], cp={}",
return ByteString::formatted("{} offset={} [&{}], cp={}",
opcode_id_name(form()),
offset(), state().instruction_position + size() + offset(),
checkpoint());

View file

@ -54,19 +54,19 @@ public:
fflush(m_file);
}
void print_opcode(DeprecatedString const& system, OpCode& opcode, MatchState& state, size_t recursion = 0, bool newline = true) const
void print_opcode(ByteString const& system, OpCode& opcode, MatchState& state, size_t recursion = 0, bool newline = true) const
{
out(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}",
system.characters(),
state.instruction_position,
recursion,
opcode.to_deprecated_string().characters(),
opcode.to_byte_string().characters(),
opcode.arguments_string().characters(),
DeprecatedString::formatted("ip: {:3}, sp: {:3}", state.instruction_position, state.string_position));
ByteString::formatted("ip: {:3}, sp: {:3}", state.instruction_position, state.string_position));
if (newline)
outln();
if (newline && is<OpCode_Compare>(opcode)) {
for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_deprecated_string())
for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_byte_string())
outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", line, "");
}
}
@ -84,10 +84,10 @@ public:
builder.appendff(", next ip: {}", state.instruction_position + opcode.size());
}
outln(m_file, " | {:20}", builder.to_deprecated_string());
outln(m_file, " | {:20}", builder.to_byte_string());
if (is<OpCode_Compare>(opcode)) {
for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_deprecated_string(input)) {
for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_byte_string(input)) {
outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", line, "");
}
}
@ -103,7 +103,7 @@ public:
for (size_t i = 0; i < length; ++i) {
builder.append('=');
}
auto str = builder.to_deprecated_string();
auto str = builder.to_byte_string();
VERIFY(!str.is_empty());
outln(m_file, "{}", str);
@ -114,11 +114,11 @@ public:
builder.append('-');
}
builder.append('\n');
m_debug_stripline = builder.to_deprecated_string();
m_debug_stripline = builder.to_byte_string();
}
private:
DeprecatedString m_debug_stripline;
ByteString m_debug_stripline;
FILE* m_file;
};

View file

@ -10,8 +10,8 @@
#include "RegexOptions.h"
#include <AK/Error.h>
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/HashMap.h>
#include <AK/MemMem.h>
#include <AK/RedBlackTree.h>
@ -158,7 +158,7 @@ class RegexStringView {
public:
RegexStringView() = default;
RegexStringView(DeprecatedString const& string)
RegexStringView(ByteString const& string)
: m_view(string.view())
{
}
@ -188,7 +188,7 @@ public:
{
}
explicit RegexStringView(DeprecatedString&&) = delete;
explicit RegexStringView(ByteString&&) = delete;
bool is_string_view() const
{
@ -277,14 +277,14 @@ public:
return view;
}
RegexStringView construct_as_same(Span<u32> data, Optional<DeprecatedString>& optional_string_storage, Utf16Data& optional_utf16_storage) const
RegexStringView construct_as_same(Span<u32> data, Optional<ByteString>& optional_string_storage, Utf16Data& optional_utf16_storage) const
{
auto view = m_view.visit(
[&]<typename T>(T const&) {
StringBuilder builder;
for (auto ch : data)
builder.append(ch); // Note: The type conversion is intentional.
optional_string_storage = builder.to_deprecated_string();
optional_string_storage = builder.to_byte_string();
return RegexStringView { T { *optional_string_storage } };
},
[&](Utf32View) {
@ -392,16 +392,16 @@ public:
return view;
}
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
return m_view.visit(
[](StringView view) { return view.to_deprecated_string(); },
[](Utf16View view) { return view.to_deprecated_string(Utf16View::AllowInvalidCodeUnits::Yes).release_value_but_fixme_should_propagate_errors(); },
[](StringView view) { return view.to_byte_string(); },
[](Utf16View view) { return view.to_byte_string(Utf16View::AllowInvalidCodeUnits::Yes).release_value_but_fixme_should_propagate_errors(); },
[](auto& view) {
StringBuilder builder;
for (auto it = view.begin(); it != view.end(); ++it)
builder.append_code_point(*it);
return builder.to_deprecated_string();
return builder.to_byte_string();
});
}
@ -481,17 +481,17 @@ public:
bool operator==(char const* cstring) const
{
return m_view.visit(
[&](Utf32View) { return to_deprecated_string() == cstring; },
[&](Utf16View) { return to_deprecated_string() == cstring; },
[&](Utf32View) { return to_byte_string() == cstring; },
[&](Utf16View) { return to_byte_string() == cstring; },
[&](Utf8View const& view) { return view.as_string() == cstring; },
[&](StringView view) { return view == cstring; });
}
bool operator==(DeprecatedString const& string) const
bool operator==(ByteString const& string) const
{
return m_view.visit(
[&](Utf32View) { return to_deprecated_string() == string; },
[&](Utf16View) { return to_deprecated_string() == string; },
[&](Utf32View) { return to_byte_string() == string; },
[&](Utf16View) { return to_byte_string() == string; },
[&](Utf8View const& view) { return view.as_string() == string; },
[&](StringView view) { return view == string; });
}
@ -499,8 +499,8 @@ public:
bool operator==(StringView string) const
{
return m_view.visit(
[&](Utf32View) { return to_deprecated_string() == string; },
[&](Utf16View) { return to_deprecated_string() == string; },
[&](Utf32View) { return to_byte_string() == string; },
[&](Utf16View) { return to_byte_string() == string; },
[&](Utf8View const& view) { return view.as_string() == string; },
[&](StringView view) { return view == string; });
}
@ -511,25 +511,25 @@ public:
[&](Utf32View view) {
return view.length() == other.length() && __builtin_memcmp(view.code_points(), other.code_points(), view.length() * sizeof(u32)) == 0;
},
[&](Utf16View) { return to_deprecated_string() == RegexStringView { other }.to_deprecated_string(); },
[&](Utf8View const& view) { return view.as_string() == RegexStringView { other }.to_deprecated_string(); },
[&](StringView view) { return view == RegexStringView { other }.to_deprecated_string(); });
[&](Utf16View) { return to_byte_string() == RegexStringView { other }.to_byte_string(); },
[&](Utf8View const& view) { return view.as_string() == RegexStringView { other }.to_byte_string(); },
[&](StringView view) { return view == RegexStringView { other }.to_byte_string(); });
}
bool operator==(Utf16View const& other) const
{
return m_view.visit(
[&](Utf32View) { return to_deprecated_string() == RegexStringView { other }.to_deprecated_string(); },
[&](Utf32View) { return to_byte_string() == RegexStringView { other }.to_byte_string(); },
[&](Utf16View const& view) { return view == other; },
[&](Utf8View const& view) { return view.as_string() == RegexStringView { other }.to_deprecated_string(); },
[&](StringView view) { return view == RegexStringView { other }.to_deprecated_string(); });
[&](Utf8View const& view) { return view.as_string() == RegexStringView { other }.to_byte_string(); },
[&](StringView view) { return view == RegexStringView { other }.to_byte_string(); });
}
bool operator==(Utf8View const& other) const
{
return m_view.visit(
[&](Utf32View) { return to_deprecated_string() == other.as_string(); },
[&](Utf16View) { return to_deprecated_string() == other.as_string(); },
[&](Utf32View) { return to_byte_string() == other.as_string(); },
[&](Utf16View) { return to_byte_string() == other.as_string(); },
[&](Utf8View const& view) { return view.as_string() == other.as_string(); },
[&](StringView view) { return other.as_string() == view; });
}
@ -620,7 +620,7 @@ public:
{
}
Match(DeprecatedString string_, size_t const line_, size_t const column_, size_t const global_offset_)
Match(ByteString string_, size_t const line_, size_t const column_, size_t const global_offset_)
: string(move(string_))
, view(string.value().view())
, line(line_)
@ -700,7 +700,7 @@ template<>
struct AK::Formatter<regex::RegexStringView> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, regex::RegexStringView value)
{
auto string = value.to_deprecated_string();
auto string = value.to_byte_string();
return Formatter<StringView>::format(builder, string);
}
};

View file

@ -5,8 +5,8 @@
*/
#include <AK/BumpAllocator.h>
#include <AK/ByteString.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/StringBuilder.h>
#include <LibRegex/RegexMatcher.h>
#include <LibRegex/RegexParser.h>
@ -31,7 +31,7 @@ regex::Parser::Result Regex<Parser>::parse_pattern(StringView pattern, typename
}
template<class Parser>
Regex<Parser>::Regex(DeprecatedString pattern, typename ParserTraits<Parser>::OptionsType regex_options)
Regex<Parser>::Regex(ByteString pattern, typename ParserTraits<Parser>::OptionsType regex_options)
: pattern_value(move(pattern))
{
regex::Lexer lexer(pattern_value);
@ -45,7 +45,7 @@ Regex<Parser>::Regex(DeprecatedString pattern, typename ParserTraits<Parser>::Op
}
template<class Parser>
Regex<Parser>::Regex(regex::Parser::Result parse_result, DeprecatedString pattern, typename ParserTraits<Parser>::OptionsType regex_options)
Regex<Parser>::Regex(regex::Parser::Result parse_result, ByteString pattern, typename ParserTraits<Parser>::OptionsType regex_options)
: pattern_value(move(pattern))
, parser_result(move(parse_result))
{
@ -87,7 +87,7 @@ typename ParserTraits<Parser>::OptionsType Regex<Parser>::options() const
}
template<class Parser>
DeprecatedString Regex<Parser>::error_string(Optional<DeprecatedString> message) const
ByteString Regex<Parser>::error_string(Optional<ByteString> message) const
{
StringBuilder eb;
eb.append("Error during parsing of regular expression:\n"sv);
@ -96,7 +96,7 @@ DeprecatedString Regex<Parser>::error_string(Optional<DeprecatedString> message)
eb.append(' ');
eb.appendff("^---- {}", message.value_or(get_error_string(parser_result.error)));
return eb.to_deprecated_string();
return eb.to_byte_string();
}
template<typename Parser>
@ -169,7 +169,7 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
VERIFY(start_position + state.string_position - start_position <= input.view.length());
if (input.regex_options.has_flag_set(AllFlags::StringCopyMatches)) {
state.matches.at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position).to_deprecated_string(), input.line, start_position, input.global_offset + start_position };
state.matches.at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position).to_byte_string(), input.line, start_position, input.global_offset + start_position };
} else { // let the view point to the original string ...
state.matches.at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position), input.line, start_position, input.global_offset + start_position };
}

View file

@ -82,21 +82,21 @@ private:
template<class Parser>
class Regex final {
public:
DeprecatedString pattern_value;
ByteString pattern_value;
regex::Parser::Result parser_result;
OwnPtr<Matcher<Parser>> matcher { nullptr };
mutable size_t start_offset { 0 };
static regex::Parser::Result parse_pattern(StringView pattern, typename ParserTraits<Parser>::OptionsType regex_options = {});
explicit Regex(DeprecatedString pattern, typename ParserTraits<Parser>::OptionsType regex_options = {});
Regex(regex::Parser::Result parse_result, DeprecatedString pattern, typename ParserTraits<Parser>::OptionsType regex_options = {});
explicit Regex(ByteString pattern, typename ParserTraits<Parser>::OptionsType regex_options = {});
Regex(regex::Parser::Result parse_result, ByteString pattern, typename ParserTraits<Parser>::OptionsType regex_options = {});
~Regex() = default;
Regex(Regex&&);
Regex& operator=(Regex&&);
typename ParserTraits<Parser>::OptionsType options() const;
DeprecatedString error_string(Optional<DeprecatedString> message = {}) const;
ByteString error_string(Optional<ByteString> message = {}) const;
RegexResult match(RegexStringView view, Optional<typename ParserTraits<Parser>::OptionsType> regex_options = {}) const
{
@ -112,7 +112,7 @@ public:
return matcher->match(views, regex_options);
}
DeprecatedString replace(RegexStringView view, StringView replacement_pattern, Optional<typename ParserTraits<Parser>::OptionsType> regex_options = {}) const
ByteString replace(RegexStringView view, StringView replacement_pattern, Optional<typename ParserTraits<Parser>::OptionsType> regex_options = {}) const
{
if (!matcher || parser_result.error != Error::NoError)
return {};
@ -121,11 +121,11 @@ public:
size_t start_offset = 0;
RegexResult result = matcher->match(view, regex_options);
if (!result.success)
return view.to_deprecated_string();
return view.to_byte_string();
for (size_t i = 0; i < result.matches.size(); ++i) {
auto& match = result.matches[i];
builder.append(view.substring_view(start_offset, match.global_offset - start_offset).to_deprecated_string());
builder.append(view.substring_view(start_offset, match.global_offset - start_offset).to_byte_string());
start_offset = match.global_offset + match.view.length();
GenericLexer lexer(replacement_pattern);
while (!lexer.is_eof()) {
@ -136,7 +136,7 @@ public:
}
auto number = lexer.consume_while(isdigit);
if (auto index = number.to_uint(); index.has_value() && result.n_capture_groups >= index.value()) {
builder.append(result.capture_group_matches[i][index.value() - 1].view.to_deprecated_string());
builder.append(result.capture_group_matches[i][index.value() - 1].view.to_byte_string());
} else {
builder.appendff("\\{}", number);
}
@ -146,9 +146,9 @@ public:
}
}
builder.append(view.substring_view(start_offset, view.length() - start_offset).to_deprecated_string());
builder.append(view.substring_view(start_offset, view.length() - start_offset).to_byte_string());
return builder.to_deprecated_string();
return builder.to_byte_string();
}
// FIXME: replace(Vector<RegexStringView> const , ...)

View file

@ -568,7 +568,7 @@ bool Regex<Parser>::attempt_rewrite_entire_match_as_substring_search(BasicBlockL
state.instruction_position += opcode.size();
}
parser_result.optimization_data.pure_substring_search = final_string.to_deprecated_string();
parser_result.optimization_data.pure_substring_search = final_string.to_byte_string();
return true;
}
@ -960,10 +960,10 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
if constexpr (REGEX_DEBUG) {
Function<void(decltype(trie)&, size_t)> print_tree = [&](decltype(trie)& node, size_t indent = 0) mutable {
DeprecatedString name = "(no ip)";
DeprecatedString insn;
ByteString name = "(no ip)";
ByteString insn;
if (node.has_metadata()) {
name = DeprecatedString::formatted(
name = ByteString::formatted(
"{}@{} ({} node{})",
node.metadata_value().first().instruction_position,
node.metadata_value().first().alternative_index,
@ -973,7 +973,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
MatchState state;
state.instruction_position = node.metadata_value().first().instruction_position;
auto& opcode = alternatives[node.metadata_value().first().alternative_index].get_opcode(state);
insn = DeprecatedString::formatted("{} {}", opcode.to_deprecated_string(), opcode.arguments_string());
insn = ByteString::formatted("{} {}", opcode.to_byte_string(), opcode.arguments_string());
}
dbgln("{:->{}}| {} -- {}", "", indent * 2, name, insn);
for (auto& child : node.children())

View file

@ -8,9 +8,9 @@
#include "RegexParser.h"
#include "RegexDebug.h"
#include <AK/AnyOf.h>
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/GenericLexer.h>
#include <AK/ScopeGuard.h>
#include <AK/StringBuilder.h>
@ -75,7 +75,7 @@ ALWAYS_INLINE Token Parser::consume(TokenType type, Error error)
return consume();
}
ALWAYS_INLINE bool Parser::consume(DeprecatedString const& str)
ALWAYS_INLINE bool Parser::consume(ByteString const& str)
{
size_t potentially_go_back { 1 };
for (auto ch : str) {
@ -615,7 +615,7 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_repetition_symbol(ByteCode& byteco
number_builder.append(consume().value());
}
auto maybe_minimum = number_builder.to_deprecated_string().to_uint();
auto maybe_minimum = number_builder.to_byte_string().to_uint();
if (!maybe_minimum.has_value())
return set_error(Error::InvalidBraceContent);
@ -644,7 +644,7 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_repetition_symbol(ByteCode& byteco
number_builder.append(consume().value());
}
if (!number_builder.is_empty()) {
auto value = number_builder.to_deprecated_string().to_uint();
auto value = number_builder.to_byte_string().to_uint();
if (!value.has_value() || minimum > value.value() || *value > s_maximum_repetition_count)
return set_error(Error::InvalidBraceContent);
@ -2560,7 +2560,7 @@ DeprecatedFlyString ECMA262Parser::read_capture_group_specifier(bool take_starti
builder.append_code_point(code_point);
}
DeprecatedFlyString name = builder.to_deprecated_string();
DeprecatedFlyString name = builder.to_byte_string();
if (!hit_end || name.is_empty())
set_error(Error::InvalidNameForCaptureGroup);

View file

@ -57,7 +57,7 @@ public:
AllOptions options;
struct {
Optional<DeprecatedString> pure_substring_search;
Optional<ByteString> pure_substring_search;
} optimization_data {};
};
@ -86,7 +86,7 @@ protected:
ALWAYS_INLINE bool match_ordinary_characters();
ALWAYS_INLINE Token consume();
ALWAYS_INLINE Token consume(TokenType type, Error error);
ALWAYS_INLINE bool consume(DeprecatedString const&);
ALWAYS_INLINE bool consume(ByteString const&);
ALWAYS_INLINE Optional<u32> consume_escaped_code_point(bool unicode);
ALWAYS_INLINE bool try_skip(StringView);
ALWAYS_INLINE bool lookahead_any(StringView);