Use string_view in rXml

This commit is contained in:
Megamouse 2025-01-14 03:05:13 +01:00
parent 2643fbdea4
commit 1966171838
3 changed files with 7 additions and 8 deletions

View File

@ -21,7 +21,7 @@ using namespace std::literals::string_literals;
#include <cwchar>
#include <Windows.h>
static std::unique_ptr<wchar_t[]> to_wchar(const std::string& source)
static std::unique_ptr<wchar_t[]> to_wchar(std::string_view source)
{
// String size + null terminator
const usz buf_size = source.size() + 1;
@ -44,7 +44,7 @@ static std::unique_ptr<wchar_t[]> to_wchar(const std::string& source)
std::memcpy(buffer.get() + 32768 + 4, L"UNC\\", 4 * sizeof(wchar_t));
}
ensure(MultiByteToWideChar(CP_UTF8, 0, source.c_str(), size, buffer.get() + 32768 + (unc ? 8 : 4), size)); // "to_wchar"
ensure(MultiByteToWideChar(CP_UTF8, 0, source.data(), size, buffer.get() + 32768 + (unc ? 8 : 4), size)); // "to_wchar"
// Canonicalize wide path (replace '/', ".", "..", \\ repetitions, etc)
ensure(GetFullPathNameW(buffer.get() + 32768, 32768, buffer.get(), nullptr) - 1 < 32768 - 1); // "to_wchar"

View File

@ -49,12 +49,11 @@ std::string rXmlNode::GetName()
return {};
}
std::string rXmlNode::GetAttribute(const std::string& name)
std::string rXmlNode::GetAttribute(std::string_view name)
{
if (handle)
{
const auto pred = [&name](const pugi::xml_attribute& attr) { return (name == attr.name()); };
if (const pugi::xml_attribute attr = handle.find_attribute(pred))
if (const pugi::xml_attribute attr = handle.attribute(name))
{
if (const pugi::char_t* value = attr.value())
{
@ -86,7 +85,7 @@ rXmlDocument::rXmlDocument()
{
}
pugi::xml_parse_result rXmlDocument::Read(const std::string& data)
pugi::xml_parse_result rXmlDocument::Read(std::string_view data)
{
if (handle)
{

View File

@ -23,7 +23,7 @@ struct rXmlNode
std::shared_ptr<rXmlNode> GetChildren();
std::shared_ptr<rXmlNode> GetNext();
std::string GetName();
std::string GetAttribute(const std::string& name);
std::string GetAttribute(std::string_view name);
std::string GetNodeContent();
pugi::xml_node handle{};
@ -34,7 +34,7 @@ struct rXmlDocument
rXmlDocument();
rXmlDocument(const rXmlDocument& other) = delete;
rXmlDocument &operator=(const rXmlDocument& other) = delete;
pugi::xml_parse_result Read(const std::string& data);
pugi::xml_parse_result Read(std::string_view data);
virtual std::shared_ptr<rXmlNode> GetRoot();
pugi::xml_document handle{};