summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-07-27 14:16:33 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-27 19:58:09 +0200
commitabe925e4b08fca8eaac4d3e63508cbb9ff5c1733 (patch)
treedfd4e9bcc2edb1ced4542df0727dad39ae1f85e5
parent5fa0fdb2192cea73fb9e19c720693d91ef944101 (diff)
downloadserenity-abe925e4b08fca8eaac4d3e63508cbb9ff5c1733.zip
AK: Change the signature of AK::encode_base64() to use Span.
-rw-r--r--AK/Base64.cpp2
-rw-r--r--AK/Base64.h3
-rw-r--r--AK/Tests/TestBase64.cpp2
-rw-r--r--Libraries/LibWeb/Bindings/WindowObject.cpp4
-rw-r--r--Userland/base64.cpp2
5 files changed, 7 insertions, 6 deletions
diff --git a/AK/Base64.cpp b/AK/Base64.cpp
index 91e067c2a0..950407e26b 100644
--- a/AK/Base64.cpp
+++ b/AK/Base64.cpp
@@ -86,7 +86,7 @@ ByteBuffer decode_base64(const StringView& input)
return ByteBuffer::copy(output.data(), output.size());
}
-String encode_base64(const ByteBuffer& input)
+String encode_base64(ReadonlyBytes input)
{
StringBuilder output;
diff --git a/AK/Base64.h b/AK/Base64.h
index dc3b9c4975..758e78547d 100644
--- a/AK/Base64.h
+++ b/AK/Base64.h
@@ -27,12 +27,13 @@
#pragma once
#include <AK/Forward.h>
+#include <AK/Span.h>
namespace AK {
ByteBuffer decode_base64(const StringView&);
-String encode_base64(const ByteBuffer&);
+String encode_base64(ReadonlyBytes);
}
diff --git a/AK/Tests/TestBase64.cpp b/AK/Tests/TestBase64.cpp
index 9e65c03a83..5b19bcd544 100644
--- a/AK/Tests/TestBase64.cpp
+++ b/AK/Tests/TestBase64.cpp
@@ -49,7 +49,7 @@ TEST_CASE(test_decode)
TEST_CASE(test_encode)
{
auto encode_equal = [&](const char* input, const char* expected) {
- auto encoded = encode_base64(ByteBuffer::wrap(input, strlen(input)));
+ auto encoded = encode_base64({ input, strlen(input) });
EXPECT(encoded == String(expected));
};
diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp
index 6e604ec2f1..de382cf9ba 100644
--- a/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -28,8 +28,8 @@
#include <AK/ByteBuffer.h>
#include <AK/FlyString.h>
#include <AK/Function.h>
-#include <AK/Utf8View.h>
#include <AK/String.h>
+#include <AK/Utf8View.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/Function.h>
@@ -278,7 +278,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
byte_string.append(codepoint);
}
- auto encoded = encode_base64(ByteBuffer::wrap(byte_string.data(), byte_string.size()));
+ auto encoded = encode_base64(byte_string.span());
return JS::js_string(interpreter, move(encoded));
}
diff --git a/Userland/base64.cpp b/Userland/base64.cpp
index 0af7a684a4..a91275a0c8 100644
--- a/Userland/base64.cpp
+++ b/Userland/base64.cpp
@@ -75,6 +75,6 @@ int main(int argc, char** argv)
return 0;
}
- auto encoded = encode_base64(buffer);
+ auto encoded = encode_base64(buffer.span());
printf("%s\n", encoded.characters());
}