1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

AK: Use an enum instead of a bool for String::replace(all_occurences)

This commit has no behavior changes.

In particular, this does not fix any of the wrong uses of the previous
default parameter (which used to be 'false', meaning "only replace the
first occurence in the string"). It simply replaces the default uses by
String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
This commit is contained in:
DexesTTP 2022-07-05 22:33:15 +02:00 committed by Linus Groh
parent b2454888e8
commit 7ceeb74535
47 changed files with 108 additions and 102 deletions

View file

@ -105,7 +105,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (pager)
pager_command = pager;
else
pager_command = String::formatted("less -P 'Manual Page {}({}) line %l?e (END):.'", StringView(name).replace("'", "'\\''"), StringView(section).replace("'", "'\\''"));
pager_command = String::formatted("less -P 'Manual Page {}({}) line %l?e (END):.'", StringView(name).replace("'", "'\\''", ReplaceMode::FirstOnly), StringView(section).replace("'", "'\\''", ReplaceMode::FirstOnly));
pid_t pager_pid = TRY(pipe_to_pager(pager_command));
auto file = TRY(Core::File::open(filename, Core::OpenMode::ReadOnly));

View file

@ -143,24 +143,24 @@ static String slugify(String const& text)
String slug = text.to_lowercase();
// Reverse-engineered through github, using:
// find AK/ Base/ Documentation/ Kernel/ Meta/ Ports/ Tests/ Userland/ -name '*.md' | xargs grep --color=always -Pin '^##+ .*[^a-z0-9 ?()`_:/!&|.$'"'"',<>"+-]' README.md
slug = slug.replace(" ", "-", true)
.replace("!", "", true)
.replace("?", "", true)
.replace("(", "", true)
.replace(")", "", true)
.replace(":", "", true)
.replace("/", "-", true)
.replace("&", "", true)
.replace("|", "", true)
.replace(".", "", true)
.replace("$", "", true)
.replace("'", "", true)
.replace(",", "", true)
.replace("\"", "", true)
.replace("+", "", true)
.replace("\\", "", true)
.replace("<", "", true)
.replace(">", "", true);
slug = slug.replace(" ", "-", ReplaceMode::All)
.replace("!", "", ReplaceMode::All)
.replace("?", "", ReplaceMode::All)
.replace("(", "", ReplaceMode::All)
.replace(")", "", ReplaceMode::All)
.replace(":", "", ReplaceMode::All)
.replace("/", "-", ReplaceMode::All)
.replace("&", "", ReplaceMode::All)
.replace("|", "", ReplaceMode::All)
.replace(".", "", ReplaceMode::All)
.replace("$", "", ReplaceMode::All)
.replace("'", "", ReplaceMode::All)
.replace(",", "", ReplaceMode::All)
.replace("\"", "", ReplaceMode::All)
.replace("+", "", ReplaceMode::All)
.replace("\\", "", ReplaceMode::All)
.replace("<", "", ReplaceMode::All)
.replace(">", "", ReplaceMode::All);
// What about "="?
return slug;
}

View file

@ -122,7 +122,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!file_filters.is_empty()) {
for (auto& filter : file_filters) {
// Convert underscore wildcards (usual unzip convention) to question marks (as used by StringUtils)
auto string_filter = filter.replace("_", "?", true);
auto string_filter = filter.replace("_", "?", ReplaceMode::All);
if (zip_member.name.matches(string_filter, CaseSensitivity::CaseSensitive)) {
keep_file = true;
break;

View file

@ -18,7 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
auto cpp_full_path = parser_tests.next_full_path();
if (!cpp_full_path.ends_with(".cpp"))
continue;
auto ast_full_path = cpp_full_path.replace(".cpp", ".ast");
auto ast_full_path = cpp_full_path.replace(".cpp", ".ast", ReplaceMode::FirstOnly);
outln("{}", cpp_full_path);
auto res = Core::command("/bin/sh", { "-c", String::formatted("cpp-parser {} > {}", cpp_full_path, ast_full_path) }, {});
VERIFY(!res.is_error());
@ -29,7 +29,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
auto cpp_full_path = preprocessor_tests.next_full_path();
if (!cpp_full_path.ends_with(".cpp"))
continue;
auto ast_full_path = cpp_full_path.replace(".cpp", ".txt");
auto ast_full_path = cpp_full_path.replace(".cpp", ".txt", ReplaceMode::FirstOnly);
outln("{}", cpp_full_path);
auto res = Core::command("/bin/sh", { "-c", String::formatted("cpp-preprocessor {} > {}", cpp_full_path, ast_full_path) }, {});
VERIFY(!res.is_error());