1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:07:34 +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,9 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteString.h>
#include <AK/Debug.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/FixedArray.h>
#include <AK/Format.h>
#include <AK/IntegralMath.h>
@ -63,11 +63,11 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
BigEndianInputBitStream bit_input { MaybeOwned<Stream>(*m_stream) };
// A mixture of VERIFY and the non-crashing TRY().
#define FLAC_VERIFY(check, category, msg) \
do { \
if (!(check)) { \
return LoaderError { category, TRY(m_stream->tell()), DeprecatedString::formatted("FLAC header: {}", msg) }; \
} \
#define FLAC_VERIFY(check, category, msg) \
do { \
if (!(check)) { \
return LoaderError { category, TRY(m_stream->tell()), ByteString::formatted("FLAC header: {}", msg) }; \
} \
} while (0)
// Magic number
@ -305,7 +305,7 @@ MaybeLoaderError FlacLoaderPlugin::seek(int int_sample_index)
dbgln_if(AFLACLOADER_DEBUG, "Seeking to seektable: sample index {}, byte offset {}", target_seekpoint.sample_index, target_seekpoint.byte_offset);
auto position = target_seekpoint.byte_offset + m_data_start_location;
if (m_stream->seek(static_cast<i64>(position), SeekMode::SetPosition).is_error())
return LoaderError { LoaderError::Category::IO, m_loaded_samples, DeprecatedString::formatted("Invalid seek position {}", position) };
return LoaderError { LoaderError::Category::IO, m_loaded_samples, ByteString::formatted("Invalid seek position {}", position) };
m_loaded_samples = target_seekpoint.sample_index;
}
}
@ -367,11 +367,11 @@ ErrorOr<Vector<FixedArray<Sample>>, LoaderError> FlacLoaderPlugin::load_chunks(s
// 11.21. FRAME
LoaderSamples FlacLoaderPlugin::next_frame()
{
#define FLAC_VERIFY(check, category, msg) \
do { \
if (!(check)) { \
return LoaderError { category, static_cast<size_t>(m_current_sample_or_frame), DeprecatedString::formatted("FLAC header: {}", msg) }; \
} \
#define FLAC_VERIFY(check, category, msg) \
do { \
if (!(check)) { \
return LoaderError { category, static_cast<size_t>(m_current_sample_or_frame), ByteString::formatted("FLAC header: {}", msg) }; \
} \
} while (0)
auto frame_byte_index = TRY(m_stream->tell());
@ -612,7 +612,7 @@ ErrorOr<u8, LoaderError> FlacLoaderPlugin::convert_bit_depth_code(u8 bit_depth_c
case 7:
return 32;
default:
return LoaderError { LoaderError::Category::Format, static_cast<size_t>(m_current_sample_or_frame), DeprecatedString::formatted("Unsupported sample size {}", bit_depth_code) };
return LoaderError { LoaderError::Category::Format, static_cast<size_t>(m_current_sample_or_frame), ByteString::formatted("Unsupported sample size {}", bit_depth_code) };
}
}
@ -900,7 +900,7 @@ ErrorOr<Vector<i64>, LoaderError> FlacLoaderPlugin::decode_fixed_lpc(FlacSubfram
decoded[i] += 4 * decoded[i - 1] - 6 * decoded[i - 2] + 4 * decoded[i - 3] - decoded[i - 4];
break;
default:
return LoaderError { LoaderError::Category::Format, static_cast<size_t>(m_current_sample_or_frame), DeprecatedString::formatted("Unrecognized predictor order {}", subframe.order) };
return LoaderError { LoaderError::Category::Format, static_cast<size_t>(m_current_sample_or_frame), ByteString::formatted("Unrecognized predictor order {}", subframe.order) };
}
return decoded;
}

View file

@ -52,7 +52,7 @@ public:
virtual int total_samples() override { return static_cast<int>(m_total_samples); }
virtual u32 sample_rate() override { return m_sample_rate; }
virtual u16 num_channels() override { return m_num_channels; }
virtual DeprecatedString format_name() override { return "FLAC (.flac)"; }
virtual ByteString format_name() override { return "FLAC (.flac)"; }
virtual PcmSampleFormat pcm_format() override { return m_sample_format; }
bool is_fixed_blocksize_stream() const { return m_min_block_size == m_max_block_size; }

View file

@ -70,7 +70,7 @@ public:
virtual u16 num_channels() = 0;
// Human-readable name of the file format, of the form <full abbreviation> (.<ending>)
virtual DeprecatedString format_name() = 0;
virtual ByteString format_name() = 0;
virtual PcmSampleFormat pcm_format() = 0;
Metadata const& metadata() const { return m_metadata; }
@ -107,7 +107,7 @@ public:
int total_samples() const { return m_plugin->total_samples(); }
u32 sample_rate() const { return m_plugin->sample_rate(); }
u16 num_channels() const { return m_plugin->num_channels(); }
DeprecatedString format_name() const { return m_plugin->format_name(); }
ByteString format_name() const { return m_plugin->format_name(); }
u16 bits_per_sample() const { return pcm_bits_per_sample(m_plugin->pcm_format()); }
PcmSampleFormat pcm_format() const { return m_plugin->pcm_format(); }
Metadata const& metadata() const { return m_plugin->metadata(); }

View file

@ -28,7 +28,7 @@ struct LoaderError {
Category category { Category::Unknown };
// Binary index: where in the file the error occurred.
size_t index { 0 };
DeprecatedFlyString description { DeprecatedString::empty() };
DeprecatedFlyString description { ByteString::empty() };
constexpr LoaderError() = default;
LoaderError(Category category, size_t index, DeprecatedFlyString description)
@ -54,7 +54,7 @@ struct LoaderError {
{
if (error.is_errno()) {
auto code = error.code();
description = DeprecatedString::formatted("{} ({})", strerror(code), code);
description = ByteString::formatted("{} ({})", strerror(code), code);
if (code == EBADF || code == EBUSY || code == EEXIST || code == EIO || code == EISDIR || code == ENOENT || code == ENOMEM || code == EPIPE)
category = Category::IO;
} else {

View file

@ -37,7 +37,7 @@ public:
virtual u32 sample_rate() override { return m_sample_rate; }
virtual u16 num_channels() override { return m_num_channels; }
virtual PcmSampleFormat pcm_format() override { return m_sample_format; }
virtual DeprecatedString format_name() override { return "MP3 (.mp3)"; }
virtual ByteString format_name() override { return "MP3 (.mp3)"; }
private:
MaybeLoaderError initialize();

View file

@ -37,7 +37,7 @@ public:
virtual int total_samples() override { return static_cast<int>(m_total_samples); }
virtual u32 sample_rate() override { return m_sample_rate; }
virtual u16 num_channels() override { return m_num_channels; }
virtual DeprecatedString format_name() override { return "Quite Okay Audio (.qoa)"; }
virtual ByteString format_name() override { return "Quite Okay Audio (.qoa)"; }
virtual PcmSampleFormat pcm_format() override { return PcmSampleFormat::Int16; }
private:

View file

@ -48,10 +48,10 @@ Optional<PcmSampleFormat> integer_sample_format_for(u16 bits_per_sample)
}
}
DeprecatedString sample_format_name(PcmSampleFormat format)
ByteString sample_format_name(PcmSampleFormat format)
{
bool is_float = format == PcmSampleFormat::Float32 || format == PcmSampleFormat::Float64;
return DeprecatedString::formatted("PCM {}bit {}", pcm_bits_per_sample(format), is_float ? "Float" : "LE");
return ByteString::formatted("PCM {}bit {}", pcm_bits_per_sample(format), is_float ? "Float" : "LE");
}
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Types.h>
namespace Audio {
@ -25,5 +25,5 @@ enum class PcmSampleFormat : u8 {
u16 pcm_bits_per_sample(PcmSampleFormat format);
bool is_integer_format(PcmSampleFormat format);
Optional<PcmSampleFormat> integer_sample_format_for(u16 bits_per_sample);
DeprecatedString sample_format_name(PcmSampleFormat format);
ByteString sample_format_name(PcmSampleFormat format);
}

View file

@ -178,11 +178,11 @@ MaybeLoaderError WavLoaderPlugin::seek(int sample_index)
// Specification reference: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
MaybeLoaderError WavLoaderPlugin::parse_header()
{
#define CHECK(check, category, msg) \
do { \
if (!(check)) { \
return LoaderError { category, static_cast<size_t>(TRY(m_stream->tell())), DeprecatedString::formatted("WAV header: {}", msg) }; \
} \
#define CHECK(check, category, msg) \
do { \
if (!(check)) { \
return LoaderError { category, static_cast<size_t>(TRY(m_stream->tell())), ByteString::formatted("WAV header: {}", msg) }; \
} \
} while (0)
auto riff = TRY(m_stream->read_value<RIFF::ChunkID>());

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/FixedArray.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
@ -41,7 +41,7 @@ public:
virtual int total_samples() override { return static_cast<int>(m_total_samples); }
virtual u32 sample_rate() override { return m_sample_rate; }
virtual u16 num_channels() override { return m_num_channels; }
virtual DeprecatedString format_name() override { return "RIFF WAVE (.wav)"; }
virtual ByteString format_name() override { return "RIFF WAVE (.wav)"; }
virtual PcmSampleFormat pcm_format() override { return m_sample_format; }
private:

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Noncopyable.h>
#include <AK/RefPtr.h>
#include <AK/StringView.h>

View file

@ -7,11 +7,11 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Result.h>
struct DlErrorMessage {
DlErrorMessage(DeprecatedString&& other)
DlErrorMessage(ByteString&& other)
: text(move(other))
{
}
@ -21,7 +21,7 @@ struct DlErrorMessage {
// from the one in libc.so
virtual ~DlErrorMessage() = default;
DeprecatedString text;
ByteString text;
};
struct __Dl_info;

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Types.h>
#include <bits/dlfcn_integration.h>
#include <dlfcn.h>
@ -25,7 +25,7 @@ __thread char* s_dlerror_text = NULL;
__thread bool s_dlerror_retrieved = false;
#endif
static void store_error(DeprecatedString const& error)
static void store_error(ByteString const& error)
{
free(s_dlerror_text);
s_dlerror_text = strdup(error.characters());

View file

@ -6,7 +6,7 @@
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/ScopeGuard.h>
#include <Kernel/Net/IPv4.h>
#include <arpa/inet.h>
@ -54,8 +54,8 @@ struct ServiceFileLine {
static ErrorOr<Optional<ServiceFileLine>> parse_service_file_line(char const* line, ssize_t read);
static servent __getserv_buffer;
static DeprecatedString __getserv_name_buffer;
static DeprecatedString __getserv_protocol_buffer;
static ByteString __getserv_name_buffer;
static ByteString __getserv_protocol_buffer;
static int __getserv_port_buffer;
static Vector<ByteBuffer> __getserv_alias_list_buffer;
static Vector<char*> __getserv_alias_list;
@ -68,7 +68,7 @@ static char const* protocols_path = "/etc/protocols";
static bool fill_getproto_buffers(char const* line, ssize_t read);
static protoent __getproto_buffer;
static DeprecatedString __getproto_name_buffer;
static ByteString __getproto_name_buffer;
static Vector<ByteBuffer> __getproto_alias_list_buffer;
static Vector<char*> __getproto_alias_list;
static int __getproto_protocol_buffer;
@ -96,7 +96,7 @@ static int connect_to_lookup_server()
return fd;
}
static DeprecatedString gethostbyname_name_buffer;
static ByteString gethostbyname_name_buffer;
hostent* gethostbyname(char const* name)
{
@ -226,7 +226,7 @@ int gethostbyname_r(char const* __restrict name, struct hostent* __restrict ret,
auto ipv4_address = IPv4Address::from_string({ name, strlen(name) });
if (ipv4_address.has_value()) {
return populate_ret(ipv4_address.value().to_deprecated_string().characters(), ipv4_address.value().to_in_addr_t());
return populate_ret(ipv4_address.value().to_byte_string().characters(), ipv4_address.value().to_in_addr_t());
}
int fd = connect_to_lookup_server();
@ -318,7 +318,7 @@ int gethostbyname_r(char const* __restrict name, struct hostent* __restrict ret,
return populate_ret(name, address);
}
static DeprecatedString gethostbyaddr_name_buffer;
static ByteString gethostbyaddr_name_buffer;
hostent* gethostbyaddr(void const* addr, socklen_t addr_size, int type)
{
@ -474,9 +474,9 @@ struct servent* getservent()
servent* service_entry = nullptr;
__getserv_name_buffer = service_file_line.value().name.to_deprecated_string();
__getserv_name_buffer = service_file_line.value().name.to_byte_string();
__getserv_port_buffer = service_file_line.value().port;
__getserv_protocol_buffer = service_file_line.value().protocol.to_deprecated_string();
__getserv_protocol_buffer = service_file_line.value().protocol.to_byte_string();
__getserv_alias_list_buffer = service_file_line.value().aliases;
__getserv_buffer.s_name = const_cast<char*>(__getserv_name_buffer.characters());
@ -583,9 +583,9 @@ static ErrorOr<Optional<ServiceFileLine>> parse_service_file_line(char const* li
if (split_line.size() < 2)
return Error::from_string_view("malformed service file"sv);
auto name = TRY(String::from_deprecated_string(split_line[0]));
auto name = TRY(String::from_byte_string(split_line[0]));
auto port_protocol = TRY(String::from_deprecated_string(split_line[1]));
auto port_protocol = TRY(String::from_byte_string(split_line[1]));
auto port_protocol_split = TRY(port_protocol.split('/'));
if (port_protocol_split.size() < 2)
@ -756,7 +756,7 @@ void endprotoent()
static bool fill_getproto_buffers(char const* line, ssize_t read)
{
DeprecatedString string_line = DeprecatedString(line, read);
ByteString string_line = ByteString(line, read);
auto split_line = string_line.replace(" "sv, "\t"sv, ReplaceMode::All).split('\t');
// This indicates an incorrect file format. Protocols file entries should

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/TemporaryChange.h>
#include <AK/Vector.h>
#include <errno.h>
@ -20,8 +20,8 @@ static FILE* s_stream = nullptr;
static unsigned s_line_number = 0;
static struct spwd s_shadow_entry;
static DeprecatedString s_name;
static DeprecatedString s_pwdp;
static ByteString s_name;
static ByteString s_pwdp;
void setspent()
{
@ -61,7 +61,7 @@ struct spwd* getspnam(char const* name)
return nullptr;
}
static bool parse_shadow_entry(DeprecatedString const& line)
static bool parse_shadow_entry(ByteString const& line)
{
auto parts = line.split_view(':', SplitBehavior::KeepEmpty);
if (parts.size() != 9) {
@ -168,7 +168,7 @@ struct spwd* getspent()
if ((!s || !s[0]) && feof(s_stream))
return nullptr;
DeprecatedString line(s, Chomp);
ByteString line(s, Chomp);
if (parse_shadow_entry(line))
return &s_shadow_entry;
// Otherwise, proceed to the next line.

View file

@ -6,7 +6,7 @@
*/
#include <AK/BuiltinWrappers.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Format.h>
#include <AK/PrintfImplementation.h>
#include <AK/ScopedValueRollback.h>
@ -947,7 +947,7 @@ int vasprintf(char** strp, char const* fmt, va_list ap)
builder.appendvf(fmt, ap);
VERIFY(builder.length() <= NumericLimits<int>::max());
int length = builder.length();
*strp = strdup(builder.to_deprecated_string().characters());
*strp = strdup(builder.to_byte_string().characters());
return length;
}
@ -961,7 +961,7 @@ int asprintf(char** strp, char const* fmt, ...)
va_end(ap);
VERIFY(builder.length() <= NumericLimits<int>::max());
int length = builder.length();
*strp = strdup(builder.to_deprecated_string().characters());
*strp = strdup(builder.to_byte_string().characters());
return length;
}

View file

@ -649,7 +649,7 @@ int ptsname_r(int fd, char* buffer, size_t size)
return -1;
}
memset(buffer, 0, devpts_path_builder.length() + 1);
auto full_devpts_path_string = devpts_path_builder.to_deprecated_string();
auto full_devpts_path_string = devpts_path_builder.to_byte_string();
if (!full_devpts_path_string.copy_characters_to_buffer(buffer, size)) {
errno = ERANGE;
return -1;

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Platform.h>
#include <AK/ScopeGuard.h>
#include <fcntl.h>
@ -34,7 +34,7 @@ ALWAYS_INLINE int graphics_connector_get_head_edid(int fd, GraphicsHeadEDID* inf
}
auto minor_number = minor(display_connector_stat.st_rdev);
auto edid_fd = open(DeprecatedString::formatted("/sys/devices/graphics/connectors/{}/edid", minor_number).characters(), O_RDONLY);
auto edid_fd = open(ByteString::formatted("/sys/devices/graphics/connectors/{}/edid", minor_number).characters(), O_RDONLY);
if (edid_fd < 0) {
return edid_fd;
}

View file

@ -7,7 +7,7 @@
// Has to be defined before including due to legacy Unices
#define SYSLOG_NAMES 1
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringBuilder.h>
#include <stdio.h>
#include <string.h>
@ -124,7 +124,7 @@ void vsyslog_r(int priority, struct syslog_data* data, char const* message, va_l
combined.appendff("{}: ", get_syslog_ident(data));
combined.appendvf(message, args);
auto combined_string = combined.to_deprecated_string();
auto combined_string = combined.to_byte_string();
if (data->logopt & LOG_CONS)
dbgputstr(combined_string.characters(), combined_string.length());

View file

@ -414,7 +414,7 @@ size_t strftime(char* destination, size_t max_size, char const* format, const st
return 0;
}
auto str = builder.to_deprecated_string();
auto str = builder.to_byte_string();
bool fits = str.copy_characters_to_buffer(destination, max_size);
return fits ? str.length() : 0;
}

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/ScopeGuard.h>
#include <AK/ScopedValueRollback.h>
#include <AK/Vector.h>
@ -190,12 +190,12 @@ int execvpe(char const* filename, char* const argv[], char* const envp[])
ScopedValueRollback errno_rollback(errno);
// TODO: Make this use the PATH search implementation from LibFileSystem.
DeprecatedString path = getenv("PATH");
ByteString path = getenv("PATH");
if (path.is_empty())
path = DEFAULT_PATH;
auto parts = path.split(':');
for (auto& part : parts) {
auto candidate = DeprecatedString::formatted("{}/{}", part, filename);
auto candidate = ByteString::formatted("{}/{}", part, filename);
int rc = execve(candidate.characters(), argv, envp);
if (rc < 0 && errno != ENOENT) {
errno_rollback.set_override_rollback_value(errno);
@ -881,13 +881,13 @@ void sync()
syscall(SC_sync);
}
static Optional<DeprecatedString> getlogin_buffer {};
static Optional<ByteString> getlogin_buffer {};
char* getlogin()
{
if (!getlogin_buffer.has_value()) {
if (auto* passwd = getpwuid(getuid())) {
getlogin_buffer = DeprecatedString(passwd->pw_name);
getlogin_buffer = ByteString(passwd->pw_name);
}
endpwent();
}

View file

@ -24,8 +24,8 @@ CardPainter& CardPainter::the()
CardPainter::CardPainter()
{
m_back_image_path = MUST(String::from_deprecated_string(Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv, "/res/graphics/cards/backs/Red.png"sv)));
set_front_images_set_name(MUST(String::from_deprecated_string(Config::read_string("Games"sv, "Cards"sv, "CardFrontImages"sv, "Classic"sv))));
m_back_image_path = MUST(String::from_byte_string(Config::read_string("Games"sv, "Cards"sv, "CardBackImage"sv, "/res/graphics/cards/backs/Red.png"sv)));
set_front_images_set_name(MUST(String::from_byte_string(Config::read_string("Games"sv, "Cards"sv, "CardFrontImages"sv, "Classic"sv))));
}
static constexpr Gfx::CharacterBitmap s_diamond {

View file

@ -140,6 +140,6 @@ struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> {
first_card = false;
}
return Formatter<FormatString>::format(builder, "{:<10} {:>16}: {}"sv, type, stack.bounding_box(), cards.to_deprecated_string());
return Formatter<FormatString>::format(builder, "{:<10} {:>16}: {}"sv, type, stack.bounding_box(), cards.to_byte_string());
}
};

View file

@ -19,7 +19,7 @@ class Endpoint : public Core::EventReceiver {
public:
virtual ~Endpoint() override = default;
Function<void(DeprecatedString, Error)> on_command_read_error;
Function<void(ByteString, Error)> on_command_read_error;
virtual void handle_uci() { }
virtual void handle_debug(DebugCommand const&) { }

View file

@ -15,7 +15,7 @@ CodeComprehensionEngine::CodeComprehensionEngine(FileDB const& filedb, bool shou
{
}
void CodeComprehensionEngine::set_declarations_of_document(DeprecatedString const& filename, Vector<Declaration>&& declarations)
void CodeComprehensionEngine::set_declarations_of_document(ByteString const& filename, Vector<Declaration>&& declarations)
{
// Callback may not be configured if we're running tests
if (!set_declarations_of_document_callback)
@ -31,7 +31,7 @@ void CodeComprehensionEngine::set_declarations_of_document(DeprecatedString cons
set_declarations_of_document_callback(filename, move(declarations));
}
void CodeComprehensionEngine::set_todo_entries_of_document(DeprecatedString const& filename, Vector<TodoEntry>&& todo_entries)
void CodeComprehensionEngine::set_todo_entries_of_document(ByteString const& filename, Vector<TodoEntry>&& todo_entries)
{
// Callback may not be configured if we're running tests
if (!set_todo_entries_of_document_callback)

View file

@ -24,33 +24,33 @@ public:
CodeComprehensionEngine(FileDB const& filedb, bool store_all_declarations = false);
virtual ~CodeComprehensionEngine() = default;
virtual Vector<AutocompleteResultEntry> get_suggestions(DeprecatedString const& file, GUI::TextPosition const& autocomplete_position) = 0;
virtual Vector<AutocompleteResultEntry> get_suggestions(ByteString const& file, GUI::TextPosition const& autocomplete_position) = 0;
// TODO: In the future we can pass the range that was edited and only re-parse what we have to.
virtual void on_edit([[maybe_unused]] DeprecatedString const& file) {};
virtual void file_opened([[maybe_unused]] DeprecatedString const& file) {};
virtual void on_edit([[maybe_unused]] ByteString const& file) {};
virtual void file_opened([[maybe_unused]] ByteString const& file) {};
virtual Optional<ProjectLocation> find_declaration_of(DeprecatedString const&, GUI::TextPosition const&) { return {}; }
virtual Optional<ProjectLocation> find_declaration_of(ByteString const&, GUI::TextPosition const&) { return {}; }
struct FunctionParamsHint {
Vector<DeprecatedString> params;
Vector<ByteString> params;
size_t current_index { 0 };
};
virtual Optional<FunctionParamsHint> get_function_params_hint(DeprecatedString const&, GUI::TextPosition const&) { return {}; }
virtual Optional<FunctionParamsHint> get_function_params_hint(ByteString const&, GUI::TextPosition const&) { return {}; }
virtual Vector<TokenInfo> get_tokens_info(DeprecatedString const&) { return {}; }
virtual Vector<TokenInfo> get_tokens_info(ByteString const&) { return {}; }
Function<void(DeprecatedString const&, Vector<Declaration>&&)> set_declarations_of_document_callback;
Function<void(DeprecatedString const&, Vector<TodoEntry>&&)> set_todo_entries_of_document_callback;
Function<void(ByteString const&, Vector<Declaration>&&)> set_declarations_of_document_callback;
Function<void(ByteString const&, Vector<TodoEntry>&&)> set_todo_entries_of_document_callback;
protected:
FileDB const& filedb() const { return m_filedb; }
void set_declarations_of_document(DeprecatedString const&, Vector<Declaration>&&);
void set_todo_entries_of_document(DeprecatedString const&, Vector<TodoEntry>&&);
HashMap<DeprecatedString, Vector<Declaration>> const& all_declarations() const { return m_all_declarations; }
void set_declarations_of_document(ByteString const&, Vector<Declaration>&&);
void set_todo_entries_of_document(ByteString const&, Vector<TodoEntry>&&);
HashMap<ByteString, Vector<Declaration>> const& all_declarations() const { return m_all_declarations; }
private:
HashMap<DeprecatedString, Vector<Declaration>> m_all_declarations;
HashMap<ByteString, Vector<Declaration>> m_all_declarations;
FileDB const& m_filedb;
bool m_store_all_declarations { false };
};

View file

@ -19,10 +19,10 @@ private:
: LanguageServers::ConnectionFromClient(move(socket))
{
m_autocomplete_engine = make<CodeComprehension::Cpp::CppComprehensionEngine>(m_filedb);
m_autocomplete_engine->set_declarations_of_document_callback = [this](DeprecatedString const& filename, Vector<CodeComprehension::Declaration>&& declarations) {
m_autocomplete_engine->set_declarations_of_document_callback = [this](ByteString const& filename, Vector<CodeComprehension::Declaration>&& declarations) {
async_declarations_in_document(filename, move(declarations));
};
m_autocomplete_engine->set_todo_entries_of_document_callback = [this](DeprecatedString const& filename, Vector<CodeComprehension::TodoEntry>&& todo_entries) {
m_autocomplete_engine->set_todo_entries_of_document_callback = [this](ByteString const& filename, Vector<CodeComprehension::TodoEntry>&& todo_entries) {
async_todo_entries_in_document(filename, move(todo_entries));
};
}

View file

@ -25,7 +25,7 @@ CppComprehensionEngine::CppComprehensionEngine(FileDB const& filedb)
{
}
CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_or_create_document_data(DeprecatedString const& file)
CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_or_create_document_data(ByteString const& file)
{
auto absolute_path = filedb().to_absolute_path(file);
if (!m_documents.contains(absolute_path)) {
@ -34,7 +34,7 @@ CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_or_creat
return get_document_data(absolute_path);
}
CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_document_data(DeprecatedString const& file) const
CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_document_data(ByteString const& file) const
{
auto absolute_path = filedb().to_absolute_path(file);
auto document_data = m_documents.get(absolute_path);
@ -43,7 +43,7 @@ CppComprehensionEngine::DocumentData const* CppComprehensionEngine::get_document
return document_data.value();
}
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data_for(DeprecatedString const& file)
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data_for(ByteString const& file)
{
if (m_unfinished_documents.contains(file)) {
return {};
@ -56,12 +56,12 @@ OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_docu
return create_document_data(move(document.value()), file);
}
void CppComprehensionEngine::set_document_data(DeprecatedString const& file, OwnPtr<DocumentData>&& data)
void CppComprehensionEngine::set_document_data(ByteString const& file, OwnPtr<DocumentData>&& data)
{
m_documents.set(filedb().to_absolute_path(file), move(data));
}
Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::get_suggestions(DeprecatedString const& file, const GUI::TextPosition& autocomplete_position)
Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::get_suggestions(ByteString const& file, const GUI::TextPosition& autocomplete_position)
{
Cpp::Position position { autocomplete_position.line(), autocomplete_position.column() > 0 ? autocomplete_position.column() - 1 : 0 };
@ -104,7 +104,7 @@ Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::get_s
Optional<Vector<CodeComprehension::AutocompleteResultEntry>> CppComprehensionEngine::try_autocomplete_name(DocumentData const& document, ASTNode const& node, Optional<Token> containing_token) const
{
auto partial_text = DeprecatedString::empty();
auto partial_text = ByteString::empty();
if (containing_token.has_value() && containing_token.value().type() != Token::Type::ColonColon) {
partial_text = containing_token.value().text();
}
@ -121,7 +121,7 @@ Optional<Vector<CodeComprehension::AutocompleteResultEntry>> CppComprehensionEng
auto const& parent = static_cast<MemberExpression const&>(*node.parent());
auto partial_text = DeprecatedString::empty();
auto partial_text = ByteString::empty();
if (containing_token.value().type() != Token::Type::Dot) {
if (&node != parent.property())
return {};
@ -131,7 +131,7 @@ Optional<Vector<CodeComprehension::AutocompleteResultEntry>> CppComprehensionEng
return autocomplete_property(document, parent, partial_text);
}
Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::autocomplete_name(DocumentData const& document, ASTNode const& node, DeprecatedString const& partial_text) const
Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::autocomplete_name(DocumentData const& document, ASTNode const& node, ByteString const& partial_text) const
{
auto reference_scope = scope_of_reference_to_symbol(node);
auto current_scope = scope_of_node(node);
@ -206,7 +206,7 @@ Vector<StringView> CppComprehensionEngine::scope_of_reference_to_symbol(ASTNode
return scope_parts;
}
Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::autocomplete_property(DocumentData const& document, MemberExpression const& parent, const DeprecatedString partial_text) const
Vector<CodeComprehension::AutocompleteResultEntry> CppComprehensionEngine::autocomplete_property(DocumentData const& document, MemberExpression const& parent, const ByteString partial_text) const
{
VERIFY(parent.object());
auto type = type_of(document, *parent.object());
@ -233,7 +233,7 @@ bool CppComprehensionEngine::is_property(ASTNode const& node) const
return parent.property() == &node;
}
DeprecatedString CppComprehensionEngine::type_of_property(DocumentData const& document, Identifier const& identifier) const
ByteString CppComprehensionEngine::type_of_property(DocumentData const& document, Identifier const& identifier) const
{
auto& parent = verify_cast<MemberExpression>(*identifier.parent());
VERIFY(parent.object());
@ -253,12 +253,12 @@ DeprecatedString CppComprehensionEngine::type_of_property(DocumentData const& do
VERIFY(verify_cast<NamedType>(*type).name());
if (verify_cast<NamedType>(*type).name())
return verify_cast<NamedType>(*type).name()->full_name();
return DeprecatedString::empty();
return ByteString::empty();
}
return {};
}
DeprecatedString CppComprehensionEngine::type_of_variable(Identifier const& identifier) const
ByteString CppComprehensionEngine::type_of_variable(Identifier const& identifier) const
{
ASTNode const* current = &identifier;
while (current) {
@ -269,7 +269,7 @@ DeprecatedString CppComprehensionEngine::type_of_variable(Identifier const& iden
VERIFY(verify_cast<NamedType>(*var_or_param.type()).name());
if (verify_cast<NamedType>(*var_or_param.type()).name())
return verify_cast<NamedType>(*var_or_param.type()).name()->full_name();
return DeprecatedString::empty();
return ByteString::empty();
}
}
}
@ -278,7 +278,7 @@ DeprecatedString CppComprehensionEngine::type_of_variable(Identifier const& iden
return {};
}
DeprecatedString CppComprehensionEngine::type_of(DocumentData const& document, Expression const& expression) const
ByteString CppComprehensionEngine::type_of(DocumentData const& document, Expression const& expression) const
{
if (expression.is_member_expression()) {
auto& member_expression = verify_cast<MemberExpression>(expression);
@ -304,7 +304,7 @@ DeprecatedString CppComprehensionEngine::type_of(DocumentData const& document, E
return type_of_variable(*identifier);
}
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_type(DocumentData const& document, DeprecatedString const& type) const
Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_type(DocumentData const& document, ByteString const& type) const
{
auto type_symbol = SymbolName::create(type);
auto decl = find_declaration_of(document, type_symbol);
@ -362,21 +362,21 @@ Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols
return symbols;
}
DeprecatedString CppComprehensionEngine::document_path_from_include_path(StringView include_path) const
ByteString CppComprehensionEngine::document_path_from_include_path(StringView include_path) const
{
static Regex<PosixExtended> library_include("<(.+)>");
static Regex<PosixExtended> user_defined_include("\"(.+)\"");
auto document_path_for_library_include = [&](StringView include_path) -> DeprecatedString {
auto document_path_for_library_include = [&](StringView include_path) -> ByteString {
RegexResult result;
if (!library_include.search(include_path, result))
return {};
auto path = result.capture_group_matches.at(0).at(0).view.string_view();
return DeprecatedString::formatted("/usr/include/{}", path);
return ByteString::formatted("/usr/include/{}", path);
};
auto document_path_for_user_defined_include = [&](StringView include_path) -> DeprecatedString {
auto document_path_for_user_defined_include = [&](StringView include_path) -> ByteString {
RegexResult result;
if (!user_defined_include.search(include_path, result))
return {};
@ -391,17 +391,17 @@ DeprecatedString CppComprehensionEngine::document_path_from_include_path(StringV
return result;
}
void CppComprehensionEngine::on_edit(DeprecatedString const& file)
void CppComprehensionEngine::on_edit(ByteString const& file)
{
set_document_data(file, create_document_data_for(file));
}
void CppComprehensionEngine::file_opened([[maybe_unused]] DeprecatedString const& file)
void CppComprehensionEngine::file_opened([[maybe_unused]] ByteString const& file)
{
get_or_create_document_data(file);
}
Optional<CodeComprehension::ProjectLocation> CppComprehensionEngine::find_declaration_of(DeprecatedString const& filename, const GUI::TextPosition& identifier_position)
Optional<CodeComprehension::ProjectLocation> CppComprehensionEngine::find_declaration_of(ByteString const& filename, const GUI::TextPosition& identifier_position)
{
auto const* document_ptr = get_or_create_document_data(filename);
if (!document_ptr)
@ -456,10 +456,10 @@ struct TargetDeclaration {
Property,
Scope
} type;
DeprecatedString name;
ByteString name;
};
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node, DeprecatedString name);
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node, ByteString name);
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node)
{
if (node.is_identifier()) {
@ -478,7 +478,7 @@ static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node)
return {};
}
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node, DeprecatedString name)
static Optional<TargetDeclaration> get_target_declaration(ASTNode const& node, ByteString name)
{
if (node.parent() && node.parent()->is_name()) {
auto& name_node = *verify_cast<Name>(node.parent());
@ -612,7 +612,7 @@ CodeComprehension::DeclarationType CppComprehensionEngine::type_of_declaration(C
return CodeComprehension::DeclarationType::Variable;
}
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data(DeprecatedString text, DeprecatedString const& filename)
OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data(ByteString text, ByteString const& filename)
{
auto document_data = make<DocumentData>();
document_data->m_filename = filename;
@ -693,7 +693,7 @@ Optional<Vector<CodeComprehension::AutocompleteResultEntry>> CppComprehensionEng
System,
} include_type { Project };
DeprecatedString include_root;
ByteString include_root;
bool already_has_suffix = false;
if (partial_include.starts_with('<')) {
include_root = "/usr/include/";
@ -716,7 +716,7 @@ Optional<Vector<CodeComprehension::AutocompleteResultEntry>> CppComprehensionEng
return {};
auto last_slash = partial_include.find_last('/');
auto include_dir = DeprecatedString::empty();
auto include_dir = ByteString::empty();
auto partial_basename = partial_include.substring_view((last_slash.has_value() ? last_slash.value() : 0) + 1);
if (last_slash.has_value()) {
include_dir = partial_include.substring_view(1, last_slash.value());
@ -738,12 +738,12 @@ Optional<Vector<CodeComprehension::AutocompleteResultEntry>> CppComprehensionEng
if (FileSystem::is_directory(LexicalPath::join(full_dir, path).string())) {
// FIXME: Don't dismiss the autocomplete when filling these suggestions.
auto completion = DeprecatedString::formatted("{}{}{}/", prefix, include_dir, path);
auto completion = ByteString::formatted("{}{}{}/", prefix, include_dir, path);
options.empend(completion, include_dir.length() + partial_basename.length() + 1, CodeComprehension::Language::Cpp, path, CodeComprehension::AutocompleteResultEntry::HideAutocompleteAfterApplying::No);
} else if (path.ends_with(".h"sv)) {
// FIXME: Place the cursor after the trailing > or ", even if it was
// already typed.
auto completion = DeprecatedString::formatted("{}{}{}{}", prefix, include_dir, path, already_has_suffix ? "" : suffix);
auto completion = ByteString::formatted("{}{}{}{}", prefix, include_dir, path, already_has_suffix ? "" : suffix);
options.empend(completion, include_dir.length() + partial_basename.length() + 1, CodeComprehension::Language::Cpp, path);
}
}
@ -764,17 +764,17 @@ RefPtr<Cpp::Declaration const> CppComprehensionEngine::find_declaration_of(CppCo
return target_declaration;
}
DeprecatedString CppComprehensionEngine::SymbolName::scope_as_string() const
ByteString CppComprehensionEngine::SymbolName::scope_as_string() const
{
if (scope.is_empty())
return DeprecatedString::empty();
return ByteString::empty();
StringBuilder builder;
for (size_t i = 0; i < scope.size() - 1; ++i) {
builder.appendff("{}::", scope[i]);
}
builder.append(scope.last());
return builder.to_deprecated_string();
return builder.to_byte_string();
}
CppComprehensionEngine::SymbolName CppComprehensionEngine::SymbolName::create(StringView name, Vector<StringView>&& scope)
@ -790,11 +790,11 @@ CppComprehensionEngine::SymbolName CppComprehensionEngine::SymbolName::create(St
return SymbolName::create(name, move(parts));
}
DeprecatedString CppComprehensionEngine::SymbolName::to_deprecated_string() const
ByteString CppComprehensionEngine::SymbolName::to_byte_string() const
{
if (scope.is_empty())
return name;
return DeprecatedString::formatted("{}::{}", scope_as_string(), name);
return ByteString::formatted("{}::{}", scope_as_string(), name);
}
bool CppComprehensionEngine::is_symbol_available(Symbol const& symbol, Vector<StringView> const& current_scope, Vector<StringView> const& reference_scope)
@ -818,7 +818,7 @@ bool CppComprehensionEngine::is_symbol_available(Symbol const& symbol, Vector<St
return true;
}
Optional<CodeComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get_function_params_hint(DeprecatedString const& filename, const GUI::TextPosition& identifier_position)
Optional<CodeComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get_function_params_hint(ByteString const& filename, const GUI::TextPosition& identifier_position)
{
auto const* document_ptr = get_or_create_document_data(filename);
if (!document_ptr)
@ -923,13 +923,13 @@ Optional<CppComprehensionEngine::FunctionParamsHint> CppComprehensionEngine::get
for (auto token : document_of_declaration->parser().tokens_in_range(arg->start(), arg->end())) {
tokens_text.append(token.text());
}
hint.params.append(DeprecatedString::join(' ', tokens_text));
hint.params.append(ByteString::join(' ', tokens_text));
}
return hint;
}
Vector<CodeComprehension::TokenInfo> CppComprehensionEngine::get_tokens_info(DeprecatedString const& filename)
Vector<CodeComprehension::TokenInfo> CppComprehensionEngine::get_tokens_info(ByteString const& filename)
{
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "CppComprehensionEngine::get_tokens_info: {}", filename);

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <AK/Vector.h>
#include <DevTools/HackStudio/AutoCompleteResponse.h>
@ -25,12 +25,12 @@ class CppComprehensionEngine : public CodeComprehensionEngine {
public:
CppComprehensionEngine(FileDB const& filedb);
virtual Vector<CodeComprehension::AutocompleteResultEntry> get_suggestions(DeprecatedString const& file, GUI::TextPosition const& autocomplete_position) override;
virtual void on_edit(DeprecatedString const& file) override;
virtual void file_opened([[maybe_unused]] DeprecatedString const& file) override;
virtual Optional<CodeComprehension::ProjectLocation> find_declaration_of(DeprecatedString const& filename, GUI::TextPosition const& identifier_position) override;
virtual Optional<FunctionParamsHint> get_function_params_hint(DeprecatedString const&, GUI::TextPosition const&) override;
virtual Vector<CodeComprehension::TokenInfo> get_tokens_info(DeprecatedString const& filename) override;
virtual Vector<CodeComprehension::AutocompleteResultEntry> get_suggestions(ByteString const& file, GUI::TextPosition const& autocomplete_position) override;
virtual void on_edit(ByteString const& file) override;
virtual void file_opened([[maybe_unused]] ByteString const& file) override;
virtual Optional<CodeComprehension::ProjectLocation> find_declaration_of(ByteString const& filename, GUI::TextPosition const& identifier_position) override;
virtual Optional<FunctionParamsHint> get_function_params_hint(ByteString const&, GUI::TextPosition const&) override;
virtual Vector<CodeComprehension::TokenInfo> get_tokens_info(ByteString const& filename) override;
private:
struct SymbolName {
@ -39,8 +39,8 @@ private:
static SymbolName create(StringView, Vector<StringView>&&);
static SymbolName create(StringView);
DeprecatedString scope_as_string() const;
DeprecatedString to_deprecated_string() const;
ByteString scope_as_string() const;
ByteString to_byte_string() const;
bool operator==(SymbolName const&) const = default;
};
@ -63,8 +63,8 @@ private:
friend Traits<SymbolName>;
struct DocumentData {
DeprecatedString const& filename() const { return m_filename; }
DeprecatedString const& text() const { return m_text; }
ByteString const& filename() const { return m_filename; }
ByteString const& text() const { return m_text; }
Preprocessor const& preprocessor() const
{
VERIFY(m_preprocessor);
@ -86,20 +86,20 @@ private:
return *m_parser;
}
DeprecatedString m_filename;
DeprecatedString m_text;
ByteString m_filename;
ByteString m_text;
OwnPtr<Preprocessor> m_preprocessor;
OwnPtr<Parser> m_parser;
HashMap<SymbolName, Symbol> m_symbols;
HashTable<DeprecatedString> m_available_headers;
HashTable<ByteString> m_available_headers;
};
Vector<CodeComprehension::AutocompleteResultEntry> autocomplete_property(DocumentData const&, MemberExpression const&, const DeprecatedString partial_text) const;
Vector<AutocompleteResultEntry> autocomplete_name(DocumentData const&, ASTNode const&, DeprecatedString const& partial_text) const;
DeprecatedString type_of(DocumentData const&, Expression const&) const;
DeprecatedString type_of_property(DocumentData const&, Identifier const&) const;
DeprecatedString type_of_variable(Identifier const&) const;
Vector<CodeComprehension::AutocompleteResultEntry> autocomplete_property(DocumentData const&, MemberExpression const&, const ByteString partial_text) const;
Vector<AutocompleteResultEntry> autocomplete_name(DocumentData const&, ASTNode const&, ByteString const& partial_text) const;
ByteString type_of(DocumentData const&, Expression const&) const;
ByteString type_of_property(DocumentData const&, Identifier const&) const;
ByteString type_of_variable(Identifier const&) const;
bool is_property(ASTNode const&) const;
RefPtr<Cpp::Declaration const> find_declaration_of(DocumentData const&, ASTNode const&) const;
RefPtr<Cpp::Declaration const> find_declaration_of(DocumentData const&, SymbolName const&) const;
@ -110,16 +110,16 @@ private:
Yes
};
Vector<Symbol> properties_of_type(DocumentData const& document, DeprecatedString const& type) const;
Vector<Symbol> properties_of_type(DocumentData const& document, ByteString const& type) const;
Vector<Symbol> get_child_symbols(ASTNode const&) const;
Vector<Symbol> get_child_symbols(ASTNode const&, Vector<StringView> const& scope, Symbol::IsLocal) const;
DocumentData const* get_document_data(DeprecatedString const& file) const;
DocumentData const* get_or_create_document_data(DeprecatedString const& file);
void set_document_data(DeprecatedString const& file, OwnPtr<DocumentData>&& data);
DocumentData const* get_document_data(ByteString const& file) const;
DocumentData const* get_or_create_document_data(ByteString const& file);
void set_document_data(ByteString const& file, OwnPtr<DocumentData>&& data);
OwnPtr<DocumentData> create_document_data_for(DeprecatedString const& file);
DeprecatedString document_path_from_include_path(StringView include_path) const;
OwnPtr<DocumentData> create_document_data_for(ByteString const& file);
ByteString document_path_from_include_path(StringView include_path) const;
void update_declared_symbols(DocumentData&);
void update_todo_entries(DocumentData&);
CodeComprehension::DeclarationType type_of_declaration(Cpp::Declaration const&);
@ -129,7 +129,7 @@ private:
Optional<CodeComprehension::ProjectLocation> find_preprocessor_definition(DocumentData const&, const GUI::TextPosition&);
Optional<Cpp::Preprocessor::Substitution> find_preprocessor_substitution(DocumentData const&, Cpp::Position const&);
OwnPtr<DocumentData> create_document_data(DeprecatedString text, DeprecatedString const& filename);
OwnPtr<DocumentData> create_document_data(ByteString text, ByteString const& filename);
Optional<Vector<CodeComprehension::AutocompleteResultEntry>> try_autocomplete_property(DocumentData const&, ASTNode const&, Optional<Token> containing_token) const;
Optional<Vector<CodeComprehension::AutocompleteResultEntry>> try_autocomplete_name(DocumentData const&, ASTNode const&, Optional<Token> containing_token) const;
Optional<Vector<CodeComprehension::AutocompleteResultEntry>> try_autocomplete_include(DocumentData const&, Token include_path_token, Cpp::Position const& cursor_position) const;
@ -145,12 +145,12 @@ private:
CodeComprehension::TokenInfo::SemanticType get_token_semantic_type(DocumentData const&, Token const&);
CodeComprehension::TokenInfo::SemanticType get_semantic_type_for_identifier(DocumentData const&, Position);
HashMap<DeprecatedString, OwnPtr<DocumentData>> m_documents;
HashMap<ByteString, OwnPtr<DocumentData>> m_documents;
// A document's path will be in this set if we're currently processing it.
// A document is added to this set when we start processing it (e.g because it was #included) and removed when we're done.
// We use this to prevent circular #includes from looping indefinitely.
HashTable<DeprecatedString> m_unfinished_documents;
HashTable<ByteString> m_unfinished_documents;
};
template<typename Func>

View file

@ -44,14 +44,14 @@ class FileDB : public CodeComprehension::FileDB {
public:
FileDB() = default;
void add(DeprecatedString filename, DeprecatedString content)
void add(ByteString filename, ByteString content)
{
m_map.set(filename, content);
}
virtual Optional<DeprecatedString> get_or_read_from_filesystem(StringView filename) const override
virtual Optional<ByteString> get_or_read_from_filesystem(StringView filename) const override
{
DeprecatedString target_filename = filename;
ByteString target_filename = filename;
if (project_root().has_value() && filename.starts_with(*project_root())) {
target_filename = LexicalPath::relative_path(filename, *project_root());
}
@ -59,7 +59,7 @@ public:
}
private:
HashMap<DeprecatedString, DeprecatedString> m_map;
HashMap<ByteString, ByteString> m_map;
};
static void test_complete_local_args();
@ -86,10 +86,10 @@ int run_tests()
return 0;
}
static void add_file(FileDB& filedb, DeprecatedString const& name)
static void add_file(FileDB& filedb, ByteString const& name)
{
auto file = Core::File::open(LexicalPath::join(TESTS_ROOT_DIR, name).string(), Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
filedb.add(name, DeprecatedString::copy(MUST(file->read_until_eof())));
filedb.add(name, ByteString::copy(MUST(file->read_until_eof())));
}
void test_complete_local_args()
@ -246,19 +246,19 @@ void test_parameters_hint()
auto result = engine.get_function_params_hint("parameters_hint1.cpp", { 4, 9 });
if (!result.has_value())
FAIL("failed to get parameters hint (1)");
if (result->params != Vector<DeprecatedString> { "int x", "char y" } || result->current_index != 0)
if (result->params != Vector<ByteString> { "int x", "char y" } || result->current_index != 0)
FAIL("bad result (1)");
result = engine.get_function_params_hint("parameters_hint1.cpp", { 5, 15 });
if (!result.has_value())
FAIL("failed to get parameters hint (2)");
if (result->params != Vector<DeprecatedString> { "int x", "char y" } || result->current_index != 1)
if (result->params != Vector<ByteString> { "int x", "char y" } || result->current_index != 1)
FAIL("bad result (2)");
result = engine.get_function_params_hint("parameters_hint1.cpp", { 6, 8 });
if (!result.has_value())
FAIL("failed to get parameters hint (3)");
if (result->params != Vector<DeprecatedString> { "int x", "char y" } || result->current_index != 0)
if (result->params != Vector<ByteString> { "int x", "char y" } || result->current_index != 0)
FAIL("bad result (3)");
PASS;

View file

@ -9,14 +9,14 @@
namespace CodeComprehension {
DeprecatedString FileDB::to_absolute_path(StringView filename) const
ByteString FileDB::to_absolute_path(StringView filename) const
{
if (LexicalPath { filename }.is_absolute()) {
return filename;
}
if (!m_project_root.has_value())
return filename;
return LexicalPath { DeprecatedString::formatted("{}/{}", *m_project_root, filename) }.string();
return LexicalPath { ByteString::formatted("{}/{}", *m_project_root, filename) }.string();
}
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringView.h>
namespace CodeComprehension {
@ -18,7 +18,7 @@ class FileDB {
public:
virtual ~FileDB() = default;
virtual Optional<DeprecatedString> get_or_read_from_filesystem(StringView filename) const = 0;
virtual Optional<ByteString> get_or_read_from_filesystem(StringView filename) const = 0;
void set_project_root(StringView project_root)
{
if (project_root.is_null())
@ -26,14 +26,14 @@ public:
else
m_project_root = project_root;
}
Optional<DeprecatedString> const& project_root() const { return m_project_root; }
DeprecatedString to_absolute_path(StringView filename) const;
Optional<ByteString> const& project_root() const { return m_project_root; }
ByteString to_absolute_path(StringView filename) const;
protected:
FileDB() = default;
private:
Optional<DeprecatedString> m_project_root;
Optional<ByteString> m_project_root;
};
}

View file

@ -20,10 +20,10 @@ private:
: LanguageServers::ConnectionFromClient(move(socket))
{
m_autocomplete_engine = make<CodeComprehension::Shell::ShellComprehensionEngine>(m_filedb);
m_autocomplete_engine->set_declarations_of_document_callback = [this](DeprecatedString const& filename, Vector<CodeComprehension::Declaration>&& declarations) {
m_autocomplete_engine->set_declarations_of_document_callback = [this](ByteString const& filename, Vector<CodeComprehension::Declaration>&& declarations) {
async_declarations_in_document(filename, move(declarations));
};
m_autocomplete_engine->set_todo_entries_of_document_callback = [this](DeprecatedString const& filename, Vector<CodeComprehension::TodoEntry>&& todo_entries) {
m_autocomplete_engine->set_todo_entries_of_document_callback = [this](ByteString const& filename, Vector<CodeComprehension::TodoEntry>&& todo_entries) {
async_todo_entries_in_document(filename, move(todo_entries));
};
}

View file

@ -18,7 +18,7 @@ ShellComprehensionEngine::ShellComprehensionEngine(FileDB const& filedb)
{
}
ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_or_create_document_data(DeprecatedString const& file)
ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_or_create_document_data(ByteString const& file)
{
auto absolute_path = filedb().to_absolute_path(file);
if (!m_documents.contains(absolute_path)) {
@ -27,7 +27,7 @@ ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_or_c
return get_document_data(absolute_path);
}
ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_document_data(DeprecatedString const& file) const
ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_document_data(ByteString const& file) const
{
auto absolute_path = filedb().to_absolute_path(file);
auto document_data = m_documents.get(absolute_path);
@ -35,7 +35,7 @@ ShellComprehensionEngine::DocumentData const& ShellComprehensionEngine::get_docu
return *document_data.value();
}
OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_document_data_for(DeprecatedString const& file)
OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_document_data_for(ByteString const& file)
{
auto document = filedb().get_or_read_from_filesystem(file);
if (!document.has_value())
@ -50,19 +50,19 @@ OwnPtr<ShellComprehensionEngine::DocumentData> ShellComprehensionEngine::create_
return document_data;
}
void ShellComprehensionEngine::set_document_data(DeprecatedString const& file, OwnPtr<DocumentData>&& data)
void ShellComprehensionEngine::set_document_data(ByteString const& file, OwnPtr<DocumentData>&& data)
{
m_documents.set(filedb().to_absolute_path(file), move(data));
}
ShellComprehensionEngine::DocumentData::DocumentData(DeprecatedString&& _text, DeprecatedString _filename)
ShellComprehensionEngine::DocumentData::DocumentData(ByteString&& _text, ByteString _filename)
: filename(move(_filename))
, text(move(_text))
, node(parse())
{
}
Vector<DeprecatedString> const& ShellComprehensionEngine::DocumentData::sourced_paths() const
Vector<ByteString> const& ShellComprehensionEngine::DocumentData::sourced_paths() const
{
if (all_sourced_paths.has_value())
return all_sourced_paths.value();
@ -82,19 +82,19 @@ Vector<DeprecatedString> const& ShellComprehensionEngine::DocumentData::sourced_
auto name_list = name_list_node->resolve_as_list(nullptr).release_value_but_fixme_should_propagate_errors();
StringBuilder builder;
builder.join(' ', name_list);
sourced_files.set(builder.to_deprecated_string());
sourced_files.set(builder.to_byte_string());
}
}
}
::Shell::AST::NodeVisitor::visit(node);
}
HashTable<DeprecatedString> sourced_files;
HashTable<ByteString> sourced_files;
} visitor;
node->visit(visitor);
Vector<DeprecatedString> sourced_paths;
Vector<ByteString> sourced_paths;
for (auto& entry : visitor.sourced_files)
sourced_paths.append(move(entry));
@ -134,7 +134,7 @@ size_t ShellComprehensionEngine::resolve(ShellComprehensionEngine::DocumentData
return offset;
}
Vector<CodeComprehension::AutocompleteResultEntry> ShellComprehensionEngine::get_suggestions(DeprecatedString const& file, const GUI::TextPosition& position)
Vector<CodeComprehension::AutocompleteResultEntry> ShellComprehensionEngine::get_suggestions(ByteString const& file, const GUI::TextPosition& position)
{
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "ShellComprehensionEngine position {}:{}", position.line(), position.column());
@ -155,17 +155,17 @@ Vector<CodeComprehension::AutocompleteResultEntry> ShellComprehensionEngine::get
return entries;
}
void ShellComprehensionEngine::on_edit(DeprecatedString const& file)
void ShellComprehensionEngine::on_edit(ByteString const& file)
{
set_document_data(file, create_document_data_for(file));
}
void ShellComprehensionEngine::file_opened([[maybe_unused]] DeprecatedString const& file)
void ShellComprehensionEngine::file_opened([[maybe_unused]] ByteString const& file)
{
set_document_data(file, create_document_data_for(file));
}
Optional<CodeComprehension::ProjectLocation> ShellComprehensionEngine::find_declaration_of(DeprecatedString const& filename, const GUI::TextPosition& identifier_position)
Optional<CodeComprehension::ProjectLocation> ShellComprehensionEngine::find_declaration_of(ByteString const& filename, const GUI::TextPosition& identifier_position)
{
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "find_declaration_of({}, {}:{})", filename, identifier_position.line(), identifier_position.column());
auto const& document = get_or_create_document_data(filename);
@ -196,7 +196,7 @@ Optional<CodeComprehension::ProjectLocation> ShellComprehensionEngine::find_decl
void ShellComprehensionEngine::update_declared_symbols(DocumentData const& document)
{
struct Visitor : public ::Shell::AST::NodeVisitor {
explicit Visitor(DeprecatedString const& filename)
explicit Visitor(ByteString const& filename)
: filename(filename)
{
}
@ -208,9 +208,9 @@ void ShellComprehensionEngine::update_declared_symbols(DocumentData const& docum
if (!literal)
continue;
DeprecatedString name;
ByteString name;
if (literal->is_bareword())
name = static_ptr_cast<::Shell::AST::BarewordLiteral const>(literal)->text().to_deprecated_string();
name = static_ptr_cast<::Shell::AST::BarewordLiteral const>(literal)->text().to_byte_string();
if (!name.is_empty()) {
dbgln("Found variable {}", name);
@ -223,10 +223,10 @@ void ShellComprehensionEngine::update_declared_symbols(DocumentData const& docum
void visit(::Shell::AST::FunctionDeclaration const* node) override
{
dbgln("Found function {}", node->name().name);
declarations.append({ node->name().name.to_deprecated_string(), { filename, node->position().start_line.line_number, node->position().start_line.line_column }, CodeComprehension::DeclarationType::Function, {} });
declarations.append({ node->name().name.to_byte_string(), { filename, node->position().start_line.line_number, node->position().start_line.line_column }, CodeComprehension::DeclarationType::Function, {} });
}
DeprecatedString const& filename;
ByteString const& filename;
Vector<CodeComprehension::Declaration> declarations;
} visitor { document.filename };

View file

@ -14,31 +14,31 @@ namespace CodeComprehension::Shell {
class ShellComprehensionEngine : public CodeComprehensionEngine {
public:
ShellComprehensionEngine(FileDB const& filedb);
virtual Vector<CodeComprehension::AutocompleteResultEntry> get_suggestions(DeprecatedString const& file, const GUI::TextPosition& position) override;
virtual void on_edit(DeprecatedString const& file) override;
virtual void file_opened([[maybe_unused]] DeprecatedString const& file) override;
virtual Optional<CodeComprehension::ProjectLocation> find_declaration_of(DeprecatedString const& filename, const GUI::TextPosition& identifier_position) override;
virtual Vector<CodeComprehension::AutocompleteResultEntry> get_suggestions(ByteString const& file, const GUI::TextPosition& position) override;
virtual void on_edit(ByteString const& file) override;
virtual void file_opened([[maybe_unused]] ByteString const& file) override;
virtual Optional<CodeComprehension::ProjectLocation> find_declaration_of(ByteString const& filename, const GUI::TextPosition& identifier_position) override;
private:
struct DocumentData {
DocumentData(DeprecatedString&& text, DeprecatedString filename);
DeprecatedString filename;
DeprecatedString text;
DocumentData(ByteString&& text, ByteString filename);
ByteString filename;
ByteString text;
NonnullRefPtr<::Shell::AST::Node> node;
Vector<DeprecatedString> const& sourced_paths() const;
Vector<ByteString> const& sourced_paths() const;
private:
NonnullRefPtr<::Shell::AST::Node> parse() const;
mutable Optional<Vector<DeprecatedString>> all_sourced_paths {};
mutable Optional<Vector<ByteString>> all_sourced_paths {};
};
DocumentData const& get_document_data(DeprecatedString const& file) const;
DocumentData const& get_or_create_document_data(DeprecatedString const& file);
void set_document_data(DeprecatedString const& file, OwnPtr<DocumentData>&& data);
DocumentData const& get_document_data(ByteString const& file) const;
DocumentData const& get_or_create_document_data(ByteString const& file);
void set_document_data(ByteString const& file, OwnPtr<DocumentData>&& data);
OwnPtr<DocumentData> create_document_data_for(DeprecatedString const& file);
OwnPtr<DocumentData> create_document_data_for(ByteString const& file);
void update_declared_symbols(DocumentData const&);
static size_t resolve(ShellComprehensionEngine::DocumentData const& document, const GUI::TextPosition& position);
@ -51,7 +51,7 @@ private:
return *s_shell;
}
HashMap<DeprecatedString, OwnPtr<DocumentData>> m_documents;
HashMap<ByteString, OwnPtr<DocumentData>> m_documents;
static RefPtr<::Shell::Shell> s_shell;
};
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
namespace CodeComprehension {
@ -16,11 +16,11 @@ enum class Language {
};
struct AutocompleteResultEntry {
DeprecatedString completion;
ByteString completion;
size_t partial_input_length { 0 };
// TODO: Actually assign the value of this field in more places (when applicable).
Language language { Language::Unspecified };
DeprecatedString display_text {};
ByteString display_text {};
enum class HideAutocompleteAfterApplying {
No,
@ -30,7 +30,7 @@ struct AutocompleteResultEntry {
};
struct ProjectLocation {
DeprecatedString file;
ByteString file;
size_t line { 0 };
size_t column { 0 };
@ -51,10 +51,10 @@ enum class DeclarationType {
};
struct Declaration {
DeprecatedString name;
ByteString name;
ProjectLocation position;
DeclarationType type;
DeprecatedString scope;
ByteString scope;
bool operator==(Declaration const& other) const
{
@ -109,8 +109,8 @@ struct TokenInfo {
};
struct TodoEntry {
DeprecatedString content;
DeprecatedString filename;
ByteString content;
ByteString filename;
size_t line { 0 };
size_t column { 0 };
};

View file

@ -19,27 +19,27 @@ Client& Client::the()
return *s_the;
}
void Client::pledge_domains(Vector<DeprecatedString> const& domains)
void Client::pledge_domains(Vector<ByteString> const& domains)
{
async_pledge_domains(domains);
}
void Client::monitor_domain(DeprecatedString const& domain)
void Client::monitor_domain(ByteString const& domain)
{
async_monitor_domain(domain);
}
Vector<DeprecatedString> Client::list_keys(StringView domain, StringView group)
Vector<ByteString> Client::list_keys(StringView domain, StringView group)
{
return list_config_keys(domain, group);
}
Vector<DeprecatedString> Client::list_groups(StringView domain)
Vector<ByteString> Client::list_groups(StringView domain)
{
return list_config_groups(domain);
}
DeprecatedString Client::read_string(StringView domain, StringView group, StringView key, StringView fallback)
ByteString Client::read_string(StringView domain, StringView group, StringView key, StringView fallback)
{
return read_string_value(domain, group, key).value_or(fallback);
}
@ -94,49 +94,49 @@ void Client::add_group(StringView domain, StringView group)
add_group_entry(domain, group);
}
void Client::notify_changed_string_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value)
void Client::notify_changed_string_value(ByteString const& domain, ByteString const& group, ByteString const& key, ByteString const& value)
{
Listener::for_each([&](auto& listener) {
listener.config_string_did_change(domain, group, key, value);
});
}
void Client::notify_changed_i32_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, i32 value)
void Client::notify_changed_i32_value(ByteString const& domain, ByteString const& group, ByteString const& key, i32 value)
{
Listener::for_each([&](auto& listener) {
listener.config_i32_did_change(domain, group, key, value);
});
}
void Client::notify_changed_u32_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, u32 value)
void Client::notify_changed_u32_value(ByteString const& domain, ByteString const& group, ByteString const& key, u32 value)
{
Listener::for_each([&](auto& listener) {
listener.config_u32_did_change(domain, group, key, value);
});
}
void Client::notify_changed_bool_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value)
void Client::notify_changed_bool_value(ByteString const& domain, ByteString const& group, ByteString const& key, bool value)
{
Listener::for_each([&](auto& listener) {
listener.config_bool_did_change(domain, group, key, value);
});
}
void Client::notify_removed_key(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key)
void Client::notify_removed_key(ByteString const& domain, ByteString const& group, ByteString const& key)
{
Listener::for_each([&](auto& listener) {
listener.config_key_was_removed(domain, group, key);
});
}
void Client::notify_removed_group(DeprecatedString const& domain, DeprecatedString const& group)
void Client::notify_removed_group(ByteString const& domain, ByteString const& group)
{
Listener::for_each([&](auto& listener) {
listener.config_group_was_removed(domain, group);
});
}
void Client::notify_added_group(DeprecatedString const& domain, DeprecatedString const& group)
void Client::notify_added_group(ByteString const& domain, ByteString const& group)
{
Listener::for_each([&](auto& listener) {
listener.config_group_was_added(domain, group);

View file

@ -20,13 +20,13 @@ class Client final
IPC_CLIENT_CONNECTION(Client, "/tmp/session/%sid/portal/config"sv)
public:
void pledge_domains(Vector<DeprecatedString> const&);
void monitor_domain(DeprecatedString const&);
void pledge_domains(Vector<ByteString> const&);
void monitor_domain(ByteString const&);
Vector<DeprecatedString> list_groups(StringView domain);
Vector<DeprecatedString> list_keys(StringView domain, StringView group);
Vector<ByteString> list_groups(StringView domain);
Vector<ByteString> list_keys(StringView domain, StringView group);
DeprecatedString read_string(StringView domain, StringView group, StringView key, StringView fallback);
ByteString read_string(StringView domain, StringView group, StringView key, StringView fallback);
i32 read_i32(StringView domain, StringView group, StringView key, i32 fallback);
u32 read_u32(StringView domain, StringView group, StringView key, u32 fallback);
bool read_bool(StringView domain, StringView group, StringView key, bool fallback);
@ -47,26 +47,26 @@ private:
{
}
void notify_changed_string_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value) override;
void notify_changed_i32_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, i32 value) override;
void notify_changed_u32_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, u32 value) override;
void notify_changed_bool_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value) override;
void notify_removed_key(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key) override;
void notify_removed_group(DeprecatedString const& domain, DeprecatedString const& group) override;
void notify_added_group(DeprecatedString const& domain, DeprecatedString const& group) override;
void notify_changed_string_value(ByteString const& domain, ByteString const& group, ByteString const& key, ByteString const& value) override;
void notify_changed_i32_value(ByteString const& domain, ByteString const& group, ByteString const& key, i32 value) override;
void notify_changed_u32_value(ByteString const& domain, ByteString const& group, ByteString const& key, u32 value) override;
void notify_changed_bool_value(ByteString const& domain, ByteString const& group, ByteString const& key, bool value) override;
void notify_removed_key(ByteString const& domain, ByteString const& group, ByteString const& key) override;
void notify_removed_group(ByteString const& domain, ByteString const& group) override;
void notify_added_group(ByteString const& domain, ByteString const& group) override;
};
inline Vector<DeprecatedString> list_groups(StringView domain)
inline Vector<ByteString> list_groups(StringView domain)
{
return Client::the().list_groups(domain);
}
inline Vector<DeprecatedString> list_keys(StringView domain, StringView group)
inline Vector<ByteString> list_keys(StringView domain, StringView group)
{
return Client::the().list_keys(domain, group);
}
inline DeprecatedString read_string(StringView domain, StringView group, StringView key, StringView fallback = {})
inline ByteString read_string(StringView domain, StringView group, StringView key, StringView fallback = {})
{
return Client::the().read_string(domain, group, key, fallback);
}
@ -121,17 +121,17 @@ inline void add_group(StringView domain, StringView group)
Client::the().add_group(domain, group);
}
inline void pledge_domains(Vector<DeprecatedString> const& domains)
inline void pledge_domains(Vector<ByteString> const& domains)
{
Client::the().pledge_domains(domains);
}
inline void pledge_domain(DeprecatedString const& domain)
inline void pledge_domain(ByteString const& domain)
{
Client::the().pledge_domains({ domain });
}
inline void monitor_domain(DeprecatedString const& domain)
inline void monitor_domain(ByteString const& domain)
{
Client::the().monitor_domain(domain);
}

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <AK/HashTable.h>
#include <LibConfig/Listener.h>

View file

@ -27,7 +27,7 @@
namespace Core {
static DeprecatedString get_salt()
static ByteString get_salt()
{
char random_data[12];
fill_with_random({ random_data, sizeof(random_data) });
@ -39,7 +39,7 @@ static DeprecatedString get_salt()
auto salt_string = MUST(encode_base64({ random_data, sizeof(random_data) }));
builder.append(salt_string);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
static Vector<gid_t> get_extra_gids(passwd const& pwd)
@ -191,25 +191,25 @@ void Account::set_password(SecretString const& password)
void Account::set_password_enabled(bool enabled)
{
auto flattened_password_hash = m_password_hash.value_or(DeprecatedString::empty());
auto flattened_password_hash = m_password_hash.value_or(ByteString::empty());
if (enabled && !flattened_password_hash.is_empty() && flattened_password_hash[0] == '!') {
m_password_hash = flattened_password_hash.substring(1, flattened_password_hash.length() - 1);
} else if (!enabled && (flattened_password_hash.is_empty() || flattened_password_hash[0] != '!')) {
StringBuilder builder;
builder.append('!');
builder.append(flattened_password_hash);
m_password_hash = builder.to_deprecated_string();
m_password_hash = builder.to_byte_string();
}
}
void Account::delete_password()
{
m_password_hash = DeprecatedString::empty();
m_password_hash = ByteString::empty();
}
Account::Account(passwd const& pwd, spwd const& spwd, Vector<gid_t> extra_gids)
: m_username(pwd.pw_name)
, m_password_hash(spwd.sp_pwdp ? Optional<DeprecatedString>(spwd.sp_pwdp) : OptionalNone {})
, m_password_hash(spwd.sp_pwdp ? Optional<ByteString>(spwd.sp_pwdp) : OptionalNone {})
, m_uid(pwd.pw_uid)
, m_gid(pwd.pw_gid)
, m_gecos(pwd.pw_gecos)
@ -219,7 +219,7 @@ Account::Account(passwd const& pwd, spwd const& spwd, Vector<gid_t> extra_gids)
{
}
ErrorOr<DeprecatedString> Account::generate_passwd_file() const
ErrorOr<ByteString> Account::generate_passwd_file() const
{
StringBuilder builder;
char buffer[1024] = { 0 };
@ -250,10 +250,10 @@ ErrorOr<DeprecatedString> Account::generate_passwd_file() const
}
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
ErrorOr<DeprecatedString> Account::generate_group_file() const
ErrorOr<ByteString> Account::generate_group_file() const
{
StringBuilder builder;
char buffer[1024] = { 0 };
@ -283,14 +283,14 @@ ErrorOr<DeprecatedString> Account::generate_group_file() const
if (should_be_present && !already_present)
members.append(m_username.characters());
builder.appendff("{}:{}:{}:{}\n", group->gr_name, group->gr_passwd, group->gr_gid, DeprecatedString::join(","sv, members));
builder.appendff("{}:{}:{}:{}\n", group->gr_name, group->gr_passwd, group->gr_gid, ByteString::join(","sv, members));
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
#ifndef AK_OS_BSD_GENERIC
ErrorOr<DeprecatedString> Account::generate_shadow_file() const
ErrorOr<ByteString> Account::generate_shadow_file() const
{
StringBuilder builder;
@ -302,25 +302,25 @@ ErrorOr<DeprecatedString> Account::generate_shadow_file() const
if (p->sp_namp == m_username) {
if (m_deleted)
continue;
builder.appendff("{}:{}", m_username, m_password_hash.value_or(DeprecatedString::empty()));
builder.appendff("{}:{}", m_username, m_password_hash.value_or(ByteString::empty()));
} else
builder.appendff("{}:{}", p->sp_namp, p->sp_pwdp);
builder.appendff(":{}:{}:{}:{}:{}:{}:{}\n",
(p->sp_lstchg == -1) ? "" : DeprecatedString::formatted("{}", p->sp_lstchg),
(p->sp_min == -1) ? "" : DeprecatedString::formatted("{}", p->sp_min),
(p->sp_max == -1) ? "" : DeprecatedString::formatted("{}", p->sp_max),
(p->sp_warn == -1) ? "" : DeprecatedString::formatted("{}", p->sp_warn),
(p->sp_inact == -1) ? "" : DeprecatedString::formatted("{}", p->sp_inact),
(p->sp_expire == -1) ? "" : DeprecatedString::formatted("{}", p->sp_expire),
(p->sp_flag == 0) ? "" : DeprecatedString::formatted("{}", p->sp_flag));
(p->sp_lstchg == -1) ? "" : ByteString::formatted("{}", p->sp_lstchg),
(p->sp_min == -1) ? "" : ByteString::formatted("{}", p->sp_min),
(p->sp_max == -1) ? "" : ByteString::formatted("{}", p->sp_max),
(p->sp_warn == -1) ? "" : ByteString::formatted("{}", p->sp_warn),
(p->sp_inact == -1) ? "" : ByteString::formatted("{}", p->sp_inact),
(p->sp_expire == -1) ? "" : ByteString::formatted("{}", p->sp_expire),
(p->sp_flag == 0) ? "" : ByteString::formatted("{}", p->sp_flag));
}
endspent();
if (errno)
return Error::from_errno(errno);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
#endif

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <LibCore/SecretString.h>
@ -40,8 +40,8 @@ public:
bool authenticate(SecretString const& password) const;
ErrorOr<void> login() const;
DeprecatedString username() const { return m_username; }
DeprecatedString password_hash() const { return m_password_hash.value_or(DeprecatedString::empty()); }
ByteString username() const { return m_username; }
ByteString password_hash() const { return m_password_hash.value_or(ByteString::empty()); }
// Setters only affect in-memory copy of password.
// You must call sync to apply changes.
@ -62,9 +62,9 @@ public:
uid_t uid() const { return m_uid; }
gid_t gid() const { return m_gid; }
DeprecatedString const& gecos() const { return m_gecos; }
DeprecatedString const& home_directory() const { return m_home_directory; }
DeprecatedString const& shell() const { return m_shell; }
ByteString const& gecos() const { return m_gecos; }
ByteString const& home_directory() const { return m_home_directory; }
ByteString const& shell() const { return m_shell; }
Vector<gid_t> const& extra_gids() const { return m_extra_gids; }
ErrorOr<void> sync();
@ -74,20 +74,20 @@ private:
Account(passwd const& pwd, spwd const& spwd, Vector<gid_t> extra_gids);
ErrorOr<DeprecatedString> generate_passwd_file() const;
ErrorOr<DeprecatedString> generate_group_file() const;
ErrorOr<ByteString> generate_passwd_file() const;
ErrorOr<ByteString> generate_group_file() const;
#ifndef AK_OS_BSD_GENERIC
ErrorOr<DeprecatedString> generate_shadow_file() const;
ErrorOr<ByteString> generate_shadow_file() const;
#endif
DeprecatedString m_username;
ByteString m_username;
Optional<DeprecatedString> m_password_hash;
Optional<ByteString> m_password_hash;
uid_t m_uid { 0 };
gid_t m_gid { 0 };
DeprecatedString m_gecos;
DeprecatedString m_home_directory;
DeprecatedString m_shell;
ByteString m_gecos;
ByteString m_home_directory;
ByteString m_shell;
Vector<gid_t> m_extra_gids;
bool m_deleted { false };
};

View file

@ -88,7 +88,7 @@ bool ArgsParser::parse(Span<StringView> arguments, FailureBehavior failure_behav
}
}
auto short_options = short_options_builder.to_deprecated_string();
auto short_options = short_options_builder.to_byte_string();
size_t option_index = 1;
while (true) {
auto result = parser.getopt(arguments.slice(1), short_options, long_options, {});
@ -439,7 +439,7 @@ void ArgsParser::add_option(bool& value, char const* help_string, char const* lo
add_option(move(option));
}
void ArgsParser::add_option(DeprecatedString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
void ArgsParser::add_option(ByteString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
{
Option option {
OptionArgumentMode::Required,
@ -599,7 +599,7 @@ void ArgsParser::add_option(Vector<size_t>& values, char const* help_string, cha
add_option(move(option));
}
void ArgsParser::add_option(Vector<DeprecatedString>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
void ArgsParser::add_option(Vector<ByteString>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
{
Option option {
OptionArgumentMode::Optional,
@ -622,7 +622,7 @@ void ArgsParser::add_positional_argument(Arg&& arg)
m_positional_args.append(move(arg));
}
void ArgsParser::add_positional_argument(DeprecatedString& value, char const* help_string, char const* name, Required required)
void ArgsParser::add_positional_argument(ByteString& value, char const* help_string, char const* name, Required required)
{
Arg arg {
help_string,
@ -713,7 +713,7 @@ void ArgsParser::add_positional_argument(double& value, char const* help_string,
add_positional_argument(move(arg));
}
void ArgsParser::add_positional_argument(Vector<DeprecatedString>& values, char const* help_string, char const* name, Required required)
void ArgsParser::add_positional_argument(Vector<ByteString>& values, char const* help_string, char const* name, Required required)
{
Arg arg {
help_string,
@ -837,12 +837,12 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, ReadonlySpan<
auto write_completion = [&](auto format, auto& option, auto has_invariant, auto... args) {
JsonObject object;
object.set("completion", DeprecatedString::formatted(StringView { format, strlen(format) }, args...));
object.set("completion", ByteString::formatted(StringView { format, strlen(format) }, args...));
object.set("static_offset", 0);
object.set("invariant_offset", has_invariant ? option_to_complete.length() : 0u);
object.set("display_trivia", option.help_string);
object.set("trailing_trivia", option.argument_mode == OptionArgumentMode::Required ? " " : "");
outln(file, "{}", object.to_deprecated_string());
outln(file, "{}", object.to_byte_string());
};
if (option_to_complete.starts_with("--"sv)) {

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/Concepts.h>
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/Vector.h>
#include <LibMain/Main.h>
@ -54,11 +54,11 @@ public:
Function<ErrorOr<bool>(StringView)> accept_value;
OptionHideMode hide_mode { OptionHideMode::None };
DeprecatedString name_for_display() const
ByteString name_for_display() const
{
if (long_name)
return DeprecatedString::formatted("--{}", long_name);
return DeprecatedString::formatted("-{:c}", short_name);
return ByteString::formatted("--{}", long_name);
return ByteString::formatted("-{:c}", short_name);
}
};
@ -101,7 +101,7 @@ public:
},
.hide_mode = hide_mode });
}
void add_option(DeprecatedString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
void add_option(ByteString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
void add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
template<Integral I>
@ -112,16 +112,16 @@ public:
void add_option(Vector<size_t>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator = ',', OptionHideMode hide_mode = OptionHideMode::None);
// Note: This option is being used when we expect the user to use the same option
// multiple times (e.g. "program --option=example --option=anotherexample ...").
void add_option(Vector<DeprecatedString>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
void add_option(Vector<ByteString>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
void add_positional_argument(Arg&&);
void add_positional_argument(DeprecatedString& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(ByteString& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(StringView& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(String& value, char const* help_string, char const* name, Required required = Required::Yes);
template<Integral I>
void add_positional_argument(I& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(double& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(Vector<DeprecatedString>& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(Vector<ByteString>& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(Vector<StringView>& value, char const* help_string, char const* name, Required required = Required::Yes);
void add_positional_argument(Vector<String>& value, char const* help_string, char const* name, Required required = Required::Yes);

View file

@ -63,7 +63,7 @@ ErrorOr<void> Command::write(StringView input)
return {};
}
ErrorOr<void> Command::write_lines(Span<DeprecatedString> lines)
ErrorOr<void> Command::write_lines(Span<ByteString> lines)
{
// It's possible the process dies before we can write everything to the
// stdin. So make sure that we don't crash but just stop writing.
@ -83,8 +83,8 @@ ErrorOr<void> Command::write_lines(Span<DeprecatedString> lines)
perror("sigaction");
});
for (DeprecatedString const& line : lines)
TRY(m_stdin->write_until_depleted(DeprecatedString::formatted("{}\n", line).bytes()));
for (ByteString const& line : lines)
TRY(m_stdin->write_until_depleted(ByteString::formatted("{}\n", line).bytes()));
return {};
}
@ -120,7 +120,7 @@ ErrorOr<Command::ProcessResult> Command::status(int options)
// Only supported in serenity mode because we use `posix_spawn_file_actions_addchdir`
#ifdef AK_OS_SERENITY
ErrorOr<CommandResult> command(DeprecatedString const& command_string, Optional<LexicalPath> chdir)
ErrorOr<CommandResult> command(ByteString const& command_string, Optional<LexicalPath> chdir)
{
auto parts = command_string.split(' ');
if (parts.is_empty())
@ -130,7 +130,7 @@ ErrorOr<CommandResult> command(DeprecatedString const& command_string, Optional<
return command(program, parts, chdir);
}
ErrorOr<CommandResult> command(DeprecatedString const& program, Vector<DeprecatedString> const& arguments, Optional<LexicalPath> chdir)
ErrorOr<CommandResult> command(ByteString const& program, Vector<ByteString> const& arguments, Optional<LexicalPath> chdir)
{
int stdout_pipe[2] = {};
int stderr_pipe[2] = {};

View file

@ -25,8 +25,8 @@ struct CommandResult {
ByteBuffer error;
};
ErrorOr<CommandResult> command(DeprecatedString const& program, Vector<DeprecatedString> const& arguments, Optional<LexicalPath> chdir);
ErrorOr<CommandResult> command(DeprecatedString const& command_string, Optional<LexicalPath> chdir);
ErrorOr<CommandResult> command(ByteString const& program, Vector<ByteString> const& arguments, Optional<LexicalPath> chdir);
ErrorOr<CommandResult> command(ByteString const& command_string, Optional<LexicalPath> chdir);
class Command {
public:
@ -41,7 +41,7 @@ public:
ErrorOr<void> write(StringView input);
ErrorOr<void> write_lines(Span<DeprecatedString> lines);
ErrorOr<void> write_lines(Span<ByteString> lines);
ErrorOr<ProcessOutputs> read_all();

View file

@ -17,28 +17,28 @@
namespace Core {
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_lib(DeprecatedString const& lib_name, AllowWriting allow_altering)
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_lib(ByteString const& lib_name, AllowWriting allow_altering)
{
DeprecatedString directory_name = DeprecatedString::formatted("{}/lib", StandardPaths::config_directory());
ByteString directory_name = ByteString::formatted("{}/lib", StandardPaths::config_directory());
auto directory = TRY(Directory::create(directory_name, Directory::CreateDirectories::Yes));
auto path = DeprecatedString::formatted("{}/{}.ini", directory, lib_name);
auto path = ByteString::formatted("{}/{}.ini", directory, lib_name);
return ConfigFile::open(path, allow_altering);
}
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_app(DeprecatedString const& app_name, AllowWriting allow_altering)
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_app(ByteString const& app_name, AllowWriting allow_altering)
{
auto directory = TRY(Directory::create(StandardPaths::config_directory(), Directory::CreateDirectories::Yes));
auto path = DeprecatedString::formatted("{}/{}.ini", directory, app_name);
auto path = ByteString::formatted("{}/{}.ini", directory, app_name);
return ConfigFile::open(path, allow_altering);
}
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_system(DeprecatedString const& app_name, AllowWriting allow_altering)
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_system(ByteString const& app_name, AllowWriting allow_altering)
{
auto path = DeprecatedString::formatted("/etc/{}.ini", app_name);
auto path = ByteString::formatted("/etc/{}.ini", app_name);
return ConfigFile::open(path, allow_altering);
}
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, AllowWriting allow_altering)
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(ByteString const& filename, AllowWriting allow_altering)
{
auto maybe_file = File::open(filename, allow_altering == AllowWriting::Yes ? File::OpenMode::ReadWrite : File::OpenMode::Read);
OwnPtr<InputBufferedFile> buffered_file;
@ -57,13 +57,13 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& file
return config_file;
}
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, int fd)
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(ByteString const& filename, int fd)
{
auto file = TRY(File::adopt_fd(fd, File::OpenMode::ReadWrite));
return open(filename, move(file));
}
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, NonnullOwnPtr<Core::File> file)
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(ByteString const& filename, NonnullOwnPtr<Core::File> file)
{
auto buffered_file = TRY(InputBufferedFile::create(move(file)));
@ -72,7 +72,7 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& file
return config_file;
}
ConfigFile::ConfigFile(DeprecatedString const& filename, OwnPtr<InputBufferedFile> open_file)
ConfigFile::ConfigFile(ByteString const& filename, OwnPtr<InputBufferedFile> open_file)
: m_filename(filename)
, m_file(move(open_file))
{
@ -89,7 +89,7 @@ ErrorOr<void> ConfigFile::reparse()
if (!m_file)
return {};
HashMap<DeprecatedString, DeprecatedString>* current_group = nullptr;
HashMap<ByteString, ByteString>* current_group = nullptr;
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (TRY(m_file->can_read_line())) {
@ -113,7 +113,7 @@ ErrorOr<void> ConfigFile::reparse()
builder.append(line[i]);
++i;
}
current_group = &m_groups.ensure(builder.to_deprecated_string());
current_group = &m_groups.ensure(builder.to_byte_string());
break;
}
default: { // Start of key
@ -132,15 +132,15 @@ ErrorOr<void> ConfigFile::reparse()
// We're not in a group yet, create one with the name ""...
current_group = &m_groups.ensure("");
}
auto value_string = value_builder.to_deprecated_string();
current_group->set(key_builder.to_deprecated_string(), value_string.trim_whitespace(TrimMode::Right));
auto value_string = value_builder.to_byte_string();
current_group->set(key_builder.to_byte_string(), value_string.trim_whitespace(TrimMode::Right));
}
}
}
return {};
}
Optional<DeprecatedString> ConfigFile::read_entry_optional(const AK::DeprecatedString& group, const AK::DeprecatedString& key) const
Optional<ByteString> ConfigFile::read_entry_optional(const AK::ByteString& group, const AK::ByteString& key) const
{
if (!has_key(group, key))
return {};
@ -149,19 +149,19 @@ Optional<DeprecatedString> ConfigFile::read_entry_optional(const AK::DeprecatedS
return jt->value;
}
bool ConfigFile::read_bool_entry(DeprecatedString const& group, DeprecatedString const& key, bool default_value) const
bool ConfigFile::read_bool_entry(ByteString const& group, ByteString const& key, bool default_value) const
{
auto value = read_entry(group, key, default_value ? "true" : "false");
return value == "1" || value.equals_ignoring_ascii_case("true"sv);
}
void ConfigFile::write_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value)
void ConfigFile::write_entry(ByteString const& group, ByteString const& key, ByteString const& value)
{
m_groups.ensure(group).ensure(key) = value;
m_dirty = true;
}
void ConfigFile::write_bool_entry(DeprecatedString const& group, DeprecatedString const& key, bool value)
void ConfigFile::write_bool_entry(ByteString const& group, ByteString const& key, bool value)
{
write_entry(group, key, value ? "true" : "false");
}
@ -178,9 +178,9 @@ ErrorOr<void> ConfigFile::sync()
TRY(m_file->seek(0, SeekMode::SetPosition));
for (auto& it : m_groups) {
TRY(m_file->write_until_depleted(DeprecatedString::formatted("[{}]\n", it.key).bytes()));
TRY(m_file->write_until_depleted(ByteString::formatted("[{}]\n", it.key).bytes()));
for (auto& jt : it.value)
TRY(m_file->write_until_depleted(DeprecatedString::formatted("{}={}\n", jt.key, jt.value).bytes()));
TRY(m_file->write_until_depleted(ByteString::formatted("{}={}\n", jt.key, jt.value).bytes()));
TRY(m_file->write_until_depleted("\n"sv.bytes()));
}
@ -198,12 +198,12 @@ void ConfigFile::dump() const
}
}
Vector<DeprecatedString> ConfigFile::groups() const
Vector<ByteString> ConfigFile::groups() const
{
return m_groups.keys();
}
Vector<DeprecatedString> ConfigFile::keys(DeprecatedString const& group) const
Vector<ByteString> ConfigFile::keys(ByteString const& group) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
@ -211,7 +211,7 @@ Vector<DeprecatedString> ConfigFile::keys(DeprecatedString const& group) const
return it->value.keys();
}
bool ConfigFile::has_key(DeprecatedString const& group, DeprecatedString const& key) const
bool ConfigFile::has_key(ByteString const& group, ByteString const& key) const
{
auto it = m_groups.find(group);
if (it == m_groups.end())
@ -219,24 +219,24 @@ bool ConfigFile::has_key(DeprecatedString const& group, DeprecatedString const&
return it->value.contains(key);
}
bool ConfigFile::has_group(DeprecatedString const& group) const
bool ConfigFile::has_group(ByteString const& group) const
{
return m_groups.contains(group);
}
void ConfigFile::add_group(DeprecatedString const& group)
void ConfigFile::add_group(ByteString const& group)
{
m_groups.ensure(group);
m_dirty = true;
}
void ConfigFile::remove_group(DeprecatedString const& group)
void ConfigFile::remove_group(ByteString const& group)
{
m_groups.remove(group);
m_dirty = true;
}
void ConfigFile::remove_entry(DeprecatedString const& group, DeprecatedString const& key)
void ConfigFile::remove_entry(ByteString const& group, ByteString const& key)
{
auto it = m_groups.find(group);
if (it == m_groups.end())

View file

@ -8,7 +8,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Forward.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
@ -26,31 +26,31 @@ public:
No,
};
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_lib(DeprecatedString const& lib_name, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_app(DeprecatedString const& app_name, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_system(DeprecatedString const& app_name, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, int fd);
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, NonnullOwnPtr<Core::File>);
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_lib(ByteString const& lib_name, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_app(ByteString const& app_name, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_system(ByteString const& app_name, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open(ByteString const& filename, AllowWriting = AllowWriting::No);
static ErrorOr<NonnullRefPtr<ConfigFile>> open(ByteString const& filename, int fd);
static ErrorOr<NonnullRefPtr<ConfigFile>> open(ByteString const& filename, NonnullOwnPtr<Core::File>);
~ConfigFile();
bool has_group(DeprecatedString const&) const;
bool has_key(DeprecatedString const& group, DeprecatedString const& key) const;
bool has_group(ByteString const&) const;
bool has_key(ByteString const& group, ByteString const& key) const;
Vector<DeprecatedString> groups() const;
Vector<DeprecatedString> keys(DeprecatedString const& group) const;
Vector<ByteString> groups() const;
Vector<ByteString> keys(ByteString const& group) const;
size_t num_groups() const { return m_groups.size(); }
DeprecatedString read_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& default_value = {}) const
ByteString read_entry(ByteString const& group, ByteString const& key, ByteString const& default_value = {}) const
{
return read_entry_optional(group, key).value_or(default_value);
}
Optional<DeprecatedString> read_entry_optional(DeprecatedString const& group, DeprecatedString const& key) const;
bool read_bool_entry(DeprecatedString const& group, DeprecatedString const& key, bool default_value = false) const;
Optional<ByteString> read_entry_optional(ByteString const& group, ByteString const& key) const;
bool read_bool_entry(ByteString const& group, ByteString const& key, bool default_value = false) const;
template<Integral T = int>
T read_num_entry(DeprecatedString const& group, DeprecatedString const& key, T default_value = 0) const
T read_num_entry(ByteString const& group, ByteString const& key, T default_value = 0) const
{
if (!has_key(group, key))
return default_value;
@ -61,13 +61,13 @@ public:
return read_entry(group, key, "").to_uint<T>().value_or(default_value);
}
void write_entry(DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value);
void write_bool_entry(DeprecatedString const& group, DeprecatedString const& key, bool value);
void write_entry(ByteString const& group, ByteString const& key, ByteString const& value);
void write_bool_entry(ByteString const& group, ByteString const& key, bool value);
template<Integral T = int>
void write_num_entry(DeprecatedString const& group, DeprecatedString const& key, T value)
void write_num_entry(ByteString const& group, ByteString const& key, T value)
{
write_entry(group, key, DeprecatedString::number(value));
write_entry(group, key, ByteString::number(value));
}
void dump() const;
@ -76,20 +76,20 @@ public:
ErrorOr<void> sync();
void add_group(DeprecatedString const& group);
void remove_group(DeprecatedString const& group);
void remove_entry(DeprecatedString const& group, DeprecatedString const& key);
void add_group(ByteString const& group);
void remove_group(ByteString const& group);
void remove_entry(ByteString const& group, ByteString const& key);
DeprecatedString const& filename() const { return m_filename; }
ByteString const& filename() const { return m_filename; }
private:
ConfigFile(DeprecatedString const& filename, OwnPtr<InputBufferedFile> open_file);
ConfigFile(ByteString const& filename, OwnPtr<InputBufferedFile> open_file);
ErrorOr<void> reparse();
DeprecatedString m_filename;
ByteString m_filename;
OwnPtr<InputBufferedFile> m_file;
HashMap<DeprecatedString, HashMap<DeprecatedString, DeprecatedString>> m_groups;
HashMap<ByteString, HashMap<ByteString, ByteString>> m_groups;
bool m_dirty { false };
};

View file

@ -283,9 +283,9 @@ ErrorOr<String> DateTime::to_string(StringView format) const
return builder.to_string();
}
DeprecatedString DateTime::to_deprecated_string(StringView format) const
ByteString DateTime::to_byte_string(StringView format) const
{
return MUST(to_string(format)).to_deprecated_string();
return MUST(to_string(format)).to_byte_string();
}
Optional<DateTime> DateTime::parse(StringView format, StringView string)

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringView.h>
#include <LibIPC/Forward.h>
#include <time.h>
@ -32,7 +32,7 @@ public:
void set_time(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0);
ErrorOr<String> to_string(StringView format = "%Y-%m-%d %H:%M:%S"sv) const;
DeprecatedString to_deprecated_string(StringView format = "%Y-%m-%d %H:%M:%S"sv) const;
ByteString to_byte_string(StringView format = "%Y-%m-%d %H:%M:%S"sv) const;
static DateTime create(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0);
static DateTime now();

View file

@ -11,7 +11,7 @@
namespace Core {
DirIterator::DirIterator(DeprecatedString path, Flags flags)
DirIterator::DirIterator(ByteString path, Flags flags)
: m_path(move(path))
, m_flags(flags)
{
@ -93,7 +93,7 @@ Optional<DirectoryEntry> DirIterator::next()
return result;
}
DeprecatedString DirIterator::next_path()
ByteString DirIterator::next_path()
{
auto entry = next();
if (entry.has_value())
@ -101,14 +101,14 @@ DeprecatedString DirIterator::next_path()
return "";
}
DeprecatedString DirIterator::next_full_path()
ByteString DirIterator::next_full_path()
{
StringBuilder builder;
builder.append(m_path);
if (!m_path.ends_with('/'))
builder.append('/');
builder.append(next_path());
return builder.to_deprecated_string();
return builder.to_byte_string();
}
int DirIterator::fd() const

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <LibCore/DirectoryEntry.h>
#include <dirent.h>
#include <string.h>
@ -22,7 +22,7 @@ public:
SkipParentAndBaseDir = 0x2,
};
explicit DirIterator(DeprecatedString path, Flags = Flags::NoFlags);
explicit DirIterator(ByteString path, Flags = Flags::NoFlags);
~DirIterator();
DirIterator(DirIterator&&);
@ -32,15 +32,15 @@ public:
Error error() const { return Error::copy(m_error.value()); }
bool has_next();
Optional<DirectoryEntry> next();
DeprecatedString next_path();
DeprecatedString next_full_path();
ByteString next_path();
ByteString next_full_path();
int fd() const;
private:
DIR* m_dir = nullptr;
Optional<Error> m_error;
Optional<DirectoryEntry> m_next;
DeprecatedString m_path;
ByteString m_path;
int m_flags;
bool advance_next();

View file

@ -53,7 +53,7 @@ ErrorOr<Directory> Directory::adopt_fd(int fd, LexicalPath path)
return Directory { fd, move(path) };
}
ErrorOr<Directory> Directory::create(DeprecatedString path, CreateDirectories create_directories, mode_t creation_mode)
ErrorOr<Directory> Directory::create(ByteString path, CreateDirectories create_directories, mode_t creation_mode)
{
return create(LexicalPath { move(path) }, create_directories, creation_mode);
}

View file

@ -37,7 +37,7 @@ public:
};
static ErrorOr<Directory> create(LexicalPath path, CreateDirectories, mode_t creation_mode = 0755);
static ErrorOr<Directory> create(DeprecatedString path, CreateDirectories, mode_t creation_mode = 0755);
static ErrorOr<Directory> create(ByteString path, CreateDirectories, mode_t creation_mode = 0755);
static ErrorOr<Directory> adopt_fd(int fd, LexicalPath path);
ErrorOr<NonnullOwnPtr<File>> open(StringView filename, File::OpenMode mode) const;

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <dirent.h>
namespace Core {
@ -25,7 +25,7 @@ struct DirectoryEntry {
};
Type type;
// FIXME: Once we have a special Path string class, use that.
DeprecatedString name;
ByteString name;
ino_t inode_number;
static DirectoryEntry from_dirent(dirent const&);

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Forward.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
@ -67,8 +67,8 @@ public:
virtual bool is_widget() const { return false; }
DeprecatedString const& name() const { return m_name; }
void set_name(DeprecatedString name) { m_name = move(name); }
ByteString const& name() const { return m_name; }
void set_name(ByteString name) { m_name = move(name); }
Vector<NonnullRefPtr<EventReceiver>>& children() { return m_children; }
Vector<NonnullRefPtr<EventReceiver>> const& children() const { return m_children; }
@ -168,7 +168,7 @@ protected:
private:
EventReceiver* m_parent { nullptr };
DeprecatedString m_name;
ByteString m_name;
int m_timer_id { 0 };
Vector<NonnullRefPtr<EventReceiver>> m_children;
Function<bool(Core::Event&)> m_event_filter;

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/EnumBits.h>
#include <AK/Function.h>
#include <AK/Noncopyable.h>
@ -27,7 +27,7 @@ struct FileWatcherEvent {
ChildDeleted = 1 << 4,
};
Type type { Type::Invalid };
DeprecatedString event_path;
ByteString event_path;
};
AK_ENUM_BITWISE_OPERATORS(FileWatcherEvent::Type);
@ -44,9 +44,9 @@ class FileWatcherBase {
public:
virtual ~FileWatcherBase() = default;
ErrorOr<bool> add_watch(DeprecatedString path, FileWatcherEvent::Type event_mask);
ErrorOr<bool> remove_watch(DeprecatedString path);
bool is_watching(DeprecatedString const& path) const { return m_path_to_wd.find(path) != m_path_to_wd.end(); }
ErrorOr<bool> add_watch(ByteString path, FileWatcherEvent::Type event_mask);
ErrorOr<bool> remove_watch(ByteString path);
bool is_watching(ByteString const& path) const { return m_path_to_wd.find(path) != m_path_to_wd.end(); }
protected:
FileWatcherBase(int watcher_fd)
@ -55,8 +55,8 @@ protected:
}
int m_watcher_fd { -1 };
HashMap<DeprecatedString, unsigned> m_path_to_wd;
HashMap<unsigned, DeprecatedString> m_wd_to_path;
HashMap<ByteString, unsigned> m_path_to_wd;
HashMap<unsigned, ByteString> m_wd_to_path;
};
class BlockingFileWatcher final : public FileWatcherBase {

View file

@ -5,8 +5,8 @@
*/
#include "FileWatcher.h"
#include <AK/ByteString.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <LibCore/Notifier.h>
#include <errno.h>
@ -34,7 +34,7 @@ static constexpr unsigned file_watcher_flags_to_inotify_flags(FileWatcherFlags f
return result;
}
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, DeprecatedString> const& wd_to_path)
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, ByteString> const& wd_to_path)
{
static constexpr auto max_event_size = sizeof(inotify_event) + NAME_MAX + 1;
@ -123,7 +123,7 @@ FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
FileWatcher::~FileWatcher() = default;
ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString path, FileWatcherEvent::Type event_mask)
ErrorOr<bool> FileWatcherBase::add_watch(ByteString path, FileWatcherEvent::Type event_mask)
{
if (m_path_to_wd.find(path) != m_path_to_wd.end()) {
dbgln_if(FILE_WATCHER_DEBUG, "add_watch: path '{}' is already being watched", path);
@ -154,7 +154,7 @@ ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString path, FileWatcherEvent
return true;
}
ErrorOr<bool> FileWatcherBase::remove_watch(DeprecatedString path)
ErrorOr<bool> FileWatcherBase::remove_watch(ByteString path)
{
auto it = m_path_to_wd.find(path);
if (it == m_path_to_wd.end()) {

View file

@ -29,7 +29,7 @@ static_assert(false, "This file must only be used for macOS");
namespace Core {
struct MonitoredPath {
DeprecatedString path;
ByteString path;
FileWatcherEvent::Type event_mask { FileWatcherEvent::Type::Invalid };
};
@ -55,7 +55,7 @@ public:
{
auto context = TRY(try_make<FSEventStreamContext>());
auto queue_name = DeprecatedString::formatted("Serenity.FileWatcher.{:p}", context.ptr());
auto queue_name = ByteString::formatted("Serenity.FileWatcher.{:p}", context.ptr());
auto dispatch_queue = dispatch_queue_create(queue_name.characters(), DISPATCH_QUEUE_SERIAL);
if (dispatch_queue == nullptr)
return Error::from_errno(errno);
@ -67,7 +67,7 @@ public:
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcherMacOS(move(context), dispatch_queue, move(notifier)));
}
ErrorOr<bool> add_watch(DeprecatedString path, FileWatcherEvent::Type event_mask)
ErrorOr<bool> add_watch(ByteString path, FileWatcherEvent::Type event_mask)
{
if (m_path_to_inode_id.contains(path)) {
dbgln_if(FILE_WATCHER_DEBUG, "add_watch: path '{}' is already being watched", path);
@ -84,7 +84,7 @@ public:
return true;
}
ErrorOr<bool> remove_watch(DeprecatedString path)
ErrorOr<bool> remove_watch(ByteString path)
{
auto it = m_path_to_inode_id.find(path);
if (it == m_path_to_inode_id.end()) {
@ -101,7 +101,7 @@ public:
return true;
}
ErrorOr<MonitoredPath> canonicalize_path(DeprecatedString path)
ErrorOr<MonitoredPath> canonicalize_path(ByteString path)
{
LexicalPath lexical_path { move(path) };
auto parent_path = lexical_path.parent();
@ -200,7 +200,7 @@ private:
dispatch_queue_t m_dispatch_queue { nullptr };
FSEventStreamRef m_stream { nullptr };
HashMap<DeprecatedString, ino_t> m_path_to_inode_id;
HashMap<ByteString, ino_t> m_path_to_inode_id;
HashMap<ino_t, MonitoredPath> m_inode_id_to_path;
};
@ -219,7 +219,7 @@ void on_file_system_event(ConstFSEventStreamRef, void* user_data, size_t event_s
continue;
}
auto maybe_monitored_path = file_watcher.canonicalize_path(DeprecatedString { file_path_buffer });
auto maybe_monitored_path = file_watcher.canonicalize_path(ByteString { file_path_buffer });
if (maybe_monitored_path.is_error()) {
dbgln_if(FILE_WATCHER_DEBUG, "Could not canonicalize path {}: {}", file_path_buffer, maybe_monitored_path.error());
continue;
@ -265,13 +265,13 @@ FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
FileWatcher::~FileWatcher() = default;
ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString path, FileWatcherEvent::Type event_mask)
ErrorOr<bool> FileWatcherBase::add_watch(ByteString path, FileWatcherEvent::Type event_mask)
{
auto& file_watcher = verify_cast<FileWatcherMacOS>(*this);
return file_watcher.add_watch(move(path), event_mask);
}
ErrorOr<bool> FileWatcherBase::remove_watch(DeprecatedString path)
ErrorOr<bool> FileWatcherBase::remove_watch(ByteString path)
{
auto& file_watcher = verify_cast<FileWatcherMacOS>(*this);
return file_watcher.remove_watch(move(path));

View file

@ -6,8 +6,8 @@
*/
#include "FileWatcher.h"
#include <AK/ByteString.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/NonnullRefPtr.h>
#include <Kernel/API/InodeWatcherEvent.h>
@ -36,7 +36,7 @@ static constexpr unsigned file_watcher_flags_to_inode_watcher_flags(FileWatcherF
return static_cast<unsigned>(result);
}
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, DeprecatedString> const& wd_to_path)
static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, ByteString> const& wd_to_path)
{
u8 buffer[MAXIMUM_EVENT_SIZE];
int rc = read(fd, &buffer, MAXIMUM_EVENT_SIZE);
@ -55,7 +55,7 @@ static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, De
dbgln_if(FILE_WATCHER_DEBUG, "get_event_from_fd: Got an event for a non-existent wd {}?!", event->watch_descriptor);
return {};
}
DeprecatedString const& path = it->value;
ByteString const& path = it->value;
switch (event->type) {
case InodeWatcherEvent::Type::ChildCreated:
@ -80,7 +80,7 @@ static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, De
// We trust that the kernel only sends the name when appropriate.
if (event->name_length > 0) {
DeprecatedString child_name { event->name, event->name_length - 1 };
ByteString child_name { event->name, event->name_length - 1 };
result.event_path = LexicalPath::join(path, child_name).string();
} else {
result.event_path = path;
@ -90,7 +90,7 @@ static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, De
return result;
}
static DeprecatedString canonicalize_path(DeprecatedString path)
static ByteString canonicalize_path(ByteString path)
{
if (!path.is_empty() && path[0] == '/')
return LexicalPath::canonicalized_path(move(path));
@ -99,9 +99,9 @@ static DeprecatedString canonicalize_path(DeprecatedString path)
return LexicalPath::join({ cwd, strlen(cwd) }, move(path)).string();
}
ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString path, FileWatcherEvent::Type event_mask)
ErrorOr<bool> FileWatcherBase::add_watch(ByteString path, FileWatcherEvent::Type event_mask)
{
DeprecatedString canonical_path = canonicalize_path(move(path));
ByteString canonical_path = canonicalize_path(move(path));
if (m_path_to_wd.find(canonical_path) != m_path_to_wd.end()) {
dbgln_if(FILE_WATCHER_DEBUG, "add_watch: path '{}' is already being watched", canonical_path);
@ -131,9 +131,9 @@ ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString path, FileWatcherEvent
return true;
}
ErrorOr<bool> FileWatcherBase::remove_watch(DeprecatedString path)
ErrorOr<bool> FileWatcherBase::remove_watch(ByteString path)
{
DeprecatedString canonical_path = canonicalize_path(move(path));
ByteString canonical_path = canonicalize_path(move(path));
auto it = m_path_to_wd.find(canonical_path);
if (it == m_path_to_wd.end()) {

View file

@ -24,12 +24,12 @@ FileWatcher::FileWatcher(int watcher_fd, NonnullRefPtr<Notifier> notifier)
FileWatcher::~FileWatcher() = default;
ErrorOr<bool> FileWatcherBase::add_watch(DeprecatedString, FileWatcherEvent::Type)
ErrorOr<bool> FileWatcherBase::add_watch(ByteString, FileWatcherEvent::Type)
{
return Error::from_errno(ENOTSUP);
}
ErrorOr<bool> FileWatcherBase::remove_watch(DeprecatedString)
ErrorOr<bool> FileWatcherBase::remove_watch(ByteString)
{
return Error::from_errno(ENOTSUP);
}

View file

@ -15,7 +15,7 @@
namespace Core {
ErrorOr<DeprecatedString> Group::generate_group_file() const
ErrorOr<ByteString> Group::generate_group_file() const
{
StringBuilder builder;
char buffer[1024] = { 0 };
@ -29,19 +29,19 @@ ErrorOr<DeprecatedString> Group::generate_group_file() const
break;
if (group->gr_name == m_name)
builder.appendff("{}:x:{}:{}\n", m_name, m_id, DeprecatedString::join(',', m_members));
builder.appendff("{}:x:{}:{}\n", m_name, m_id, ByteString::join(',', m_members));
else {
Vector<DeprecatedString> members;
Vector<ByteString> members;
if (group->gr_mem) {
for (size_t i = 0; group->gr_mem[i]; ++i)
members.append(group->gr_mem[i]);
}
builder.appendff("{}:x:{}:{}\n", group->gr_name, group->gr_gid, DeprecatedString::join(',', members));
builder.appendff("{}:x:{}:{}\n", group->gr_name, group->gr_gid, ByteString::join(',', members));
}
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
ErrorOr<void> Group::sync()
@ -74,7 +74,7 @@ ErrorOr<void> Group::add_group(Group& group)
return Error::from_string_literal("Group name can not be empty.");
// A quick sanity check on group name
if (group.name().find_any_of("\\/!@#$%^&*()~+=`:\n"sv, DeprecatedString::SearchDirection::Forward).has_value())
if (group.name().find_any_of("\\/!@#$%^&*()~+=`:\n"sv, ByteString::SearchDirection::Forward).has_value())
return Error::from_string_literal("Group name has invalid characters.");
// Disallow names starting with '_', '-' or other non-alpha characters.
@ -129,7 +129,7 @@ ErrorOr<Vector<Group>> Group::all()
if (!group.has_value())
break;
Vector<DeprecatedString> members;
Vector<ByteString> members;
if (group->gr_mem) {
for (size_t i = 0; group->gr_mem[i]; ++i)
members.append(group->gr_mem[i]);
@ -141,7 +141,7 @@ ErrorOr<Vector<Group>> Group::all()
return groups;
}
Group::Group(DeprecatedString name, gid_t id, Vector<DeprecatedString> members)
Group::Group(ByteString name, gid_t id, Vector<ByteString> members)
: m_name(move(name))
, m_id(id)
, m_members(move(members))

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Error.h>
#include <AK/Vector.h>
#include <grp.h>
@ -22,17 +22,17 @@ public:
static ErrorOr<Vector<Group>> all();
Group() = default;
Group(DeprecatedString name, gid_t id = 0, Vector<DeprecatedString> members = {});
Group(ByteString name, gid_t id = 0, Vector<ByteString> members = {});
~Group() = default;
DeprecatedString const& name() const { return m_name; }
void set_name(DeprecatedString const& name) { m_name = name; }
ByteString const& name() const { return m_name; }
void set_name(ByteString const& name) { m_name = name; }
gid_t id() const { return m_id; }
void set_group_id(gid_t const id) { m_id = id; }
Vector<DeprecatedString>& members() { return m_members; }
Vector<ByteString>& members() { return m_members; }
ErrorOr<void> sync();
@ -41,11 +41,11 @@ private:
static ErrorOr<bool> id_exists(gid_t id);
ErrorOr<struct group> to_libc_group();
ErrorOr<DeprecatedString> generate_group_file() const;
ErrorOr<ByteString> generate_group_file() const;
DeprecatedString m_name;
ByteString m_name;
gid_t m_id { 0 };
Vector<DeprecatedString> m_members;
Vector<ByteString> m_members;
};
}

View file

@ -33,7 +33,7 @@ LocalServer::~LocalServer()
::close(m_fd);
}
ErrorOr<void> LocalServer::take_over_from_system_server(DeprecatedString const& socket_path)
ErrorOr<void> LocalServer::take_over_from_system_server(ByteString const& socket_path)
{
if (m_listening)
return Error::from_string_literal("Core::LocalServer: Can't perform socket takeover when already listening");
@ -65,7 +65,7 @@ void LocalServer::setup_notifier()
};
}
bool LocalServer::listen(DeprecatedString const& address)
bool LocalServer::listen(ByteString const& address)
{
if (m_listening)
return false;

View file

@ -16,9 +16,9 @@ class LocalServer : public EventReceiver {
public:
virtual ~LocalServer() override;
ErrorOr<void> take_over_from_system_server(DeprecatedString const& path = DeprecatedString());
ErrorOr<void> take_over_from_system_server(ByteString const& path = ByteString());
bool is_listening() const { return m_listening; }
bool listen(DeprecatedString const& address);
bool listen(ByteString const& address);
ErrorOr<NonnullOwnPtr<LocalSocket>> accept();

View file

@ -27,7 +27,7 @@ ErrorOr<void> MimeData::set_urls(Vector<URL> const& urls)
{
StringBuilder builder;
for (auto& url : urls) {
TRY(builder.try_append(url.to_deprecated_string()));
TRY(builder.try_append(url.to_byte_string()));
TRY(builder.try_append('\n'));
}
set_data("text/uri-list"_string, TRY(builder.to_byte_buffer()));
@ -35,12 +35,12 @@ ErrorOr<void> MimeData::set_urls(Vector<URL> const& urls)
return {};
}
DeprecatedString MimeData::text() const
ByteString MimeData::text() const
{
return DeprecatedString::copy(m_data.get("text/plain"sv).value_or({}));
return ByteString::copy(m_data.get("text/plain"sv).value_or({}));
}
void MimeData::set_text(DeprecatedString const& text)
void MimeData::set_text(ByteString const& text)
{
set_data("text/plain"_string, text.to_byte_buffer());
}

View file

@ -28,8 +28,8 @@ public:
// Convenience helpers for "text/plain"
bool has_text() const { return has_format("text/plain"sv); }
DeprecatedString text() const;
void set_text(DeprecatedString const&);
ByteString text() const;
void set_text(ByteString const&);
// Convenience helpers for "text/uri-list"
bool has_urls() const { return has_format("text/uri-list"sv); }

View file

@ -27,7 +27,7 @@ public:
virtual ~NetworkJob() override = default;
// Could fire twice, after Headers and after Trailers!
Function<void(HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code)> on_headers_received;
Function<void(HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code)> on_headers_received;
Function<void(bool success)> on_finish;
Function<void(Optional<u64>, u64)> on_progress;

View file

@ -6,7 +6,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <AK/Vector.h>
@ -35,10 +35,10 @@ extern "C" {
namespace Core {
struct ArgvList {
DeprecatedString m_path;
ByteString m_path;
Vector<char const*, 10> m_argv;
ArgvList(DeprecatedString path, size_t size)
ArgvList(ByteString path, size_t size)
: m_path { path }
{
m_argv.ensure_capacity(size + 2);
@ -103,12 +103,12 @@ ErrorOr<Process> Process::spawn(ProcessSpawnOptions const& options)
return Process { pid };
}
ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<DeprecatedString> arguments, DeprecatedString working_directory, KeepAsChild keep_as_child)
ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<ByteString> arguments, ByteString working_directory, KeepAsChild keep_as_child)
{
auto process = TRY(spawn({
.path = path,
.arguments = Vector<DeprecatedString> { arguments },
.working_directory = working_directory.is_empty() ? Optional<DeprecatedString> {} : Optional<DeprecatedString> { working_directory },
.arguments = Vector<ByteString> { arguments },
.working_directory = working_directory.is_empty() ? Optional<ByteString> {} : Optional<ByteString> { working_directory },
}));
if (keep_as_child == KeepAsChild::No)
@ -120,9 +120,9 @@ ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<DeprecatedString> ar
return process.pid();
}
ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<StringView> arguments, DeprecatedString working_directory, KeepAsChild keep_as_child)
ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<StringView> arguments, ByteString working_directory, KeepAsChild keep_as_child)
{
Vector<DeprecatedString> backing_strings;
Vector<ByteString> backing_strings;
backing_strings.ensure_capacity(arguments.size());
for (auto const& argument : arguments)
backing_strings.append(argument);
@ -130,7 +130,7 @@ ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<StringView> argument
auto process = TRY(spawn({
.path = path,
.arguments = backing_strings,
.working_directory = working_directory.is_empty() ? Optional<DeprecatedString> {} : Optional<DeprecatedString> { working_directory },
.working_directory = working_directory.is_empty() ? Optional<ByteString> {} : Optional<ByteString> { working_directory },
}));
if (keep_as_child == KeepAsChild::No)
@ -140,9 +140,9 @@ ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<StringView> argument
return process.pid();
}
ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<char const*> arguments, DeprecatedString working_directory, KeepAsChild keep_as_child)
ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<char const*> arguments, ByteString working_directory, KeepAsChild keep_as_child)
{
Vector<DeprecatedString> backing_strings;
Vector<ByteString> backing_strings;
backing_strings.ensure_capacity(arguments.size());
for (auto const& argument : arguments)
backing_strings.append(argument);
@ -150,7 +150,7 @@ ErrorOr<pid_t> Process::spawn(StringView path, ReadonlySpan<char const*> argumen
auto process = TRY(spawn({
.path = path,
.arguments = backing_strings,
.working_directory = working_directory.is_empty() ? Optional<DeprecatedString> {} : Optional<DeprecatedString> { working_directory },
.working_directory = working_directory.is_empty() ? Optional<ByteString> {} : Optional<ByteString> { working_directory },
}));
if (keep_as_child == KeepAsChild::No)

View file

@ -8,7 +8,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Forward.h>
#include <AK/Span.h>
#include <LibCore/File.h>
@ -18,7 +18,7 @@ namespace Core {
namespace FileAction {
struct OpenFile {
DeprecatedString path;
ByteString path;
File::OpenMode mode = File::OpenMode::NotOpen;
int fd = -1;
mode_t permissions = 0600;
@ -29,9 +29,9 @@ struct OpenFile {
}
struct ProcessSpawnOptions {
DeprecatedString path;
Vector<DeprecatedString> const& arguments = {};
Optional<DeprecatedString> working_directory = {};
ByteString path;
Vector<ByteString> const& arguments = {};
Optional<ByteString> working_directory = {};
Vector<Variant<FileAction::OpenFile>> const& file_actions = {};
};
@ -60,11 +60,11 @@ public:
static ErrorOr<Process> spawn(ProcessSpawnOptions const& options);
// FIXME: Make the following 2 functions return Process instance or delete them.
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<DeprecatedString> arguments, DeprecatedString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<StringView> arguments, DeprecatedString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<ByteString> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<StringView> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
// FIXME: Remove this. char const* should not exist on this level of abstraction.
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<char const*> arguments = {}, DeprecatedString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<char const*> arguments = {}, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
static ErrorOr<String> get_name();
enum class SetThreadName {

View file

@ -14,7 +14,7 @@
namespace Core {
HashMap<uid_t, DeprecatedString> ProcessStatisticsReader::s_usernames;
HashMap<uid_t, ByteString> ProcessStatisticsReader::s_usernames;
ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(SeekableStream& proc_all_file, bool include_usernames)
{
@ -37,11 +37,11 @@ ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(SeekableStream&
process.gid = process_object.get_u32("gid"sv).value_or(0);
process.ppid = process_object.get_u32("ppid"sv).value_or(0);
process.kernel = process_object.get_bool("kernel"sv).value_or(false);
process.name = process_object.get_deprecated_string("name"sv).value_or("");
process.executable = process_object.get_deprecated_string("executable"sv).value_or("");
process.tty = process_object.get_deprecated_string("tty"sv).value_or("");
process.pledge = process_object.get_deprecated_string("pledge"sv).value_or("");
process.veil = process_object.get_deprecated_string("veil"sv).value_or("");
process.name = process_object.get_byte_string("name"sv).value_or("");
process.executable = process_object.get_byte_string("executable"sv).value_or("");
process.tty = process_object.get_byte_string("tty"sv).value_or("");
process.pledge = process_object.get_byte_string("pledge"sv).value_or("");
process.veil = process_object.get_byte_string("veil"sv).value_or("");
process.creation_time = UnixDateTime::from_nanoseconds_since_epoch(process_object.get_i64("creation_time"sv).value_or(0));
process.amount_virtual = process_object.get_u32("amount_virtual"sv).value_or(0);
process.amount_resident = process_object.get_u32("amount_resident"sv).value_or(0);
@ -58,8 +58,8 @@ ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(SeekableStream&
Core::ThreadStatistics thread;
thread.tid = thread_object.get_u32("tid"sv).value_or(0);
thread.times_scheduled = thread_object.get_u32("times_scheduled"sv).value_or(0);
thread.name = thread_object.get_deprecated_string("name"sv).value_or("");
thread.state = thread_object.get_deprecated_string("state"sv).value_or("");
thread.name = thread_object.get_byte_string("name"sv).value_or("");
thread.state = thread_object.get_byte_string("state"sv).value_or("");
thread.time_user = thread_object.get_u64("time_user"sv).value_or(0);
thread.time_kernel = thread_object.get_u64("time_kernel"sv).value_or(0);
thread.cpu = thread_object.get_u32("cpu"sv).value_or(0);
@ -95,7 +95,7 @@ ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(bool include_us
return get_all(*proc_all_file, include_usernames);
}
DeprecatedString ProcessStatisticsReader::username_from_uid(uid_t uid)
ByteString ProcessStatisticsReader::username_from_uid(uid_t uid)
{
if (s_usernames.is_empty()) {
setpwent();
@ -107,6 +107,6 @@ DeprecatedString ProcessStatisticsReader::username_from_uid(uid_t uid)
auto it = s_usernames.find(uid);
if (it != s_usernames.end())
return (*it).value;
return DeprecatedString::number(uid);
return ByteString::number(uid);
}
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Time.h>
#include <AK/Vector.h>
#include <unistd.h>
@ -28,10 +28,10 @@ struct ThreadStatistics {
u64 ipv4_socket_write_bytes;
u64 file_read_bytes;
u64 file_write_bytes;
DeprecatedString state;
ByteString state;
u32 cpu;
u32 priority;
DeprecatedString name;
ByteString name;
};
struct ProcessStatistics {
@ -45,11 +45,11 @@ struct ProcessStatistics {
gid_t gid;
pid_t ppid;
bool kernel;
DeprecatedString name;
DeprecatedString executable;
DeprecatedString tty;
DeprecatedString pledge;
DeprecatedString veil;
ByteString name;
ByteString executable;
ByteString tty;
ByteString pledge;
ByteString veil;
UnixDateTime creation_time;
size_t amount_virtual;
size_t amount_resident;
@ -62,7 +62,7 @@ struct ProcessStatistics {
Vector<Core::ThreadStatistics> threads;
// synthetic
DeprecatedString username;
ByteString username;
};
struct AllProcessesStatistics {
@ -77,8 +77,8 @@ public:
static ErrorOr<AllProcessesStatistics> get_all(bool include_usernames = true);
private:
static DeprecatedString username_from_uid(uid_t);
static HashMap<uid_t, DeprecatedString> s_usernames;
static ByteString username_from_uid(uid_t);
static HashMap<uid_t, ByteString> s_usernames;
};
}

View file

@ -72,9 +72,9 @@ Vector<String> ResourceImplementation::child_names(Resource const& resource)
VERIFY(resource.m_scheme == Resource::Scheme::File);
Vector<String> children;
Core::DirIterator it(resource.filesystem_path().to_deprecated_string(), Core::DirIterator::SkipParentAndBaseDir);
Core::DirIterator it(resource.filesystem_path().to_byte_string(), Core::DirIterator::SkipParentAndBaseDir);
while (it.has_next())
children.append(MUST(String::from_deprecated_string(it.next_path())));
children.append(MUST(String::from_byte_string(it.next_path())));
return children;
}

View file

@ -24,7 +24,7 @@ ErrorOr<NonnullRefPtr<Resource>> ResourceImplementationFile::load_from_resource_
VERIFY(uri.starts_with(resource_scheme));
auto path = TRY(String::from_utf8(uri.substring_view(resource_scheme.length())));
auto full_path = TRY(String::from_deprecated_string(LexicalPath::join(m_base_directory, path).string()));
auto full_path = TRY(String::from_byte_string(LexicalPath::join(m_base_directory, path).string()));
if (is_directory(full_path))
return make_directory_resource(move(path));
@ -34,16 +34,16 @@ ErrorOr<NonnullRefPtr<Resource>> ResourceImplementationFile::load_from_resource_
Vector<String> ResourceImplementationFile::child_names_for_resource_scheme(Resource const& resource)
{
Vector<String> children;
Core::DirIterator it(resource.filesystem_path().to_deprecated_string(), Core::DirIterator::SkipParentAndBaseDir);
Core::DirIterator it(resource.filesystem_path().to_byte_string(), Core::DirIterator::SkipParentAndBaseDir);
while (it.has_next())
children.append(MUST(String::from_deprecated_string(it.next_path())));
children.append(MUST(String::from_byte_string(it.next_path())));
return children;
}
String ResourceImplementationFile::filesystem_path_for_resource_scheme(String const& relative_path)
{
return MUST(String::from_deprecated_string(LexicalPath::join(m_base_directory, relative_path).string()));
return MUST(String::from_byte_string(LexicalPath::join(m_base_directory, relative_path).string()));
}
}

View file

@ -161,7 +161,7 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
TRY(stream.write_value(header));
TRY(target.visit(
[&](DeprecatedString const& hostname) -> ErrorOr<void> {
[&](ByteString const& hostname) -> ErrorOr<void> {
u8 address_data[2];
address_data[0] = to_underlying(AddressType::DomainName);
address_data[1] = hostname.length();
@ -298,7 +298,7 @@ ErrorOr<NonnullOwnPtr<SOCKSProxyClient>> SOCKSProxyClient::connect(HostOrIPV4 co
[&](u32 ipv4) {
return Core::TCPSocket::connect({ IPv4Address(ipv4), static_cast<u16>(server_port) });
},
[&](DeprecatedString const& hostname) {
[&](ByteString const& hostname) {
return Core::TCPSocket::connect(hostname, static_cast<u16>(server_port));
}));

View file

@ -19,8 +19,8 @@ public:
};
struct UsernamePasswordAuthenticationData {
DeprecatedString username;
DeprecatedString password;
ByteString username;
ByteString password;
};
enum class Command : u8 {
@ -29,7 +29,7 @@ public:
UDPAssociate = 0x03,
};
using HostOrIPV4 = Variant<DeprecatedString, u32>;
using HostOrIPV4 = Variant<ByteString, u32>;
static ErrorOr<NonnullOwnPtr<SOCKSProxyClient>> connect(Socket& underlying, Version, HostOrIPV4 const& target, int target_port, Variant<UsernamePasswordAuthenticationData, Empty> const& auth_data = {}, Command = Command::Connect);
static ErrorOr<NonnullOwnPtr<SOCKSProxyClient>> connect(HostOrIPV4 const& server, int server_port, Version, HostOrIPV4 const& target, int target_port, Variant<UsernamePasswordAuthenticationData, Empty> const& auth_data = {}, Command = Command::Connect);

View file

@ -34,19 +34,19 @@ ErrorOr<void> logout(Optional<pid_t> force_sid)
return {};
}
ErrorOr<DeprecatedString> parse_path_with_sid(StringView general_path, Optional<pid_t> force_sid)
ErrorOr<ByteString> parse_path_with_sid(StringView general_path, Optional<pid_t> force_sid)
{
if (general_path.contains("%sid"sv)) {
pid_t sid = TRY(root_session_id(force_sid));
return general_path.replace("%sid"sv, DeprecatedString::number(sid), ReplaceMode::All);
return general_path.replace("%sid"sv, ByteString::number(sid), ReplaceMode::All);
}
return DeprecatedString(general_path);
return ByteString(general_path);
}
ErrorOr<void> create_session_temporary_directory_if_needed(uid_t uid, gid_t gid, Optional<pid_t> force_sid)
{
pid_t sid = TRY(root_session_id(force_sid));
auto const temporary_directory = DeprecatedString::formatted("/tmp/session/{}", sid);
auto const temporary_directory = ByteString::formatted("/tmp/session/{}", sid);
auto directory = TRY(Core::Directory::create(temporary_directory, Core::Directory::CreateDirectories::Yes));
TRY(directory.chown(uid, gid));
return {};

View file

@ -14,7 +14,7 @@ namespace Core::SessionManagement {
ErrorOr<pid_t> root_session_id(Optional<pid_t> force_sid = {});
ErrorOr<void> logout(Optional<pid_t> force_sid = {});
ErrorOr<DeprecatedString> parse_path_with_sid(StringView general_path, Optional<pid_t> force_sid = {});
ErrorOr<ByteString> parse_path_with_sid(StringView general_path, Optional<pid_t> force_sid = {});
ErrorOr<void> create_session_temporary_directory_if_needed(uid_t uid, gid_t gid, Optional<pid_t> force_sid = {});
}

View file

@ -9,8 +9,8 @@
#include <AK/Assertions.h>
#include <AK/Atomic.h>
#include <AK/BuiltinWrappers.h>
#include <AK/ByteString.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/Format.h>
#include <AK/Function.h>
@ -200,7 +200,7 @@ private:
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> create_internal(int fd, bool is_new)
{
auto name = DeprecatedString::formatted("SharedSingleProducerCircularQueue@{:x}", fd);
auto name = ByteString::formatted("SharedSingleProducerCircularQueue@{:x}", fd);
auto* raw_mapping = TRY(System::mmap(nullptr, sizeof(SharedMemorySPCQ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0, 0, name));
dbgln_if(SHARED_QUEUE_DEBUG, "successfully mmapped {} at {:p}", name, raw_mapping);
@ -212,7 +212,7 @@ private:
return SharedSingleProducerCircularQueue<T, Size> { move(name), adopt_ref(*new (nothrow) RefCountedSharedMemorySPCQ(shared_queue, fd)) };
}
SharedSingleProducerCircularQueue(DeprecatedString name, RefPtr<RefCountedSharedMemorySPCQ> queue)
SharedSingleProducerCircularQueue(ByteString name, RefPtr<RefCountedSharedMemorySPCQ> queue)
: m_queue(queue)
, m_name(move(name))
{
@ -220,7 +220,7 @@ private:
RefPtr<RefCountedSharedMemorySPCQ> m_queue;
DeprecatedString m_name {};
ByteString m_name {};
};
}

View file

@ -46,7 +46,7 @@ ErrorOr<int> Socket::create_fd(SocketDomain domain, SocketType type)
#endif
}
ErrorOr<IPv4Address> Socket::resolve_host(DeprecatedString const& host, SocketType type)
ErrorOr<IPv4Address> Socket::resolve_host(ByteString const& host, SocketType type)
{
int socket_type;
switch (type) {
@ -79,7 +79,7 @@ ErrorOr<IPv4Address> Socket::resolve_host(DeprecatedString const& host, SocketTy
return Error::from_string_literal("Could not resolve to IPv4 address");
}
ErrorOr<void> Socket::connect_local(int fd, DeprecatedString const& path)
ErrorOr<void> Socket::connect_local(int fd, ByteString const& path)
{
auto address = SocketAddress::local(path);
auto maybe_sockaddr = address.to_sockaddr_un();
@ -189,7 +189,7 @@ void PosixSocketHelper::setup_notifier()
m_notifier = Core::Notifier::construct(m_fd, Core::Notifier::Type::Read);
}
ErrorOr<NonnullOwnPtr<TCPSocket>> TCPSocket::connect(DeprecatedString const& host, u16 port)
ErrorOr<NonnullOwnPtr<TCPSocket>> TCPSocket::connect(ByteString const& host, u16 port)
{
auto ip_address = TRY(resolve_host(host, SocketType::Stream));
return connect(SocketAddress { ip_address, port });
@ -231,7 +231,7 @@ ErrorOr<size_t> PosixSocketHelper::pending_bytes() const
return static_cast<size_t>(value);
}
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout)
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(ByteString const& host, u16 port, Optional<Duration> timeout)
{
auto ip_address = TRY(resolve_host(host, SocketType::Datagram));
return connect(SocketAddress { ip_address, port }, timeout);
@ -253,7 +253,7 @@ ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& addres
return socket;
}
ErrorOr<NonnullOwnPtr<LocalSocket>> LocalSocket::connect(DeprecatedString const& path, PreventSIGPIPE prevent_sigpipe)
ErrorOr<NonnullOwnPtr<LocalSocket>> LocalSocket::connect(ByteString const& path, PreventSIGPIPE prevent_sigpipe)
{
auto socket = TRY(adopt_nonnull_own_or_enomem(new (nothrow) LocalSocket(prevent_sigpipe)));

View file

@ -72,9 +72,9 @@ protected:
static ErrorOr<int> create_fd(SocketDomain, SocketType);
// FIXME: This will need to be updated when IPv6 socket arrives. Perhaps a
// base class for all address types is appropriate.
static ErrorOr<IPv4Address> resolve_host(DeprecatedString const&, SocketType);
static ErrorOr<IPv4Address> resolve_host(ByteString const&, SocketType);
static ErrorOr<void> connect_local(int fd, DeprecatedString const& path);
static ErrorOr<void> connect_local(int fd, ByteString const& path);
static ErrorOr<void> connect_inet(int fd, SocketAddress const&);
int default_flags() const
@ -97,7 +97,7 @@ public:
virtual bool is_connected() = 0;
/// Reconnects the socket to the given host and port. Returns EALREADY if
/// is_connected() is true.
virtual ErrorOr<void> reconnect(DeprecatedString const& host, u16 port) = 0;
virtual ErrorOr<void> reconnect(ByteString const& host, u16 port) = 0;
/// Connects the socket to the given socket address (IP address + port).
/// Returns EALREADY is_connected() is true.
virtual ErrorOr<void> reconnect(SocketAddress const&) = 0;
@ -154,7 +154,7 @@ private:
class TCPSocket final : public Socket {
public:
static ErrorOr<NonnullOwnPtr<TCPSocket>> connect(DeprecatedString const& host, u16 port);
static ErrorOr<NonnullOwnPtr<TCPSocket>> connect(ByteString const& host, u16 port);
static ErrorOr<NonnullOwnPtr<TCPSocket>> connect(SocketAddress const& address);
static ErrorOr<NonnullOwnPtr<TCPSocket>> adopt_fd(int fd);
@ -215,7 +215,7 @@ private:
class UDPSocket final : public Socket {
public:
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout = {});
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(ByteString const& host, u16 port, Optional<Duration> timeout = {});
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Duration> timeout = {});
UDPSocket(UDPSocket&& other)
@ -289,7 +289,7 @@ private:
class LocalSocket final : public Socket {
public:
static ErrorOr<NonnullOwnPtr<LocalSocket>> connect(DeprecatedString const& path, PreventSIGPIPE = PreventSIGPIPE::No);
static ErrorOr<NonnullOwnPtr<LocalSocket>> connect(ByteString const& path, PreventSIGPIPE = PreventSIGPIPE::No);
static ErrorOr<NonnullOwnPtr<LocalSocket>> adopt_fd(int fd, PreventSIGPIPE = PreventSIGPIPE::No);
LocalSocket(LocalSocket&& other)
@ -450,7 +450,7 @@ using BufferedLocalSocket = BufferedSocket<LocalSocket>;
template<SocketLike T>
class BasicReusableSocket final : public ReusableSocket {
public:
static ErrorOr<NonnullOwnPtr<BasicReusableSocket<T>>> connect(DeprecatedString const& host, u16 port)
static ErrorOr<NonnullOwnPtr<BasicReusableSocket<T>>> connect(ByteString const& host, u16 port)
{
return make<BasicReusableSocket<T>>(TRY(T::connect(host, port)));
}
@ -465,7 +465,7 @@ public:
return m_socket.is_open();
}
virtual ErrorOr<void> reconnect(DeprecatedString const& host, u16 port) override
virtual ErrorOr<void> reconnect(ByteString const& host, u16 port) override
{
if (is_connected())
return Error::from_errno(EALREADY);

View file

@ -38,7 +38,7 @@ public:
{
}
static SocketAddress local(DeprecatedString const& address)
static SocketAddress local(ByteString const& address)
{
SocketAddress addr;
addr.m_type = Type::Local;
@ -51,11 +51,11 @@ public:
IPv4Address ipv4_address() const { return m_ipv4_address; }
u16 port() const { return m_port; }
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
switch (m_type) {
case Type::IPv4:
return DeprecatedString::formatted("{}:{}", m_ipv4_address, m_port);
return ByteString::formatted("{}:{}", m_ipv4_address, m_port);
case Type::Local:
return m_local_address;
default:
@ -91,16 +91,16 @@ private:
Type m_type { Type::Invalid };
IPv4Address m_ipv4_address;
u16 m_port { 0 };
DeprecatedString m_local_address;
ByteString m_local_address;
};
}
template<>
struct AK::Formatter<Core::SocketAddress> : Formatter<DeprecatedString> {
struct AK::Formatter<Core::SocketAddress> : Formatter<ByteString> {
ErrorOr<void> format(FormatBuilder& builder, Core::SocketAddress const& value)
{
return Formatter<DeprecatedString>::format(builder, value.to_deprecated_string());
return Formatter<ByteString>::format(builder, value.to_byte_string());
}
};

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/LexicalPath.h>
#include <AK/Platform.h>
#include <AK/String.h>
@ -22,42 +22,42 @@
namespace Core {
DeprecatedString StandardPaths::home_directory()
ByteString StandardPaths::home_directory()
{
if (auto* home_env = getenv("HOME"))
return LexicalPath::canonicalized_path(home_env);
auto* pwd = getpwuid(getuid());
DeprecatedString path = pwd ? pwd->pw_dir : "/";
ByteString path = pwd ? pwd->pw_dir : "/";
endpwent();
return LexicalPath::canonicalized_path(path);
}
DeprecatedString StandardPaths::desktop_directory()
ByteString StandardPaths::desktop_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Desktop"sv);
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
DeprecatedString StandardPaths::documents_directory()
ByteString StandardPaths::documents_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Documents"sv);
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
DeprecatedString StandardPaths::downloads_directory()
ByteString StandardPaths::downloads_directory()
{
StringBuilder builder;
builder.append(home_directory());
builder.append("/Downloads"sv);
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
DeprecatedString StandardPaths::config_directory()
ByteString StandardPaths::config_directory()
{
if (auto* config_directory = getenv("XDG_CONFIG_HOME"))
return LexicalPath::canonicalized_path(config_directory);
@ -71,10 +71,10 @@ DeprecatedString StandardPaths::config_directory()
#else
builder.append("/.config"sv);
#endif
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
DeprecatedString StandardPaths::data_directory()
ByteString StandardPaths::data_directory()
{
if (auto* data_directory = getenv("XDG_DATA_HOME"))
return LexicalPath::canonicalized_path(data_directory);
@ -91,10 +91,10 @@ DeprecatedString StandardPaths::data_directory()
builder.append("/.local/share"sv);
#endif
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
ErrorOr<DeprecatedString> StandardPaths::runtime_directory()
ErrorOr<ByteString> StandardPaths::runtime_directory()
{
if (auto* data_directory = getenv("XDG_RUNTIME_DIR"))
return LexicalPath::canonicalized_path(data_directory);
@ -114,10 +114,10 @@ ErrorOr<DeprecatedString> StandardPaths::runtime_directory()
builder.appendff("/run/user/{}", uid);
#endif
return LexicalPath::canonicalized_path(builder.to_deprecated_string());
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
DeprecatedString StandardPaths::tempfile_directory()
ByteString StandardPaths::tempfile_directory()
{
return "/tmp";
}

View file

@ -14,14 +14,14 @@ namespace Core {
class StandardPaths {
public:
static DeprecatedString home_directory();
static DeprecatedString desktop_directory();
static DeprecatedString documents_directory();
static DeprecatedString downloads_directory();
static DeprecatedString tempfile_directory();
static DeprecatedString config_directory();
static DeprecatedString data_directory();
static ErrorOr<DeprecatedString> runtime_directory();
static ByteString home_directory();
static ByteString desktop_directory();
static ByteString documents_directory();
static ByteString downloads_directory();
static ByteString tempfile_directory();
static ByteString config_directory();
static ByteString data_directory();
static ErrorOr<ByteString> runtime_directory();
static ErrorOr<Vector<String>> font_directories();
};

View file

@ -7,7 +7,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/FixedArray.h>
#include <AK/ScopeGuard.h>
#include <AK/ScopedValueRollback.h>
@ -202,7 +202,7 @@ ErrorOr<void> unveil(StringView path, StringView permissions)
{ nullptr, 0 },
};
DeprecatedString parsed_path;
ByteString parsed_path;
if (!path.is_null()) {
parsed_path = TRY(Core::SessionManagement::parse_path_with_sid(path));
params.path = { parsed_path.characters(), parsed_path.length() };
@ -215,7 +215,7 @@ ErrorOr<void> unveil(StringView path, StringView permissions)
ErrorOr<void> unveil_after_exec(StringView path, StringView permissions)
{
DeprecatedString parsed_path;
ByteString parsed_path;
Syscall::SC_unveil_params params {
static_cast<int>(UnveilFlags::AfterExec),
{ nullptr, 0 },
@ -448,7 +448,7 @@ ErrorOr<struct stat> fstatat(int fd, StringView path, int flags)
Syscall::SC_stat_params params { { path.characters_without_null_termination(), path.length() }, &st, fd, !(flags & AT_SYMLINK_NOFOLLOW) };
int rc = syscall(SC_stat, &params);
#else
DeprecatedString path_string = path;
ByteString path_string = path;
int rc = ::fstatat(fd, path_string.characters(), &st, flags);
#endif
HANDLE_SYSCALL_RETURN_VALUE("fstatat", rc, st);
@ -531,7 +531,7 @@ ErrorOr<int> anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int opti
#elif defined(AK_OS_BSD_GENERIC) || defined(AK_OS_EMSCRIPTEN) || defined(AK_OS_HAIKU)
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);
auto name = DeprecatedString::formatted("/shm-{}{}", (unsigned long)time.tv_sec, (unsigned long)time.tv_nsec);
auto name = ByteString::formatted("/shm-{}{}", (unsigned long)time.tv_sec, (unsigned long)time.tv_nsec);
fd = shm_open(name.characters(), O_RDWR | O_CREAT | options, 0600);
if (shm_unlink(name.characters()) == -1) {
@ -576,7 +576,7 @@ ErrorOr<int> openat(int fd, StringView path, int options, mode_t mode)
HANDLE_SYSCALL_RETURN_VALUE("open", rc, rc);
#else
// NOTE: We have to ensure that the path is null-terminated.
DeprecatedString path_string = path;
ByteString path_string = path;
int rc = ::openat(fd, path_string.characters(), options, mode);
if (rc < 0)
return Error::from_syscall("open"sv, -errno);
@ -609,7 +609,7 @@ ErrorOr<struct stat> stat(StringView path)
int rc = syscall(SC_stat, &params);
HANDLE_SYSCALL_RETURN_VALUE("stat", rc, st);
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::stat(path_string.characters(), &st) < 0)
return Error::from_syscall("stat"sv, -errno);
return st;
@ -627,7 +627,7 @@ ErrorOr<struct stat> lstat(StringView path)
int rc = syscall(SC_stat, &params);
HANDLE_SYSCALL_RETURN_VALUE("lstat", rc, st);
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::lstat(path_string.characters(), &st) < 0)
return Error::from_syscall("lstat"sv, -errno);
return st;
@ -680,21 +680,21 @@ ErrorOr<int> dup2(int source_fd, int destination_fd)
return fd;
}
ErrorOr<DeprecatedString> ptsname(int fd)
ErrorOr<ByteString> ptsname(int fd)
{
auto* name = ::ptsname(fd);
if (!name)
return Error::from_syscall("ptsname"sv, -errno);
return DeprecatedString(name);
return ByteString(name);
}
ErrorOr<DeprecatedString> gethostname()
ErrorOr<ByteString> gethostname()
{
char hostname[HOST_NAME_MAX];
int rc = ::gethostname(hostname, sizeof(hostname));
if (rc < 0)
return Error::from_syscall("gethostname"sv, -errno);
return DeprecatedString(&hostname[0]);
return ByteString(&hostname[0]);
}
ErrorOr<void> sethostname(StringView hostname)
@ -709,13 +709,13 @@ ErrorOr<void> sethostname(StringView hostname)
return {};
}
ErrorOr<DeprecatedString> getcwd()
ErrorOr<ByteString> getcwd()
{
auto* cwd = ::getcwd(nullptr, 0);
if (!cwd)
return Error::from_syscall("getcwd"sv, -errno);
DeprecatedString string_cwd(cwd);
ByteString string_cwd(cwd);
free(cwd);
return string_cwd;
}
@ -773,7 +773,7 @@ ErrorOr<void> chmod(StringView pathname, mode_t mode)
int rc = syscall(SC_chmod, &params);
HANDLE_SYSCALL_RETURN_VALUE("chmod", rc, {});
#else
DeprecatedString path = pathname;
ByteString path = pathname;
if (::chmod(path.characters(), mode) < 0)
return Error::from_syscall("chmod"sv, -errno);
return {};
@ -804,7 +804,7 @@ ErrorOr<void> lchown(StringView pathname, uid_t uid, gid_t gid)
int rc = syscall(SC_chown, &params);
HANDLE_SYSCALL_RETURN_VALUE("chown", rc, {});
#else
DeprecatedString path = pathname;
ByteString path = pathname;
if (::chown(path.characters(), uid, gid) < 0)
return Error::from_syscall("chown"sv, -errno);
return {};
@ -821,7 +821,7 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
int rc = syscall(SC_chown, &params);
HANDLE_SYSCALL_RETURN_VALUE("chown", rc, {});
#else
DeprecatedString path = pathname;
ByteString path = pathname;
if (::lchown(path.characters(), uid, gid) < 0)
return Error::from_syscall("lchown"sv, -errno);
return {};
@ -913,7 +913,7 @@ ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts)
static ALWAYS_INLINE ErrorOr<pid_t> posix_spawn_wrapper(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[], StringView function_name, decltype(::posix_spawn) spawn_function)
{
pid_t child_pid;
if ((errno = spawn_function(&child_pid, path.to_deprecated_string().characters(), file_actions, attr, arguments, envp)))
if ((errno = spawn_function(&child_pid, path.to_byte_string().characters(), file_actions, attr, arguments, envp)))
return Error::from_syscall(function_name, -errno);
return child_pid;
}
@ -1036,8 +1036,8 @@ ErrorOr<void> link(StringView old_path, StringView new_path)
int rc = syscall(SC_link, &params);
HANDLE_SYSCALL_RETURN_VALUE("link", rc, {});
#else
DeprecatedString old_path_string = old_path;
DeprecatedString new_path_string = new_path;
ByteString old_path_string = old_path;
ByteString new_path_string = new_path;
if (::link(old_path_string.characters(), new_path_string.characters()) < 0)
return Error::from_syscall("link"sv, -errno);
return {};
@ -1055,8 +1055,8 @@ ErrorOr<void> symlink(StringView target, StringView link_path)
int rc = syscall(SC_symlink, &params);
HANDLE_SYSCALL_RETURN_VALUE("symlink", rc, {});
#else
DeprecatedString target_string = target;
DeprecatedString link_path_string = link_path;
ByteString target_string = target;
ByteString link_path_string = link_path;
if (::symlink(target_string.characters(), link_path_string.characters()) < 0)
return Error::from_syscall("symlink"sv, -errno);
return {};
@ -1071,7 +1071,7 @@ ErrorOr<void> mkdir(StringView path, mode_t mode)
int rc = syscall(SC_mkdir, AT_FDCWD, path.characters_without_null_termination(), path.length(), mode);
HANDLE_SYSCALL_RETURN_VALUE("mkdir", rc, {});
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::mkdir(path_string.characters(), mode) < 0)
return Error::from_syscall("mkdir"sv, -errno);
return {};
@ -1086,7 +1086,7 @@ ErrorOr<void> chdir(StringView path)
int rc = syscall(SC_chdir, path.characters_without_null_termination(), path.length());
HANDLE_SYSCALL_RETURN_VALUE("chdir", rc, {});
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::chdir(path_string.characters()) < 0)
return Error::from_syscall("chdir"sv, -errno);
return {};
@ -1101,7 +1101,7 @@ ErrorOr<void> rmdir(StringView path)
int rc = syscall(SC_rmdir, path.characters_without_null_termination(), path.length());
HANDLE_SYSCALL_RETURN_VALUE("rmdir", rc, {});
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::rmdir(path_string.characters()) < 0)
return Error::from_syscall("rmdir"sv, -errno);
return {};
@ -1149,8 +1149,8 @@ ErrorOr<void> rename(StringView old_path, StringView new_path)
int rc = syscall(SC_rename, &params);
HANDLE_SYSCALL_RETURN_VALUE("rename", rc, {});
#else
DeprecatedString old_path_string = old_path;
DeprecatedString new_path_string = new_path;
ByteString old_path_string = old_path;
ByteString new_path_string = new_path;
if (::rename(old_path_string.characters(), new_path_string.characters()) < 0)
return Error::from_syscall("rename"sv, -errno);
return {};
@ -1166,7 +1166,7 @@ ErrorOr<void> unlink(StringView path)
int rc = syscall(SC_unlink, AT_FDCWD, path.characters_without_null_termination(), path.length(), 0);
HANDLE_SYSCALL_RETURN_VALUE("unlink", rc, {});
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::unlink(path_string.characters()) < 0)
return Error::from_syscall("unlink"sv, -errno);
return {};
@ -1185,7 +1185,7 @@ ErrorOr<void> utime(StringView path, Optional<struct utimbuf> maybe_buf)
int rc = syscall(SC_utime, path.characters_without_null_termination(), path.length(), buf);
HANDLE_SYSCALL_RETURN_VALUE("utime", rc, {});
#else
DeprecatedString path_string = path;
ByteString path_string = path;
if (::utime(path_string.characters(), buf) < 0)
return Error::from_syscall("utime"sv, -errno);
return {};
@ -1364,22 +1364,22 @@ ErrorOr<void> exec(StringView filename, ReadonlySpan<StringView> arguments, Sear
TRY(run_exec(params));
VERIFY_NOT_REACHED();
#else
DeprecatedString filename_string { filename };
ByteString filename_string { filename };
auto argument_strings = TRY(FixedArray<DeprecatedString>::create(arguments.size()));
auto argument_strings = TRY(FixedArray<ByteString>::create(arguments.size()));
auto argv = TRY(FixedArray<char*>::create(arguments.size() + 1));
for (size_t i = 0; i < arguments.size(); ++i) {
argument_strings[i] = arguments[i].to_deprecated_string();
argument_strings[i] = arguments[i].to_byte_string();
argv[i] = const_cast<char*>(argument_strings[i].characters());
}
argv[arguments.size()] = nullptr;
int rc = 0;
if (environment.has_value()) {
auto environment_strings = TRY(FixedArray<DeprecatedString>::create(environment->size()));
auto environment_strings = TRY(FixedArray<ByteString>::create(environment->size()));
auto envp = TRY(FixedArray<char*>::create(environment->size() + 1));
for (size_t i = 0; i < environment->size(); ++i) {
environment_strings[i] = environment->at(i).to_deprecated_string();
environment_strings[i] = environment->at(i).to_byte_string();
envp[i] = const_cast<char*>(environment_strings[i].characters());
}
envp[environment->size()] = nullptr;
@ -1396,7 +1396,7 @@ ErrorOr<void> exec(StringView filename, ReadonlySpan<StringView> arguments, Sear
return executable_or_error.release_error();
}
DeprecatedString executable = executable_or_error.release_value().to_deprecated_string();
ByteString executable = executable_or_error.release_value().to_byte_string();
rc = ::execve(executable.characters(), argv.data(), envp.data());
# else
rc = ::execvpe(filename_string.characters(), argv.data(), envp.data());
@ -1611,7 +1611,7 @@ ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev)
int rc = syscall(SC_mknod, &params);
HANDLE_SYSCALL_RETURN_VALUE("mknod", rc, {});
#else
DeprecatedString path_string = pathname;
ByteString path_string = pathname;
if (::mknod(path_string.characters(), mode, dev) < 0)
return Error::from_syscall("mknod"sv, -errno);
return {};
@ -1705,7 +1705,7 @@ ErrorOr<void> access(StringView pathname, int mode, int flags)
int rc = ::syscall(Syscall::SC_faccessat, &params);
HANDLE_SYSCALL_RETURN_VALUE("access", rc, {});
#else
DeprecatedString path_string = pathname;
ByteString path_string = pathname;
(void)flags;
if (::access(path_string.characters(), mode) < 0)
return Error::from_syscall("access"sv, -errno);
@ -1713,7 +1713,7 @@ ErrorOr<void> access(StringView pathname, int mode, int flags)
#endif
}
ErrorOr<DeprecatedString> readlink(StringView pathname)
ErrorOr<ByteString> readlink(StringView pathname)
{
// FIXME: Try again with a larger buffer.
#ifdef AK_OS_SERENITY
@ -1724,7 +1724,7 @@ ErrorOr<DeprecatedString> readlink(StringView pathname)
.dirfd = AT_FDCWD,
};
int rc = syscall(SC_readlink, &small_params);
HANDLE_SYSCALL_RETURN_VALUE("readlink", rc, DeprecatedString(data, rc));
HANDLE_SYSCALL_RETURN_VALUE("readlink", rc, ByteString(data, rc));
#elif defined(AK_OS_GNU_HURD)
// PATH_MAX is not defined, nor is there an upper limit on path lengths.
// Let's do this the right way.
@ -1732,15 +1732,15 @@ ErrorOr<DeprecatedString> readlink(StringView pathname)
auto file = TRY(File::adopt_fd(fd, File::OpenMode::Read));
auto buffer = TRY(file->read_until_eof());
// TODO: Get rid of this copy here.
return DeprecatedString::copy(buffer);
return ByteString::copy(buffer);
#else
char data[PATH_MAX];
DeprecatedString path_string = pathname;
ByteString path_string = pathname;
int rc = ::readlink(path_string.characters(), data, sizeof(data));
if (rc == -1)
return Error::from_syscall("readlink"sv, -errno);
return DeprecatedString(data, rc);
return ByteString(data, rc);
#endif
}
@ -1806,7 +1806,7 @@ char** environment()
#endif
}
ErrorOr<DeprecatedString> current_executable_path()
ErrorOr<ByteString> current_executable_path()
{
char path[4096] = {};
#if defined(AK_OS_LINUX) || defined(AK_OS_ANDROID) || defined(AK_OS_SERENITY)
@ -1862,7 +1862,7 @@ ErrorOr<DeprecatedString> current_executable_path()
return Error::from_string_view("current_executable_path unknown"sv);
#endif
path[sizeof(path) - 1] = '\0';
return DeprecatedString { path, strlen(path) };
return ByteString { path, strlen(path) };
}
ErrorOr<Bytes> allocate(size_t count, size_t size)

View file

@ -135,10 +135,10 @@ ErrorOr<void> kill(pid_t, int signal);
ErrorOr<void> killpg(int pgrp, int signal);
ErrorOr<int> dup(int source_fd);
ErrorOr<int> dup2(int source_fd, int destination_fd);
ErrorOr<DeprecatedString> ptsname(int fd);
ErrorOr<DeprecatedString> gethostname();
ErrorOr<ByteString> ptsname(int fd);
ErrorOr<ByteString> gethostname();
ErrorOr<void> sethostname(StringView);
ErrorOr<DeprecatedString> getcwd();
ErrorOr<ByteString> getcwd();
ErrorOr<void> ioctl(int fd, unsigned request, ...);
ErrorOr<struct termios> tcgetattr(int fd);
ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
@ -235,7 +235,7 @@ ErrorOr<int> posix_openpt(int flags);
ErrorOr<void> grantpt(int fildes);
ErrorOr<void> unlockpt(int fildes);
ErrorOr<void> access(StringView pathname, int mode, int flags = 0);
ErrorOr<DeprecatedString> readlink(StringView pathname);
ErrorOr<ByteString> readlink(StringView pathname);
ErrorOr<int> poll(Span<struct pollfd>, int timeout);
#ifdef AK_OS_SERENITY
@ -279,7 +279,7 @@ ErrorOr<String> resolve_executable_from_environment(StringView filename, int fla
char** environment();
ErrorOr<DeprecatedString> current_executable_path();
ErrorOr<ByteString> current_executable_path();
ErrorOr<Bytes> allocate(size_t count, size_t size);

View file

@ -10,7 +10,7 @@
namespace Core {
HashMap<DeprecatedString, int> s_overtaken_sockets {};
HashMap<ByteString, int> s_overtaken_sockets {};
bool s_overtaken_sockets_parsed { false };
static void parse_sockets_from_system_server()
@ -27,7 +27,7 @@ static void parse_sockets_from_system_server()
for (auto const socket : StringView { sockets, strlen(sockets) }.split_view(';')) {
auto params = socket.split_view(':');
VERIFY(params.size() == 2);
s_overtaken_sockets.set(params[0].to_deprecated_string(), params[1].to_int().value());
s_overtaken_sockets.set(params[0].to_byte_string(), params[1].to_int().value());
}
s_overtaken_sockets_parsed = true;
@ -36,7 +36,7 @@ static void parse_sockets_from_system_server()
unsetenv(socket_takeover);
}
ErrorOr<NonnullOwnPtr<Core::LocalSocket>> take_over_socket_from_system_server(DeprecatedString const& socket_path)
ErrorOr<NonnullOwnPtr<Core::LocalSocket>> take_over_socket_from_system_server(ByteString const& socket_path)
{
if (!s_overtaken_sockets_parsed)
parse_sockets_from_system_server();

View file

@ -10,6 +10,6 @@
namespace Core {
ErrorOr<NonnullOwnPtr<Core::LocalSocket>> take_over_socket_from_system_server(DeprecatedString const& socket_path = {});
ErrorOr<NonnullOwnPtr<Core::LocalSocket>> take_over_socket_from_system_server(ByteString const& socket_path = {});
}

View file

@ -20,7 +20,7 @@ namespace Coredump {
ELFObjectInfo const* Backtrace::object_info_for_region(Reader const& coredump, MemoryRegionInfo const& region)
{
DeprecatedString path = coredump.resolve_object_path(region.object_name());
ByteString path = coredump.resolve_object_path(region.object_name());
auto maybe_ptr = m_debug_info_cache.get(path);
if (maybe_ptr.has_value())
@ -127,13 +127,13 @@ void Backtrace::add_entry(Reader const& coredump, FlatPtr ip)
m_entries.append({ ip, object_name, function_name, source_position });
}
DeprecatedString Backtrace::Entry::to_deprecated_string(bool color) const
ByteString Backtrace::Entry::to_byte_string(bool color) const
{
StringBuilder builder;
builder.appendff("{:p}: ", eip);
if (object_name.is_empty()) {
builder.append("???"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
builder.appendff("[{}] {}", object_name, function_name.is_empty() ? "???" : function_name);
builder.append(" ("sv);
@ -160,7 +160,7 @@ DeprecatedString Backtrace::Entry::to_deprecated_string(bool color) const
builder.append(')');
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}

View file

@ -31,11 +31,11 @@ class Backtrace {
public:
struct Entry {
FlatPtr eip;
DeprecatedString object_name;
DeprecatedString function_name;
ByteString object_name;
ByteString function_name;
Debug::DebugInfo::SourcePositionWithInlines source_position_with_inlines;
DeprecatedString to_deprecated_string(bool color = false) const;
ByteString to_byte_string(bool color = false) const;
};
Backtrace(Reader const&, const ELF::Core::ThreadInfo&, Function<void(size_t, size_t)> on_progress = {});
@ -51,7 +51,7 @@ private:
bool m_skip_loader_so { false };
ELF::Core::ThreadInfo m_thread_info;
Vector<Entry> m_entries;
HashMap<DeprecatedString, NonnullOwnPtr<ELFObjectInfo>> m_debug_info_cache;
HashMap<ByteString, NonnullOwnPtr<ELFObjectInfo>> m_debug_info_cache;
};
}

View file

@ -46,7 +46,7 @@ void Inspector::parse_loaded_libraries(Function<void(float)> on_progress)
return;
auto image = make<ELF::Image>(file_or_error.value()->bytes());
auto debug_info = make<Debug::DebugInfo>(*image, DeprecatedString {}, library.base_address);
auto debug_info = make<Debug::DebugInfo>(*image, ByteString {}, library.base_address);
m_loaded_libraries.append(make<Debug::LoadedLibrary>(library.name, file_or_error.release_value(), move(image), move(debug_info), library.base_address));
});
}

View file

@ -210,20 +210,20 @@ u8 Reader::process_termination_signal() const
return *termination_signal;
}
DeprecatedString Reader::process_executable_path() const
ByteString Reader::process_executable_path() const
{
auto process_info = this->process_info();
auto executable_path = process_info.get_deprecated_string("executable_path"sv);
auto executable_path = process_info.get_byte_string("executable_path"sv);
return executable_path.value_or({});
}
Vector<DeprecatedString> Reader::process_arguments() const
Vector<ByteString> Reader::process_arguments() const
{
auto process_info = this->process_info();
auto arguments = process_info.get_array("arguments"sv);
if (!arguments.has_value())
return {};
Vector<DeprecatedString> vector;
Vector<ByteString> vector;
arguments->for_each([&](auto& value) {
if (value.is_string())
vector.append(value.as_string());
@ -231,13 +231,13 @@ Vector<DeprecatedString> Reader::process_arguments() const
return vector;
}
Vector<DeprecatedString> Reader::process_environment() const
Vector<ByteString> Reader::process_environment() const
{
auto process_info = this->process_info();
auto environment = process_info.get_array("environment"sv);
if (!environment.has_value())
return {};
Vector<DeprecatedString> vector;
Vector<ByteString> vector;
environment->for_each([&](auto& value) {
if (value.is_string())
vector.append(value.as_string());
@ -245,7 +245,7 @@ Vector<DeprecatedString> Reader::process_environment() const
return vector;
}
HashMap<DeprecatedString, DeprecatedString> Reader::metadata() const
HashMap<ByteString, ByteString> Reader::metadata() const
{
const ELF::Core::Metadata* metadata_notes_entry = nullptr;
NotesEntryIterator it(bit_cast<u8 const*>(m_coredump_image.program_header(m_notes_segment_index).raw_data()));
@ -263,7 +263,7 @@ HashMap<DeprecatedString, DeprecatedString> Reader::metadata() const
return {};
if (!metadata_json_value.value().is_object())
return {};
HashMap<DeprecatedString, DeprecatedString> metadata;
HashMap<ByteString, ByteString> metadata;
metadata_json_value.value().as_object().for_each_member([&](auto& key, auto& value) {
metadata.set(key, value.as_string_or({}));
});
@ -272,13 +272,13 @@ HashMap<DeprecatedString, DeprecatedString> Reader::metadata() const
Reader::LibraryData const* Reader::library_containing(FlatPtr address) const
{
static HashMap<DeprecatedString, OwnPtr<LibraryData>> cached_libs;
static HashMap<ByteString, OwnPtr<LibraryData>> cached_libs;
auto region = region_containing(address);
if (!region.has_value())
return {};
auto name = region->object_name();
DeprecatedString path = resolve_object_path(name);
ByteString path = resolve_object_path(name);
if (!cached_libs.contains(path)) {
auto file_or_error = Core::MappedFile::map(path);
@ -292,7 +292,7 @@ Reader::LibraryData const* Reader::library_containing(FlatPtr address) const
return lib_data;
}
DeprecatedString Reader::resolve_object_path(StringView name) const
ByteString Reader::resolve_object_path(StringView name) const
{
// TODO: There are other places where similar method is implemented or would be useful.
// (e.g. UserspaceEmulator, LibSymbolication, Profiler, and DynamicLinker itself)
@ -302,7 +302,7 @@ DeprecatedString Reader::resolve_object_path(StringView name) const
return name;
}
Vector<DeprecatedString> library_search_directories;
Vector<ByteString> library_search_directories;
// If LD_LIBRARY_PATH is present, check its folders first
for (auto& environment_variable : process_environment()) {
@ -336,7 +336,7 @@ DeprecatedString Reader::resolve_object_path(StringView name) const
void Reader::for_each_library(Function<void(LibraryInfo)> func) const
{
HashTable<DeprecatedString> libraries;
HashTable<ByteString> libraries;
for_each_memory_region_info([&](auto const& region) {
auto name = region.object_name();
if (name.is_null() || libraries.contains(name))
@ -344,7 +344,7 @@ void Reader::for_each_library(Function<void(LibraryInfo)> func) const
libraries.set(name);
DeprecatedString path = resolve_object_path(name);
ByteString path = resolve_object_path(name);
func(LibraryInfo { name, path, static_cast<FlatPtr>(region.region_start) });
return IterationDecision::Continue;

View file

@ -47,8 +47,8 @@ public:
void for_each_memory_region_info(Func func) const;
struct LibraryInfo {
DeprecatedString name;
DeprecatedString path;
ByteString name;
ByteString path;
FlatPtr base_address { 0 };
};
@ -64,21 +64,21 @@ public:
Optional<MemoryRegionInfo> region_containing(FlatPtr address) const;
struct LibraryData {
DeprecatedString name;
ByteString name;
FlatPtr base_address { 0 };
NonnullOwnPtr<Core::MappedFile> file;
ELF::Image lib_elf;
};
LibraryData const* library_containing(FlatPtr address) const;
DeprecatedString resolve_object_path(StringView object_name) const;
ByteString resolve_object_path(StringView object_name) const;
int process_pid() const;
u8 process_termination_signal() const;
DeprecatedString process_executable_path() const;
Vector<DeprecatedString> process_arguments() const;
Vector<DeprecatedString> process_environment() const;
HashMap<DeprecatedString, DeprecatedString> metadata() const;
ByteString process_executable_path() const;
Vector<ByteString> process_arguments() const;
Vector<ByteString> process_environment() const;
HashMap<ByteString, ByteString> metadata() const;
private:
explicit Reader(ReadonlyBytes);

View file

@ -32,10 +32,10 @@ void FunctionDeclaration::dump(FILE* output, size_t indent) const
{
ASTNode::dump(output, indent);
DeprecatedString qualifiers_string;
ByteString qualifiers_string;
if (!m_qualifiers.is_empty()) {
print_indent(output, indent + 1);
outln(output, "[{}]", DeprecatedString::join(' ', m_qualifiers));
outln(output, "[{}]", ByteString::join(' ', m_qualifiers));
}
m_return_type->dump(output, indent + 1);
@ -72,51 +72,51 @@ void Type::dump(FILE* output, size_t indent) const
{
ASTNode::dump(output, indent);
print_indent(output, indent + 1);
outln(output, "{}", to_deprecated_string());
outln(output, "{}", to_byte_string());
}
DeprecatedString NamedType::to_deprecated_string() const
ByteString NamedType::to_byte_string() const
{
DeprecatedString qualifiers_string;
ByteString qualifiers_string;
if (!qualifiers().is_empty())
qualifiers_string = DeprecatedString::formatted("[{}] ", DeprecatedString::join(' ', qualifiers()));
qualifiers_string = ByteString::formatted("[{}] ", ByteString::join(' ', qualifiers()));
DeprecatedString name;
ByteString name;
if (is_auto())
name = "auto";
else
name = m_name.is_null() ? ""sv : m_name->full_name();
return DeprecatedString::formatted("{}{}", qualifiers_string, name);
return ByteString::formatted("{}{}", qualifiers_string, name);
}
DeprecatedString Pointer::to_deprecated_string() const
ByteString Pointer::to_byte_string() const
{
if (!m_pointee)
return {};
StringBuilder builder;
builder.append(m_pointee->to_deprecated_string());
builder.append(m_pointee->to_byte_string());
builder.append('*');
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString Reference::to_deprecated_string() const
ByteString Reference::to_byte_string() const
{
if (!m_referenced_type)
return {};
StringBuilder builder;
builder.append(m_referenced_type->to_deprecated_string());
builder.append(m_referenced_type->to_byte_string());
if (m_kind == Kind::Lvalue)
builder.append('&');
else
builder.append("&&"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString FunctionType::to_deprecated_string() const
ByteString FunctionType::to_byte_string() const
{
StringBuilder builder;
builder.append(m_return_type->to_deprecated_string());
builder.append(m_return_type->to_byte_string());
builder.append('(');
bool first = true;
for (auto& parameter : m_parameters) {
@ -125,14 +125,14 @@ DeprecatedString FunctionType::to_deprecated_string() const
else
builder.append(", "sv);
if (parameter->type())
builder.append(parameter->type()->to_deprecated_string());
builder.append(parameter->type()->to_byte_string());
if (parameter->name() && !parameter->full_name().is_empty()) {
builder.append(' ');
builder.append(parameter->full_name());
}
}
builder.append(')');
return builder.to_deprecated_string();
return builder.to_byte_string();
}
void Parameter::dump(FILE* output, size_t indent) const
@ -552,7 +552,7 @@ StringView Name::full_name() const
builder.appendff("{}::", scope->name());
}
}
m_full_name = DeprecatedString::formatted("{}{}", builder.to_deprecated_string(), m_name.is_null() ? ""sv : m_name->name());
m_full_name = ByteString::formatted("{}{}", builder.to_byte_string(), m_name.is_null() ? ""sv : m_name->name());
return *m_full_name;
}
@ -565,10 +565,10 @@ StringView TemplatizedName::full_name() const
name.append(Name::full_name());
name.append('<');
for (auto& type : m_template_arguments) {
name.append(type->to_deprecated_string());
name.append(type->to_byte_string());
}
name.append('>');
m_full_name = name.to_deprecated_string();
m_full_name = name.to_byte_string();
return *m_full_name;
}
@ -587,7 +587,7 @@ void SizedName::dump(FILE* output, size_t indent) const
if (dimension_info.is_empty()) {
dimension_info.append("[]"sv);
}
outln(output, "{}", dimension_info.to_deprecated_string());
outln(output, "{}", dimension_info.to_byte_string());
}
void CppCastExpression::dump(FILE* output, size_t indent) const
@ -670,7 +670,7 @@ StringView Declaration::full_name() const
if (m_name)
m_full_name = m_name->full_name();
else
m_full_name = DeprecatedString::empty();
m_full_name = ByteString::empty();
}
return *m_full_name;

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/RefCounted.h>
#include <AK/StringView.h>
@ -65,7 +65,7 @@ public:
virtual bool is_dummy_node() const { return false; }
protected:
ASTNode(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
ASTNode(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: m_parent(parent)
, m_start(start)
, m_end(end)
@ -88,7 +88,7 @@ public:
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual Vector<NonnullRefPtr<Declaration const>> declarations() const override { return m_declarations; }
TranslationUnit(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
TranslationUnit(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: ASTNode(parent, start, end, filename)
{
}
@ -107,7 +107,7 @@ public:
virtual Vector<NonnullRefPtr<Declaration const>> declarations() const override;
protected:
Statement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Statement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: ASTNode(parent, start, end, filename)
{
}
@ -131,13 +131,13 @@ public:
void set_name(RefPtr<Name const> name) { m_name = move(name); }
protected:
Declaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Declaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
RefPtr<Name const> m_name;
mutable Optional<DeprecatedString> m_full_name;
mutable Optional<ByteString> m_full_name;
};
class InvalidDeclaration : public Declaration {
@ -145,7 +145,7 @@ class InvalidDeclaration : public Declaration {
public:
virtual ~InvalidDeclaration() override = default;
virtual StringView class_name() const override { return "InvalidDeclaration"sv; }
InvalidDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
InvalidDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}
@ -161,7 +161,7 @@ public:
virtual bool is_destructor() const { return false; }
RefPtr<FunctionDefinition const> definition() { return m_definition; }
FunctionDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
FunctionDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}
@ -192,7 +192,7 @@ public:
Type const* type() const { return m_type.ptr(); }
protected:
VariableOrParameterDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
VariableOrParameterDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}
@ -207,7 +207,7 @@ public:
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual bool is_parameter() const override { return true; }
Parameter(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename, RefPtr<Name const> name)
Parameter(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename, RefPtr<Name const> name)
: VariableOrParameterDeclaration(parent, start, end, filename)
{
m_name = name;
@ -227,7 +227,7 @@ public:
virtual bool is_type() const override { return true; }
virtual bool is_templatized() const { return false; }
virtual bool is_named_type() const { return false; }
virtual DeprecatedString to_deprecated_string() const = 0;
virtual ByteString to_byte_string() const = 0;
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
bool is_auto() const { return m_is_auto; }
@ -236,7 +236,7 @@ public:
void set_qualifiers(Vector<StringView>&& qualifiers) { m_qualifiers = move(qualifiers); }
protected:
Type(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Type(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: ASTNode(parent, start, end, filename)
{
}
@ -250,10 +250,10 @@ class NamedType : public Type {
public:
virtual ~NamedType() override = default;
virtual StringView class_name() const override { return "NamedType"sv; }
virtual DeprecatedString to_deprecated_string() const override;
virtual ByteString to_byte_string() const override;
virtual bool is_named_type() const override { return true; }
NamedType(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
NamedType(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Type(parent, start, end, filename)
{
}
@ -270,9 +270,9 @@ public:
virtual ~Pointer() override = default;
virtual StringView class_name() const override { return "Pointer"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual DeprecatedString to_deprecated_string() const override;
virtual ByteString to_byte_string() const override;
Pointer(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Pointer(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Type(parent, start, end, filename)
{
}
@ -289,14 +289,14 @@ public:
virtual ~Reference() override = default;
virtual StringView class_name() const override { return "Reference"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual DeprecatedString to_deprecated_string() const override;
virtual ByteString to_byte_string() const override;
enum class Kind {
Lvalue,
Rvalue,
};
Reference(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename, Kind kind)
Reference(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename, Kind kind)
: Type(parent, start, end, filename)
, m_kind(kind)
{
@ -316,9 +316,9 @@ public:
virtual ~FunctionType() override = default;
virtual StringView class_name() const override { return "FunctionType"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual DeprecatedString to_deprecated_string() const override;
virtual ByteString to_byte_string() const override;
FunctionType(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
FunctionType(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Type(parent, start, end, filename)
{
}
@ -337,7 +337,7 @@ public:
virtual StringView class_name() const override { return "FunctionDefinition"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
FunctionDefinition(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
FunctionDefinition(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: ASTNode(parent, start, end, filename)
{
}
@ -354,7 +354,7 @@ class InvalidStatement : public Statement {
public:
virtual ~InvalidStatement() override = default;
virtual StringView class_name() const override { return "InvalidStatement"sv; }
InvalidStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
InvalidStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -366,7 +366,7 @@ public:
virtual StringView class_name() const override { return "Expression"sv; }
protected:
Expression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Expression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -376,7 +376,7 @@ class InvalidExpression : public Expression {
public:
virtual ~InvalidExpression() override = default;
virtual StringView class_name() const override { return "InvalidExpression"sv; }
InvalidExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
InvalidExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -388,7 +388,7 @@ public:
virtual StringView class_name() const override { return "VariableDeclaration"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
VariableDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
VariableDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: VariableOrParameterDeclaration(parent, start, end, filename)
{
}
@ -408,12 +408,12 @@ public:
virtual StringView class_name() const override { return "Identifier"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
Identifier(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename, StringView name)
Identifier(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename, StringView name)
: Expression(parent, start, end, filename)
, m_name(name)
{
}
Identifier(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Identifier(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Identifier(parent, start, end, filename, {})
{
}
@ -436,7 +436,7 @@ public:
virtual bool is_templatized() const { return false; }
virtual bool is_sized() const { return false; }
Name(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Name(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -451,7 +451,7 @@ public:
private:
RefPtr<Identifier const> m_name;
Vector<NonnullRefPtr<Identifier const>> m_scope;
mutable Optional<DeprecatedString> m_full_name;
mutable Optional<ByteString> m_full_name;
};
class SizedName : public Name {
@ -461,7 +461,7 @@ public:
virtual bool is_sized() const override { return true; }
void dump(FILE* output, size_t indent) const override;
SizedName(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
SizedName(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Name(parent, start, end, filename)
{
}
@ -470,7 +470,7 @@ public:
private:
Vector<StringView> m_dimensions;
mutable Optional<DeprecatedString> m_full_name;
mutable Optional<ByteString> m_full_name;
};
class TemplatizedName : public Name {
@ -480,7 +480,7 @@ public:
virtual bool is_templatized() const override { return true; }
virtual StringView full_name() const override;
TemplatizedName(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
TemplatizedName(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Name(parent, start, end, filename)
{
}
@ -489,7 +489,7 @@ public:
private:
Vector<NonnullRefPtr<Type const>> m_template_arguments;
mutable Optional<DeprecatedString> m_full_name;
mutable Optional<ByteString> m_full_name;
};
class NumericLiteral : public Expression {
@ -498,7 +498,7 @@ public:
virtual StringView class_name() const override { return "NumericLiteral"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
NumericLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename, StringView value)
NumericLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename, StringView value)
: Expression(parent, start, end, filename)
, m_value(value)
{
@ -516,7 +516,7 @@ public:
virtual StringView class_name() const override { return "NullPointerLiteral"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
NullPointerLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
NullPointerLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -528,7 +528,7 @@ public:
virtual StringView class_name() const override { return "BooleanLiteral"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
BooleanLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename, bool value)
BooleanLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename, bool value)
: Expression(parent, start, end, filename)
, m_value(value)
{
@ -562,7 +562,7 @@ enum class BinaryOp {
class BinaryExpression : public Expression {
public:
BinaryExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
BinaryExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -592,7 +592,7 @@ enum class AssignmentOp {
class AssignmentExpression : public Expression {
public:
AssignmentExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
AssignmentExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -616,7 +616,7 @@ private:
class FunctionCall : public Expression {
public:
FunctionCall(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
FunctionCall(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -639,7 +639,7 @@ private:
class StringLiteral final : public Expression {
public:
StringLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
StringLiteral(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -648,11 +648,11 @@ public:
virtual StringView class_name() const override { return "StringLiteral"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
DeprecatedString const& value() const { return m_value; }
void set_value(DeprecatedString value) { m_value = move(value); }
ByteString const& value() const { return m_value; }
void set_value(ByteString value) { m_value = move(value); }
private:
DeprecatedString m_value;
ByteString m_value;
};
class ReturnStatement : public Statement {
@ -660,7 +660,7 @@ public:
virtual ~ReturnStatement() override = default;
virtual StringView class_name() const override { return "ReturnStatement"sv; }
ReturnStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
ReturnStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -680,7 +680,7 @@ public:
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual bool is_enum() const override { return true; }
EnumDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
EnumDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}
@ -717,7 +717,7 @@ public:
Class
};
StructOrClassDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename, StructOrClassDeclaration::Type type)
StructOrClassDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename, StructOrClassDeclaration::Type type)
: Declaration(parent, start, end, filename)
, m_type(type)
{
@ -747,7 +747,7 @@ enum class UnaryOp {
class UnaryExpression : public Expression {
public:
UnaryExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
UnaryExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -766,7 +766,7 @@ private:
class MemberExpression : public Expression {
public:
MemberExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
MemberExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -788,7 +788,7 @@ private:
class ForStatement : public Statement {
public:
ForStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
ForStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -814,7 +814,7 @@ private:
class BlockStatement final : public Statement {
public:
BlockStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
BlockStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -835,7 +835,7 @@ private:
class Comment final : public Statement {
public:
Comment(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Comment(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -846,7 +846,7 @@ public:
class IfStatement : public Statement {
public:
IfStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
IfStatement(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Statement(parent, start, end, filename)
{
}
@ -877,7 +877,7 @@ public:
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual bool is_namespace() const override { return true; }
NamespaceDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
NamespaceDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}
@ -891,7 +891,7 @@ private:
class CppCastExpression : public Expression {
public:
CppCastExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
CppCastExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -912,7 +912,7 @@ private:
class CStyleCastExpression : public Expression {
public:
CStyleCastExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
CStyleCastExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -931,7 +931,7 @@ private:
class SizeofExpression : public Expression {
public:
SizeofExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
SizeofExpression(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -948,7 +948,7 @@ private:
class BracedInitList : public Expression {
public:
BracedInitList(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
BracedInitList(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Expression(parent, start, end, filename)
{
}
@ -965,7 +965,7 @@ private:
class DummyAstNode : public ASTNode {
public:
DummyAstNode(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
DummyAstNode(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: ASTNode(parent, start, end, filename)
{
}
@ -981,7 +981,7 @@ public:
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual bool is_constructor() const override { return true; }
Constructor(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Constructor(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: FunctionDeclaration(parent, start, end, filename)
{
}
@ -994,7 +994,7 @@ public:
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual bool is_destructor() const override { return true; }
Destructor(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
Destructor(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: FunctionDeclaration(parent, start, end, filename)
{
}
@ -1006,7 +1006,7 @@ public:
virtual StringView class_name() const override { return "UsingNamespaceDeclaration"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
UsingNamespaceDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
UsingNamespaceDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}
@ -1018,7 +1018,7 @@ public:
virtual StringView class_name() const override { return "TypedefDeclaration"sv; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
TypedefDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, DeprecatedString const& filename)
TypedefDeclaration(ASTNode const* parent, Optional<Position> start, Optional<Position> end, ByteString const& filename)
: Declaration(parent, start, end, filename)
{
}

View file

@ -5,8 +5,8 @@
*/
#include "Lexer.h"
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/HashTable.h>
#include <AK/StdLibExtras.h>
@ -203,7 +203,7 @@ constexpr StringView s_known_types[] = {
static bool is_keyword(StringView string)
{
static HashTable<DeprecatedString> keywords(array_size(s_known_keywords));
static HashTable<ByteString> keywords(array_size(s_known_keywords));
if (keywords.is_empty()) {
keywords.set_from(s_known_keywords);
}
@ -212,7 +212,7 @@ static bool is_keyword(StringView string)
static bool is_known_type(StringView string)
{
static HashTable<DeprecatedString> types(array_size(s_known_types));
static HashTable<ByteString> types(array_size(s_known_types));
if (types.is_empty()) {
types.set_from(s_known_types);
}

View file

@ -11,18 +11,18 @@
#include <AK/ScopeLogger.h>
#include <LibCpp/Lexer.h>
#define LOG_SCOPE() ScopeLogger<CPP_DEBUG> logger(DeprecatedString::formatted("'{}' - {} ({})", peek().text(), peek().type_as_deprecated_string(), m_state.token_index))
#define LOG_SCOPE() ScopeLogger<CPP_DEBUG> logger(ByteString::formatted("'{}' - {} ({})", peek().text(), peek().type_as_byte_string(), m_state.token_index))
namespace Cpp {
Parser::Parser(Vector<Token> tokens, DeprecatedString const& filename)
Parser::Parser(Vector<Token> tokens, ByteString const& filename)
: m_filename(filename)
, m_tokens(move(tokens))
{
if constexpr (CPP_DEBUG) {
dbgln("Tokens:");
for (size_t i = 0; i < m_tokens.size(); ++i) {
dbgln("{}- {}", i, m_tokens[i].to_deprecated_string());
dbgln("{}- {}", i, m_tokens[i].to_byte_string());
}
}
}
@ -598,7 +598,7 @@ NonnullRefPtr<Expression const> Parser::parse_secondary_expression(ASTNode const
return func;
}
default: {
error(DeprecatedString::formatted("unexpected operator for expression. operator: {}", peek().to_deprecated_string()));
error(ByteString::formatted("unexpected operator for expression. operator: {}", peek().to_byte_string()));
auto token = consume();
return create_ast_node<InvalidExpression>(parent, token.start(), token.end());
}
@ -845,7 +845,7 @@ Token Parser::consume(Token::Type type)
{
auto token = consume();
if (token.type() != type)
error(DeprecatedString::formatted("expected {} at {}:{}, found: {}", Token::type_to_string(type), token.start().line, token.start().column, Token::type_to_string(token.type())));
error(ByteString::formatted("expected {} at {}:{}, found: {}", Token::type_to_string(type), token.start().line, token.start().column, Token::type_to_string(token.type())));
return token;
}
@ -894,18 +894,18 @@ StringView Parser::text_of_token(Cpp::Token const& token) const
return token.text();
}
DeprecatedString Parser::text_of_node(ASTNode const& node) const
ByteString Parser::text_of_node(ASTNode const& node) const
{
return text_in_range(node.start(), node.end());
}
DeprecatedString Parser::text_in_range(Position start, Position end) const
ByteString Parser::text_in_range(Position start, Position end) const
{
StringBuilder builder;
for (auto token : tokens_in_range(start, end)) {
builder.append(token.text());
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
Vector<Token> Parser::tokens_in_range(Position start, Position end) const
@ -931,11 +931,11 @@ void Parser::error(StringView message)
if (message.is_null() || message.is_empty())
message = "<empty>"sv;
DeprecatedString formatted_message;
ByteString formatted_message;
if (m_state.token_index >= m_tokens.size()) {
formatted_message = DeprecatedString::formatted("C++ Parsed error on EOF.{}", message);
formatted_message = ByteString::formatted("C++ Parsed error on EOF.{}", message);
} else {
formatted_message = DeprecatedString::formatted("C++ Parser error: {}. token: {} ({}:{})",
formatted_message = ByteString::formatted("C++ Parser error: {}. token: {} ({}:{})",
message,
m_state.token_index < m_tokens.size() ? text_of_token(m_tokens[m_state.token_index]) : "EOF"sv,
m_tokens[m_state.token_index].start().line,
@ -1033,7 +1033,7 @@ Optional<size_t> Parser::index_of_token_at(Position pos) const
void Parser::print_tokens() const
{
for (auto& token : m_tokens) {
outln("{}", token.to_deprecated_string());
outln("{}", token.to_byte_string());
}
}
@ -1131,21 +1131,21 @@ NonnullRefPtr<EnumDeclaration const> Parser::parse_enum_declaration(ASTNode cons
return enum_decl;
}
Token Parser::consume_keyword(DeprecatedString const& keyword)
Token Parser::consume_keyword(ByteString const& keyword)
{
auto token = consume();
if (token.type() != Token::Type::Keyword) {
error(DeprecatedString::formatted("unexpected token: {}, expected Keyword", token.to_deprecated_string()));
error(ByteString::formatted("unexpected token: {}, expected Keyword", token.to_byte_string()));
return token;
}
if (text_of_token(token) != keyword) {
error(DeprecatedString::formatted("unexpected keyword: {}, expected {}", text_of_token(token), keyword));
error(ByteString::formatted("unexpected keyword: {}, expected {}", text_of_token(token), keyword));
return token;
}
return token;
}
bool Parser::match_keyword(DeprecatedString const& keyword)
bool Parser::match_keyword(ByteString const& keyword)
{
auto token = peek();
if (token.type() != Token::Type::Keyword) {
@ -1257,7 +1257,7 @@ NonnullRefPtr<Type const> Parser::parse_type(ASTNode const& parent)
if (!match_name()) {
named_type->set_end(position());
error(DeprecatedString::formatted("expected name instead of: {}", peek().text()));
error(ByteString::formatted("expected name instead of: {}", peek().text()));
return named_type;
}
named_type->set_name(parse_name(*named_type));

View file

@ -19,7 +19,7 @@ class Parser final {
AK_MAKE_NONCOPYABLE(Parser);
public:
explicit Parser(Vector<Token> tokens, DeprecatedString const& filename);
explicit Parser(Vector<Token> tokens, ByteString const& filename);
~Parser() = default;
NonnullRefPtr<TranslationUnit> parse();
@ -30,11 +30,11 @@ public:
Optional<Token> token_at(Position) const;
Optional<size_t> index_of_token_at(Position) const;
RefPtr<TranslationUnit const> root_node() const { return m_root_node; }
DeprecatedString text_of_node(ASTNode const&) const;
ByteString text_of_node(ASTNode const&) const;
StringView text_of_token(Cpp::Token const& token) const;
void print_tokens() const;
Vector<Token> const& tokens() const { return m_tokens; }
Vector<DeprecatedString> const& errors() const { return m_errors; }
Vector<ByteString> const& errors() const { return m_errors; }
Vector<CodeComprehension::TodoEntry> get_todo_entries() const;
@ -69,7 +69,7 @@ private:
bool match_literal();
bool match_unary_expression();
bool match_boolean_literal();
bool match_keyword(DeprecatedString const&);
bool match_keyword(ByteString const&);
bool match_block_statement();
bool match_namespace_declaration();
bool match_template_arguments();
@ -132,12 +132,12 @@ private:
bool match(Token::Type);
Token consume(Token::Type);
Token consume();
Token consume_keyword(DeprecatedString const&);
Token consume_keyword(ByteString const&);
Token peek(size_t offset = 0) const;
Optional<Token> peek(Token::Type) const;
Position position() const;
Position previous_token_end() const;
DeprecatedString text_in_range(Position start, Position end) const;
ByteString text_in_range(Position start, Position end) const;
void save_state();
void load_state();
@ -192,12 +192,12 @@ private:
};
void parse_constructor_or_destructor_impl(FunctionDeclaration&, CtorOrDtor);
DeprecatedString m_filename;
ByteString m_filename;
Vector<Token> m_tokens;
State m_state;
Vector<State> m_saved_states;
RefPtr<TranslationUnit> m_root_node;
Vector<DeprecatedString> m_errors;
Vector<ByteString> m_errors;
Vector<NonnullRefPtr<ASTNode>> m_nodes;
};

View file

@ -12,7 +12,7 @@
#include <ctype.h>
namespace Cpp {
Preprocessor::Preprocessor(DeprecatedString const& filename, StringView program)
Preprocessor::Preprocessor(ByteString const& filename, StringView program)
: m_filename(filename)
, m_program(program)
{
@ -369,7 +369,7 @@ Optional<Preprocessor::Definition> Preprocessor::create_definition(StringView li
return definition;
}
DeprecatedString Preprocessor::remove_escaped_newlines(StringView value)
ByteString Preprocessor::remove_escaped_newlines(StringView value)
{
static constexpr auto escaped_newline = "\\\n"sv;
AK::StringBuilder processed_value;
@ -378,10 +378,10 @@ DeprecatedString Preprocessor::remove_escaped_newlines(StringView value)
processed_value.append(lexer.consume_until(escaped_newline));
lexer.ignore(escaped_newline.length());
}
return processed_value.to_deprecated_string();
return processed_value.to_byte_string();
}
DeprecatedString Preprocessor::evaluate_macro_call(MacroCall const& macro_call, Definition const& definition)
ByteString Preprocessor::evaluate_macro_call(MacroCall const& macro_call, Definition const& definition)
{
if (macro_call.arguments.size() != definition.parameters.size()) {
dbgln("mismatch in # of arguments for macro call: {}", macro_call.name.text());
@ -408,7 +408,7 @@ DeprecatedString Preprocessor::evaluate_macro_call(MacroCall const& macro_call,
}
});
return processed_value.to_deprecated_string();
return processed_value.to_byte_string();
}
};

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/Optional.h>
@ -20,24 +20,24 @@ namespace Cpp {
class Preprocessor {
public:
explicit Preprocessor(DeprecatedString const& filename, StringView program);
explicit Preprocessor(ByteString const& filename, StringView program);
Vector<Token> process_and_lex();
Vector<StringView> included_paths() const { return m_included_paths; }
struct Definition {
DeprecatedString key;
Vector<DeprecatedString> parameters;
DeprecatedString value;
ByteString key;
Vector<ByteString> parameters;
ByteString value;
DeprecatedFlyString filename;
size_t line { 0 };
size_t column { 0 };
};
using Definitions = HashMap<DeprecatedString, Definition>;
using Definitions = HashMap<ByteString, Definition>;
struct Substitution {
Vector<Token> original_tokens;
Definition defined_value;
DeprecatedString processed_value;
ByteString processed_value;
};
Definitions const& definitions() const { return m_definitions; }
@ -55,7 +55,7 @@ private:
void handle_preprocessor_statement(StringView);
void handle_include_statement(StringView);
void handle_preprocessor_keyword(StringView keyword, GenericLexer& line_lexer);
DeprecatedString remove_escaped_newlines(StringView value);
ByteString remove_escaped_newlines(StringView value);
size_t do_substitution(Vector<Token> const& tokens, size_t token_index, Definition const&);
Optional<Definition> create_definition(StringView line);
@ -69,10 +69,10 @@ private:
size_t end_token_index { 0 };
};
Optional<MacroCall> parse_macro_call(Vector<Token> const& tokens, size_t token_index);
DeprecatedString evaluate_macro_call(MacroCall const&, Definition const&);
ByteString evaluate_macro_call(MacroCall const&, Definition const&);
DeprecatedString m_filename;
DeprecatedString m_program;
ByteString m_filename;
ByteString m_program;
Vector<Token> m_unprocessed_tokens;
Vector<Token> m_processed_tokens;

View file

@ -45,13 +45,13 @@ void SemanticSyntaxHighlighter::rehighlight(Palette const& palette)
StringBuilder previous_tokens_as_lines;
for (auto& token : current_tokens)
current_tokens_as_lines.appendff("{}\n", token.type_as_deprecated_string());
current_tokens_as_lines.appendff("{}\n", token.type_as_byte_string());
for (Cpp::Token const& token : m_saved_tokens)
previous_tokens_as_lines.appendff("{}\n", token.type_as_deprecated_string());
previous_tokens_as_lines.appendff("{}\n", token.type_as_byte_string());
auto previous = previous_tokens_as_lines.to_deprecated_string();
auto current = current_tokens_as_lines.to_deprecated_string();
auto previous = previous_tokens_as_lines.to_byte_string();
auto current = current_tokens_as_lines.to_byte_string();
// FIXME: Computing the diff on the entire document's tokens is quite inefficient.
// An improvement over this could be only including the tokens that are in edited text ranges in the diff.

Some files were not shown because too many files have changed in this diff Show more