mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
cksum: Stop using DeprecatedString
This has the side-effect of making the algorithm name case-sensitive, but there doesn't seem to be an especially good reason to support that. On the other hand, converting an AK::String to lowercase would require linking LibUnicode.
This commit is contained in:
parent
2db4a2450b
commit
739e657ad0
Notes:
sideshowbarker
2024-07-17 14:36:19 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/739e657ad0 Pull-request: https://github.com/SerenityOS/serenity/pull/17793 Reviewed-by: https://github.com/krkk Reviewed-by: https://github.com/trflynn89
1 changed files with 8 additions and 8 deletions
|
@ -4,9 +4,9 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibCrypto/Checksum/Adler32.h>
|
||||
#include <LibCrypto/Checksum/CRC32.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
@ -14,7 +14,7 @@
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
Vector<DeprecatedString> paths;
|
||||
Vector<StringView> paths;
|
||||
StringView opt_algorithm;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
|
@ -22,9 +22,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_positional_argument(paths, "File", "file", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto algorithm = opt_algorithm.is_empty() ? "crc32" : DeprecatedString(opt_algorithm).to_lowercase();
|
||||
auto algorithm = opt_algorithm.is_empty() ? "crc32"sv : opt_algorithm;
|
||||
|
||||
auto available_algorithms = Vector<DeprecatedString> { "crc32", "adler32" };
|
||||
auto available_algorithms = Vector<StringView> { "crc32"sv, "adler32"sv };
|
||||
|
||||
if (algorithm == "list") {
|
||||
outln("Available algorithms:");
|
||||
|
@ -40,14 +40,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
if (paths.is_empty())
|
||||
paths.append("-");
|
||||
paths.append("-"sv);
|
||||
|
||||
bool fail = false;
|
||||
Array<u8, PAGE_SIZE> buffer;
|
||||
|
||||
for (auto& path : paths) {
|
||||
auto file_or_error = Core::File::open_file_or_standard_stream(path, Core::File::OpenMode::Read);
|
||||
auto filepath = (path == "-") ? "/dev/stdin" : path;
|
||||
auto filepath = (path == "-"sv) ? "/dev/stdin"sv : path;
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("{}: {}: {}", arguments.strings[0], filepath, file_or_error.error());
|
||||
fail = true;
|
||||
|
@ -56,7 +56,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto file = file_or_error.release_value();
|
||||
size_t file_size = 0;
|
||||
|
||||
if (algorithm == "crc32") {
|
||||
if (algorithm == "crc32"sv) {
|
||||
Crypto::Checksum::CRC32 crc32;
|
||||
while (!file->is_eof()) {
|
||||
auto data_or_error = file->read_some(buffer);
|
||||
|
@ -69,7 +69,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
crc32.update(data_or_error.value());
|
||||
}
|
||||
outln("{:08x} {} {}", crc32.digest(), file_size, path);
|
||||
} else if (algorithm == "adler32") {
|
||||
} else if (algorithm == "adler32"sv) {
|
||||
Crypto::Checksum::Adler32 adler32;
|
||||
while (!file->is_eof()) {
|
||||
auto data_or_error = file->read_some(buffer);
|
||||
|
|
Loading…
Reference in a new issue