diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-20 14:13:40 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-20 14:13:40 +0200 |
commit | ab94a6be00ecd48575653e5d0ab3b2f21d131836 (patch) | |
tree | 8ded9c664c65a51f4a6c5f2fbf008facba67abf6 /AK/AKString.h | |
parent | 5eedb2283488fafef98c20729bc6917c6de957e5 (diff) | |
download | serenity-ab94a6be00ecd48575653e5d0ab3b2f21d131836.zip |
AK: Add String::copy(BufferType) helper.
This will create a String from any BufferType that has data() and size().
Diffstat (limited to 'AK/AKString.h')
-rw-r--r-- | AK/AKString.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/AK/AKString.h b/AK/AKString.h index 27efb80051..2370a2bd4d 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -118,7 +118,16 @@ public: } ByteBuffer to_byte_buffer() const; - static String from_byte_buffer(const ByteBuffer&, ShouldChomp = NoChomp); + + template<typename BufferType> + static String copy(const BufferType& buffer, ShouldChomp should_chomp = NoChomp) + { + if (buffer.is_null()) + return { }; + if (buffer.is_empty()) + return empty(); + return String((const char*)buffer.data(), buffer.size(), should_chomp); + } static String format(const char*, ...); |