From 280eb99ab9d3d88f6d1ee4ad0a821ab755eea12e Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Thu, 15 Dec 2022 22:57:48 +0100 Subject: [PATCH] Use string_view instead of string. Signed-off-by: Viktor Govako --- base/string_utils.cpp | 4 ++-- kml/serdes.cpp | 44 +++++++++++++++++++------------------------ kml/serdes.hpp | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 819a528996..420c938760 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -71,8 +71,8 @@ bool UniString::IsEqualAscii(char const * s) const SimpleDelimiter::SimpleDelimiter(char const * delims) { - std::string const s(delims); - std::string::const_iterator it = s.begin(); + std::string_view const s(delims); + auto it = s.begin(); while (it != s.end()) m_delims.push_back(utf8::unchecked::next(it)); } diff --git a/kml/serdes.cpp b/kml/serdes.cpp index 0e9d473737..1ea52a0f78 100644 --- a/kml/serdes.cpp +++ b/kml/serdes.cpp @@ -15,25 +15,23 @@ #include -using namespace std::string_literals; - namespace kml { namespace { -std::string const kPlacemark = "Placemark"; -std::string const kStyle = "Style"; -std::string const kDocument = "Document"; -std::string const kStyleMap = "StyleMap"; -std::string const kStyleUrl = "styleUrl"; -std::string const kPair = "Pair"; -std::string const kExtendedData = "ExtendedData"; +std::string_view const kPlacemark = "Placemark"; +std::string_view const kStyle = "Style"; +std::string_view const kDocument = "Document"; +std::string_view const kStyleMap = "StyleMap"; +std::string_view const kStyleUrl = "styleUrl"; +std::string_view const kPair = "Pair"; +std::string_view const kExtendedData = "ExtendedData"; std::string const kCompilation = "mwm:compilation"; -std::string const kCoordinates = "coordinates"; -std::string const kTrack = "Track"; -std::string const gxTrack = "gx:Track"; -std::string const gxCoord = "gx:coord"; +std::string_view const kCoordinates = "coordinates"; +std::string_view const kTrack = "Track"; +std::string_view const gxTrack = "gx:Track"; +std::string_view const gxCoord = "gx:coord"; std::string const kKmlHeader = "\n" @@ -59,19 +57,15 @@ auto const kDefaultTrackColor = 0x006ec7ff; std::string Indent(size_t count) { - static std::string const kIndent = " "; - std::ostringstream indent; - for (size_t i = 0; i < count; ++i) - indent << kIndent; - return indent.str(); + return std::string(count, ' '); } -static std::string const kIndent0 = Indent(0); -static std::string const kIndent2 = Indent(2); -static std::string const kIndent4 = Indent(4); -static std::string const kIndent6 = Indent(6); -static std::string const kIndent8 = Indent(8); -static std::string const kIndent10 = Indent(10); +std::string const kIndent0 = Indent(0); +std::string const kIndent2 = Indent(2); +std::string const kIndent4 = Indent(4); +std::string const kIndent6 = Indent(6); +std::string const kIndent8 = Indent(8); +std::string const kIndent10 = Indent(10); std::string PointToString(m2::PointD const & org) { @@ -883,7 +877,7 @@ void KmlParser::AddAttr(std::string const & attr, std::string const & value) } } -bool KmlParser::IsValidAttribute(std::string const & type, std::string const & value, +bool KmlParser::IsValidAttribute(std::string_view const & type, std::string const & value, std::string const & attrInLowerCase) const { return (GetTagFromEnd(0) == type && !value.empty() && attrInLowerCase == "id"); diff --git a/kml/serdes.hpp b/kml/serdes.hpp index 7694efe30f..ab8d3385b1 100644 --- a/kml/serdes.hpp +++ b/kml/serdes.hpp @@ -73,7 +73,7 @@ public: void CharData(std::string value); /// @} - bool IsValidAttribute(std::string const & type, std::string const & value, + bool IsValidAttribute(std::string_view const & type, std::string const & value, std::string const & attrInLowerCase) const; static kml::TrackLayer GetDefaultTrackLayer();