db/upnp/Util: trimstring() constructs string from buffer
Reduce overhead by omitting the part of the buffer that consists only of whitespace.
This commit is contained in:
parent
f3b4ddee6c
commit
55737e4ff6
|
@ -56,8 +56,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void CharacterData(const XML_Char *s, int len) {
|
virtual void CharacterData(const XML_Char *s, int len) {
|
||||||
std::string str(s, len);
|
std::string str = trimstring(s, len);
|
||||||
trimstring(str);
|
|
||||||
switch (m_path.back()[0]) {
|
switch (m_path.back()[0]) {
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!m_path.back().compare("controlURL"))
|
if (!m_path.back().compare("controlURL"))
|
||||||
|
|
|
@ -156,8 +156,7 @@ protected:
|
||||||
|
|
||||||
virtual void CharacterData(const XML_Char *s, int len)
|
virtual void CharacterData(const XML_Char *s, int len)
|
||||||
{
|
{
|
||||||
std::string str(s, len);
|
std::string str = trimstring(s, len);
|
||||||
trimstring(str);
|
|
||||||
|
|
||||||
TagType type = tag_table_lookup(upnp_tags,
|
TagType type = tag_table_lookup(upnp_tags,
|
||||||
m_path.back().c_str());
|
m_path.back().c_str());
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Util.hxx"
|
#include "Util.hxx"
|
||||||
|
#include "util/CharUtil.hxx"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -27,19 +28,17 @@
|
||||||
#include <upnp/ixml.h>
|
#include <upnp/ixml.h>
|
||||||
|
|
||||||
/** Get rid of white space at both ends */
|
/** Get rid of white space at both ends */
|
||||||
void
|
std::string
|
||||||
trimstring(std::string &s, const char *ws)
|
trimstring(const char *p, size_t length)
|
||||||
{
|
{
|
||||||
auto pos = s.find_first_not_of(ws);
|
while (length > 0 && IsWhitespaceOrNull(p[length - 1]))
|
||||||
if (pos == std::string::npos) {
|
--length;
|
||||||
s.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s.replace(0, pos, std::string());
|
|
||||||
|
|
||||||
pos = s.find_last_not_of(ws);
|
const char *end = p + length;
|
||||||
if (pos != std::string::npos && pos != s.length()-1)
|
while (p != end && IsWhitespaceOrNull(*p))
|
||||||
s.replace(pos + 1, std::string::npos, std::string());
|
++p;
|
||||||
|
|
||||||
|
return std::string(p, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
|
|
@ -28,8 +28,9 @@
|
||||||
std::string
|
std::string
|
||||||
caturl(const std::string& s1, const std::string& s2);
|
caturl(const std::string& s1, const std::string& s2);
|
||||||
|
|
||||||
void
|
gcc_pure
|
||||||
trimstring(std::string &s, const char *ws = " \t\n");
|
std::string
|
||||||
|
trimstring(const char *p, size_t length);
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
path_getfather(const std::string &s);
|
path_getfather(const std::string &s);
|
||||||
|
|
Loading…
Reference in New Issue