From b283fe07af7b2b32c3935fac2f76b9a615b57626 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Jan 2024 20:52:33 +0100 Subject: [PATCH] lib/expat/ExpatParser: pass std::string_view to CharacterData() --- src/db/plugins/upnp/Directory.cxx | 8 ++++---- src/lib/expat/ExpatParser.hxx | 4 ++-- src/lib/upnp/Device.cxx | 4 ++-- src/storage/plugins/CurlStorage.cxx | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/db/plugins/upnp/Directory.cxx b/src/db/plugins/upnp/Directory.cxx index 6f1d2b7db..87f439762 100644 --- a/src/db/plugins/upnp/Directory.cxx +++ b/src/db/plugins/upnp/Directory.cxx @@ -191,12 +191,12 @@ protected: state = NONE; } - void CharacterData(const XML_Char *s, int len) override + void CharacterData(std::string_view s) override { if (tag_type != TAG_NUM_OF_ITEM_TYPES) { assert(object.type != UPnPDirObject::Type::UNKNOWN); - value.append(s, len); + value.append(s); return; } @@ -205,11 +205,11 @@ protected: break; case RES: - object.url.assign(s, len); + object.url.assign(s); break; case CLASS: - object.item_class = ParseItemClass(std::string_view(s, len)); + object.item_class = ParseItemClass(s); break; } } diff --git a/src/lib/expat/ExpatParser.hxx b/src/lib/expat/ExpatParser.hxx index 0ea814248..656f34b8f 100644 --- a/src/lib/expat/ExpatParser.hxx +++ b/src/lib/expat/ExpatParser.hxx @@ -115,7 +115,7 @@ protected: virtual void StartElement(const XML_Char *name, const XML_Char **atts) = 0; virtual void EndElement(const XML_Char *name) = 0; - virtual void CharacterData(const XML_Char *s, int len) = 0; + virtual void CharacterData(const std::string_view s) = 0; private: static void XMLCALL StartElement(void *user_data, const XML_Char *name, @@ -132,6 +132,6 @@ private: static void XMLCALL CharacterData(void *user_data, const XML_Char *s, int len) { CommonExpatParser &p = *(CommonExpatParser *)user_data; - p.CharacterData(s, len); + p.CharacterData({s, static_cast(len)}); } }; diff --git a/src/lib/upnp/Device.cxx b/src/lib/upnp/Device.cxx index 1dc3e8355..9b1a1e729 100644 --- a/src/lib/upnp/Device.cxx +++ b/src/lib/upnp/Device.cxx @@ -69,9 +69,9 @@ protected: } } - void CharacterData(const XML_Char *s, int len) override { + void CharacterData(std::string_view s) override { if (value != nullptr) - value->append(s, len); + value->append(s); } }; diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index 3fa88f9d9..49ac95864 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -172,9 +172,9 @@ ParseStatus(const char *s) noexcept [[gnu::pure]] static unsigned -ParseStatus(const char *s, size_t length) noexcept +ParseStatus(std::string_view s) noexcept { - return ParseStatus(std::string(s, length).c_str()); + return ParseStatus(std::string{s}.c_str()); } [[gnu::pure]] @@ -186,9 +186,9 @@ ParseTimeStamp(const char *s) noexcept [[gnu::pure]] static std::chrono::system_clock::time_point -ParseTimeStamp(const char *s, size_t length) noexcept +ParseTimeStamp(std::string_view s) noexcept { - return ParseTimeStamp(std::string(s, length).c_str()); + return ParseTimeStamp(std::string{s}.c_str()); } [[gnu::pure]] @@ -200,9 +200,9 @@ ParseU64(const char *s) noexcept [[gnu::pure]] static uint64_t -ParseU64(const char *s, size_t length) noexcept +ParseU64(std::string_view s) noexcept { - return ParseU64(std::string(s, length).c_str()); + return ParseU64(std::string{s}.c_str()); } [[gnu::pure]] @@ -391,7 +391,7 @@ private: } } - void CharacterData(const XML_Char *s, int len) final { + void CharacterData(std::string_view s) final { switch (state) { case State::ROOT: case State::PROPSTAT: @@ -400,19 +400,19 @@ private: break; case State::HREF: - response.href.append(s, len); + response.href.append(s); break; case State::STATUS: - response.status = ParseStatus(s, len); + response.status = ParseStatus(s); break; case State::MTIME: - response.mtime = ParseTimeStamp(s, len); + response.mtime = ParseTimeStamp(s); break; case State::LENGTH: - response.length = ParseU64(s, len); + response.length = ParseU64(s); break; } }