mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +00:00
AK+Everywhere: Turn bool keep_empty to an enum in split* functions
This commit is contained in:
parent
f485db2501
commit
3e8b5ac920
44 changed files with 96 additions and 81 deletions
|
@ -138,7 +138,7 @@ int OptionParser::getopt()
|
|||
|
||||
bool OptionParser::lookup_short_option(char option, int& needs_value) const
|
||||
{
|
||||
Vector<StringView> parts = m_short_options.split_view(option, true);
|
||||
Vector<StringView> parts = m_short_options.split_view(option, SplitBehavior::KeepEmpty);
|
||||
|
||||
VERIFY(parts.size() <= 2);
|
||||
if (parts.size() < 2) {
|
||||
|
|
|
@ -73,7 +73,7 @@ struct group* getgrnam(char const* name)
|
|||
|
||||
static bool parse_grpdb_entry(String const& line)
|
||||
{
|
||||
auto parts = line.split_view(':', true);
|
||||
auto parts = line.split_view(':', SplitBehavior::KeepEmpty);
|
||||
if (parts.size() != 4) {
|
||||
warnln("getgrent(): Malformed entry on line {}: '{}' has {} parts", s_line_number, line, parts.size());
|
||||
return false;
|
||||
|
|
|
@ -73,7 +73,7 @@ struct passwd* getpwnam(char const* name)
|
|||
|
||||
static bool parse_pwddb_entry(String const& line)
|
||||
{
|
||||
auto parts = line.split_view(':', true);
|
||||
auto parts = line.split_view(':', SplitBehavior::KeepEmpty);
|
||||
if (parts.size() != 7) {
|
||||
dbgln("getpwent(): Malformed entry on line {}", s_line_number);
|
||||
return false;
|
||||
|
|
|
@ -64,7 +64,7 @@ struct spwd* getspnam(char const* name)
|
|||
|
||||
static bool parse_shadow_entry(String const& line)
|
||||
{
|
||||
auto parts = line.split_view(':', true);
|
||||
auto parts = line.split_view(':', SplitBehavior::KeepEmpty);
|
||||
if (parts.size() != 9) {
|
||||
dbgln("getspent(): Malformed entry on line {}", s_line_number);
|
||||
return false;
|
||||
|
|
|
@ -117,7 +117,7 @@ size_t ShellComprehensionEngine::resolve(ShellComprehensionEngine::DocumentData
|
|||
if (position.line() > 0) {
|
||||
auto first = true;
|
||||
size_t line = 0;
|
||||
for (auto& line_view : document.text.split_limit('\n', position.line() + 1, true)) {
|
||||
for (auto& line_view : document.text.split_limit('\n', position.line() + 1, SplitBehavior::KeepEmpty)) {
|
||||
if (line == position.line())
|
||||
break;
|
||||
if (first)
|
||||
|
|
|
@ -554,7 +554,7 @@ void ArgsParser::add_option(Vector<size_t>& values, char const* help_string, cha
|
|||
[&values, separator](char const* s) {
|
||||
bool parsed_all_values = true;
|
||||
|
||||
StringView { s, strlen(s) }.for_each_split_view(separator, false, [&](auto value) {
|
||||
StringView { s, strlen(s) }.for_each_split_view(separator, SplitBehavior::Nothing, [&](auto value) {
|
||||
if (auto maybe_value = AK::StringUtils::convert_to_uint<size_t>(value); maybe_value.has_value())
|
||||
values.append(*maybe_value);
|
||||
else
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Diff {
|
||||
String generate_only_additions(String const& text)
|
||||
{
|
||||
auto lines = text.split('\n', true); // Keep empty
|
||||
auto lines = text.split('\n', SplitBehavior::KeepEmpty);
|
||||
StringBuilder builder;
|
||||
builder.appendff("@@ -0,0 +1,{} @@\n", lines.size());
|
||||
for (auto const& line : lines) {
|
||||
|
|
|
@ -179,7 +179,7 @@ auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
|||
StringBuilder builder;
|
||||
Vector<u32> code_points;
|
||||
|
||||
basename.for_each_split_view('_', false, [&](auto segment) {
|
||||
basename.for_each_split_view('_', SplitBehavior::Nothing, [&](auto segment) {
|
||||
auto code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segment.substring_view(2));
|
||||
VERIFY(code_point.has_value());
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ Optional<HttpRequest> HttpRequest::from_raw_request(ReadonlyBytes raw_request)
|
|||
return {};
|
||||
|
||||
request.m_headers = move(headers);
|
||||
auto url_parts = resource.split_limit('?', 2, true);
|
||||
auto url_parts = resource.split_limit('?', 2, SplitBehavior::KeepEmpty);
|
||||
|
||||
request.m_url.set_cannot_be_a_base_url(true);
|
||||
if (url_parts.size() == 2) {
|
||||
|
|
|
@ -453,7 +453,7 @@ void Job::on_socket_connected()
|
|||
finish_up();
|
||||
break;
|
||||
} else {
|
||||
auto chunk = size_lines[0].split_view(';', true);
|
||||
auto chunk = size_lines[0].split_view(';', SplitBehavior::KeepEmpty);
|
||||
String size_string = chunk[0];
|
||||
char* endptr;
|
||||
auto size = strtoul(size_string.characters(), &endptr, 16);
|
||||
|
|
|
@ -192,7 +192,7 @@ public:
|
|||
// line terminators to \n is easier than splitting using all different LT characters.
|
||||
String source_string = source.replace("\r\n"sv, "\n"sv, ReplaceMode::All).replace("\r"sv, "\n"sv, ReplaceMode::All).replace(LINE_SEPARATOR_STRING, "\n"sv, ReplaceMode::All).replace(PARAGRAPH_SEPARATOR_STRING, "\n"sv, ReplaceMode::All);
|
||||
StringBuilder builder;
|
||||
builder.append(source_string.split_view('\n', true)[position.value().line - 1]);
|
||||
builder.append(source_string.split_view('\n', SplitBehavior::KeepEmpty)[position.value().line - 1]);
|
||||
builder.append('\n');
|
||||
for (size_t i = 0; i < position.value().column - 1; ++i)
|
||||
builder.append(spacer);
|
||||
|
|
|
@ -965,7 +965,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
|
|||
|
||||
// 19. Repeat, while q < size,
|
||||
while (next_search_from < string.length_in_code_units()) {
|
||||
// a. Perform ? Set(splitter, "lastIndex", 𝔽(q), true).
|
||||
// a. Perform ? Set(splitter, "lastIndex", 𝔽(q), SplitBehavior::KeepEmpty).
|
||||
TRY(splitter->set(vm.names.lastIndex, Value(next_search_from), Object::ShouldThrowExceptions::Yes));
|
||||
|
||||
// b. Let z be ? RegExpExec(splitter, S).
|
||||
|
|
|
@ -138,8 +138,8 @@ OwnPtr<Table> Table::parse(LineIterator& lines)
|
|||
if (peek_it.is_end())
|
||||
return {};
|
||||
|
||||
auto header_segments = first_line.split_view('|', true);
|
||||
auto header_delimiters = peek_it->split_view('|', true);
|
||||
auto header_segments = first_line.split_view('|', SplitBehavior::KeepEmpty);
|
||||
auto header_delimiters = peek_it->split_view('|', SplitBehavior::KeepEmpty);
|
||||
|
||||
if (!header_segments.is_empty())
|
||||
header_segments.take_first();
|
||||
|
@ -214,7 +214,7 @@ OwnPtr<Table> Table::parse(LineIterator& lines)
|
|||
|
||||
++lines;
|
||||
|
||||
auto segments = line.split_view('|', true);
|
||||
auto segments = line.split_view('|', SplitBehavior::KeepEmpty);
|
||||
segments.take_first();
|
||||
if (!segments.is_empty() && segments.last().is_empty())
|
||||
segments.take_last();
|
||||
|
|
|
@ -522,7 +522,7 @@ inline void TestRunner::print_file_result(JSFileResult const& file_result) const
|
|||
#endif
|
||||
outln();
|
||||
print_modifiers({ FG_GRAY });
|
||||
for (auto& message : test_error.hint.split('\n', true)) {
|
||||
for (auto& message : test_error.hint.split('\n', SplitBehavior::KeepEmpty)) {
|
||||
outln(" {}", message);
|
||||
}
|
||||
print_modifiers({ FG_RED });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue