mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
AK: Change the signature of AK::encode_base64() to use Span.
This commit is contained in:
parent
5fa0fdb219
commit
abe925e4b0
5 changed files with 7 additions and 6 deletions
|
@ -86,7 +86,7 @@ ByteBuffer decode_base64(const StringView& input)
|
||||||
return ByteBuffer::copy(output.data(), output.size());
|
return ByteBuffer::copy(output.data(), output.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
String encode_base64(const ByteBuffer& input)
|
String encode_base64(ReadonlyBytes input)
|
||||||
{
|
{
|
||||||
StringBuilder output;
|
StringBuilder output;
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
|
#include <AK/Span.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
ByteBuffer decode_base64(const StringView&);
|
ByteBuffer decode_base64(const StringView&);
|
||||||
|
|
||||||
String encode_base64(const ByteBuffer&);
|
String encode_base64(ReadonlyBytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ TEST_CASE(test_decode)
|
||||||
TEST_CASE(test_encode)
|
TEST_CASE(test_encode)
|
||||||
{
|
{
|
||||||
auto encode_equal = [&](const char* input, const char* expected) {
|
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));
|
EXPECT(encoded == String(expected));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/FlyString.h>
|
#include <AK/FlyString.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/Utf8View.h>
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
#include <AK/Utf8View.h>
|
||||||
#include <LibJS/Interpreter.h>
|
#include <LibJS/Interpreter.h>
|
||||||
#include <LibJS/Runtime/Error.h>
|
#include <LibJS/Runtime/Error.h>
|
||||||
#include <LibJS/Runtime/Function.h>
|
#include <LibJS/Runtime/Function.h>
|
||||||
|
@ -278,7 +278,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
||||||
byte_string.append(codepoint);
|
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));
|
return JS::js_string(interpreter, move(encoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,6 @@ int main(int argc, char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encoded = encode_base64(buffer);
|
auto encoded = encode_base64(buffer.span());
|
||||||
printf("%s\n", encoded.characters());
|
printf("%s\n", encoded.characters());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue