mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
AK: Add StringView(String const&) constructor
This allows us to pass the new String type to functions that take a StringView directly, having to call bytes_as_string_view() every time gets old quickly.
This commit is contained in:
parent
daec065fde
commit
f23b55ae86
Notes:
sideshowbarker
2024-07-17 03:42:10 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/f23b55ae86 Pull-request: https://github.com/SerenityOS/serenity/pull/16341 Reviewed-by: https://github.com/davidot ✅
2 changed files with 9 additions and 0 deletions
|
@ -16,11 +16,18 @@
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/DeprecatedString.h>
|
||||||
# include <AK/FlyString.h>
|
# include <AK/FlyString.h>
|
||||||
|
# include <AK/String.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
|
StringView::StringView(String const& string)
|
||||||
|
: m_characters(reinterpret_cast<char const*>(string.bytes().data()))
|
||||||
|
, m_length(string.bytes().size())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
StringView::StringView(DeprecatedString const& string)
|
StringView::StringView(DeprecatedString const& string)
|
||||||
: m_characters(string.characters())
|
: m_characters(string.characters())
|
||||||
, m_length(string.length())
|
, m_length(string.length())
|
||||||
|
|
|
@ -42,12 +42,14 @@ public:
|
||||||
|
|
||||||
StringView(ByteBuffer const&);
|
StringView(ByteBuffer const&);
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
|
StringView(String const&);
|
||||||
StringView(DeprecatedString const&);
|
StringView(DeprecatedString const&);
|
||||||
StringView(FlyString const&);
|
StringView(FlyString const&);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
explicit StringView(ByteBuffer&&) = delete;
|
explicit StringView(ByteBuffer&&) = delete;
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
|
explicit StringView(String&&) = delete;
|
||||||
explicit StringView(DeprecatedString&&) = delete;
|
explicit StringView(DeprecatedString&&) = delete;
|
||||||
explicit StringView(FlyString&&) = delete;
|
explicit StringView(FlyString&&) = delete;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue