lib/expat/ExpatParser: pass std::string_view to CharacterData()
This commit is contained in:
parent
feeb21577f
commit
b283fe07af
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<std::size_t>(len)});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue