lib/expat/ExpatParser: pass std::string_view to Parse()

This commit is contained in:
Max Kellermann 2024-01-04 12:58:20 +01:00
parent 4c9942534c
commit ee4b49d12f
9 changed files with 18 additions and 24 deletions

View File

@ -216,8 +216,8 @@ protected:
};
void
UPnPDirContent::Parse(const char *input)
UPnPDirContent::Parse(std::string_view input)
{
UPnPDirParser parser(*this);
parser.Parse(input, strlen(input), true);
parser.Parse(input, true);
}

View File

@ -1,12 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#ifndef MPD_UPNP_DIRECTORY_HXX
#define MPD_UPNP_DIRECTORY_HXX
#pragma once
#include "Object.hxx"
#include <string>
#include <string_view>
#include <vector>
/**
@ -44,7 +43,5 @@ public:
* actually global, nothing really bad will happen if you mix
* up...
*/
void Parse(const char *didltext);
void Parse(std::string_view didltext);
};
#endif /* _UPNPDIRCONTENT_H_X_INCLUDED_ */

View File

@ -7,9 +7,9 @@
#include <string.h>
void
ExpatParser::Parse(const char *data, size_t length, bool is_final)
ExpatParser::Parse(std::string_view src, bool is_final)
{
if (XML_Parse(parser, data, length, is_final) != XML_STATUS_OK)
if (XML_Parse(parser, src.data(), src.size(), is_final) != XML_STATUS_OK)
throw ExpatError(parser);
}

View File

@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#ifndef MPD_EXPAT_HXX
#define MPD_EXPAT_HXX
#pragma once
#include <expat.h>
#include <stdexcept>
#include <string_view>
#include <utility>
class InputStream;
@ -54,10 +54,10 @@ public:
XML_SetCharacterDataHandler(parser, charhndl);
}
void Parse(const char *data, size_t length, bool is_final=false);
void Parse(std::string_view src, bool is_final=false);
void CompleteParse() {
Parse("", 0, true);
Parse({}, true);
}
void Parse(InputStream &is);
@ -135,5 +135,3 @@ private:
p.CharacterData(s, len);
}
};
#endif

View File

@ -79,11 +79,11 @@ protected:
};
void
UPnPDevice::Parse(const std::string_view url, const char *description)
UPnPDevice::Parse(const std::string_view url, const std::string_view description)
{
{
UPnPDeviceParser mparser(*this);
mparser.Parse(description, strlen(description), true);
mparser.Parse(description, true);
}
if (URLBase.empty()) {

View File

@ -56,5 +56,5 @@ public:
* @param url where the description came from
* @param description the xml device description
*/
void Parse(std::string_view url, const char *description);
void Parse(std::string_view url, std::string_view description);
};

View File

@ -63,7 +63,7 @@ UPnPDeviceDirectory::Downloader::OnEnd()
expires);
try {
d.Parse(url, data.c_str());
d.Parse(url, data);
} catch (...) {
LogError(std::current_exception());
}

View File

@ -55,7 +55,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
:id(std::move(_id)),
expires(last + exp + std::chrono::seconds(20)) {}
void Parse(std::string_view url, const char *description) {
void Parse(std::string_view url, std::string_view description) {
device.Parse(url, description);
}
};

View File

@ -297,9 +297,8 @@ private:
throw std::runtime_error("Unexpected Content-Type from WebDAV server");
}
void OnData(std::span<const std::byte> _src) final {
auto src = ToStringView(_src);
Parse(src.data(), src.size());
void OnData(std::span<const std::byte> src) final {
Parse(ToStringView(src));
}
void OnEnd() final {