mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
5e1499d104
This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/LexicalPath.h>
|
|
#include <AK/StringView.h>
|
|
#include <LibCore/DirIterator.h>
|
|
#include <LibCore/Resource.h>
|
|
#include <LibCore/ResourceImplementationFile.h>
|
|
|
|
namespace Core {
|
|
|
|
ResourceImplementationFile::ResourceImplementationFile(String base_directory)
|
|
: m_base_directory(move(base_directory))
|
|
{
|
|
}
|
|
|
|
ErrorOr<NonnullRefPtr<Resource>> ResourceImplementationFile::load_from_resource_scheme_uri(StringView uri)
|
|
{
|
|
StringView const resource_scheme = "resource://"sv;
|
|
|
|
VERIFY(uri.starts_with(resource_scheme));
|
|
|
|
auto path = TRY(String::from_utf8(uri.substring_view(resource_scheme.length())));
|
|
auto full_path = TRY(String::from_byte_string(LexicalPath::join(m_base_directory, path).string()));
|
|
if (is_directory(full_path))
|
|
return make_directory_resource(move(path));
|
|
|
|
return make_resource(path, TRY(MappedFile::map(full_path)));
|
|
}
|
|
|
|
Vector<String> ResourceImplementationFile::child_names_for_resource_scheme(Resource const& resource)
|
|
{
|
|
Vector<String> children;
|
|
Core::DirIterator it(resource.filesystem_path().to_byte_string(), Core::DirIterator::SkipParentAndBaseDir);
|
|
while (it.has_next())
|
|
children.append(MUST(String::from_byte_string(it.next_path())));
|
|
|
|
return children;
|
|
}
|
|
|
|
String ResourceImplementationFile::filesystem_path_for_resource_scheme(String const& relative_path)
|
|
{
|
|
return MUST(String::from_byte_string(LexicalPath::join(m_base_directory, relative_path).string()));
|
|
}
|
|
|
|
}
|