lib/expat/ExpatParser: pass std::string_view to Parse()
This commit is contained in:
parent
4c9942534c
commit
ee4b49d12f
@ -216,8 +216,8 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
UPnPDirContent::Parse(const char *input)
|
UPnPDirContent::Parse(std::string_view input)
|
||||||
{
|
{
|
||||||
UPnPDirParser parser(*this);
|
UPnPDirParser parser(*this);
|
||||||
parser.Parse(input, strlen(input), true);
|
parser.Parse(input, true);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_UPNP_DIRECTORY_HXX
|
#pragma once
|
||||||
#define MPD_UPNP_DIRECTORY_HXX
|
|
||||||
|
|
||||||
#include "Object.hxx"
|
#include "Object.hxx"
|
||||||
|
|
||||||
#include <string>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,7 +43,5 @@ public:
|
|||||||
* actually global, nothing really bad will happen if you mix
|
* actually global, nothing really bad will happen if you mix
|
||||||
* up...
|
* up...
|
||||||
*/
|
*/
|
||||||
void Parse(const char *didltext);
|
void Parse(std::string_view didltext);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UPNPDIRCONTENT_H_X_INCLUDED_ */
|
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void
|
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);
|
throw ExpatError(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_EXPAT_HXX
|
#pragma once
|
||||||
#define MPD_EXPAT_HXX
|
|
||||||
|
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
class InputStream;
|
class InputStream;
|
||||||
@ -54,10 +54,10 @@ public:
|
|||||||
XML_SetCharacterDataHandler(parser, charhndl);
|
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() {
|
void CompleteParse() {
|
||||||
Parse("", 0, true);
|
Parse({}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parse(InputStream &is);
|
void Parse(InputStream &is);
|
||||||
@ -135,5 +135,3 @@ private:
|
|||||||
p.CharacterData(s, len);
|
p.CharacterData(s, len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -79,11 +79,11 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void
|
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);
|
UPnPDeviceParser mparser(*this);
|
||||||
mparser.Parse(description, strlen(description), true);
|
mparser.Parse(description, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (URLBase.empty()) {
|
if (URLBase.empty()) {
|
||||||
|
@ -56,5 +56,5 @@ public:
|
|||||||
* @param url where the description came from
|
* @param url where the description came from
|
||||||
* @param description the xml device description
|
* @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);
|
||||||
};
|
};
|
||||||
|
@ -63,7 +63,7 @@ UPnPDeviceDirectory::Downloader::OnEnd()
|
|||||||
expires);
|
expires);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
d.Parse(url, data.c_str());
|
d.Parse(url, data);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LogError(std::current_exception());
|
LogError(std::current_exception());
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
|
|||||||
:id(std::move(_id)),
|
:id(std::move(_id)),
|
||||||
expires(last + exp + std::chrono::seconds(20)) {}
|
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);
|
device.Parse(url, description);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -297,9 +297,8 @@ private:
|
|||||||
throw std::runtime_error("Unexpected Content-Type from WebDAV server");
|
throw std::runtime_error("Unexpected Content-Type from WebDAV server");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnData(std::span<const std::byte> _src) final {
|
void OnData(std::span<const std::byte> src) final {
|
||||||
auto src = ToStringView(_src);
|
Parse(ToStringView(src));
|
||||||
Parse(src.data(), src.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnd() final {
|
void OnEnd() final {
|
||||||
|
Loading…
Reference in New Issue
Block a user