From 411575edaf9ba586d77c8222ad25a1908b340739 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 15 Mar 2018 19:24:36 +0000 Subject: Apply some C++17 love. --- gentoobrowse-api/service/depend.cpp | 12 ++---------- gentoobrowse-api/service/depend.h | 3 +-- .../service/maintenance/ebuildMetaProcessor.cpp | 4 ++-- .../service/utils/ebuildCacheParser.cpp | 22 ++++++++++------------ gentoobrowse-api/service/utils/ebuildCacheParser.h | 10 +++++----- .../service/utils/splitEbuildProps.cpp | 2 +- gentoobrowse-api/service/utils/splitEbuildProps.h | 6 +++--- gentoobrowse-api/service/utils/xmlUtils.cpp | 4 ++-- gentoobrowse-api/service/utils/xmlUtils.h | 4 ++-- 9 files changed, 28 insertions(+), 39 deletions(-) diff --git a/gentoobrowse-api/service/depend.cpp b/gentoobrowse-api/service/depend.cpp index 11244d9..c17b37a 100644 --- a/gentoobrowse-api/service/depend.cpp +++ b/gentoobrowse-api/service/depend.cpp @@ -79,18 +79,10 @@ namespace Portage { } std::vector - Depend::parse(const std::string & s) + Depend::parse(const std::string_view & s) { Depend d; - d.extract(s.c_str(), s.length()); - return d.ds; - } - - std::vector - Depend::parse(const char * begin, const char * end) - { - Depend d; - d.extract(begin, end - begin); + d.extract(s.data(), s.length()); return d.ds; } } diff --git a/gentoobrowse-api/service/depend.h b/gentoobrowse-api/service/depend.h index abd9f06..beeace6 100644 --- a/gentoobrowse-api/service/depend.h +++ b/gentoobrowse-api/service/depend.h @@ -14,8 +14,7 @@ namespace Portage { Gentoo::StringList when; public: - static std::vector parse(const std::string &); - static std::vector parse(const char *, const char *); + static std::vector parse(const std::string_view &); std::vector ds; }; } diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index 3d4ecd7..34b451f 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -218,11 +218,11 @@ namespace Gentoo { depInsert->bindParamI(1, ebuildId); if (auto depend = ecp.getRange("DEPEND")) { depInsert->bindParamB(5, false); - insertDeps(Portage::Utils::Depend::parse(depend->first, depend->second)); + insertDeps(Portage::Utils::Depend::parse(*depend)); } if (auto rdepend = ecp.getRange("RDEPEND")) { depInsert->bindParamB(5, true); - insertDeps(Portage::Utils::Depend::parse(rdepend->first, rdepend->second)); + insertDeps(Portage::Utils::Depend::parse(*rdepend)); } if (newest) { DB::TablePatch t; diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp index f83d5f8..c3ac689 100644 --- a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp +++ b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp @@ -1,37 +1,35 @@ #include "ebuildCacheParser.h" -#include namespace Gentoo { namespace Utils { EbuildCacheParser::EbuildCacheParser(const boost::filesystem::path & p) : AdHoc::FileUtils::MemMap(p) { - const char * chardata = (const char *)this->data; - auto len = this->getStat().st_size; - while (const char * eq = (const char *)memchr(chardata, '=', len - (chardata - (const char *)this->data))) { - if (const char * nl = (const char *)memchr(eq + 1, '\n', len - ((eq + 1) - (const char *)this->data))) { - kvs.insert({ std::string(chardata, eq), { eq + 1, nl } }); - chardata = nl + 1; + auto chardata = sv(); + for (auto eq = chardata.find('='); eq != std::string_view::npos; eq = chardata.find('=')) { + if (auto nl = chardata.find('\n', eq + 1); nl != std::string_view::npos) { + kvs.insert({ chardata.substr(0, eq), chardata.substr(eq + 1, nl - eq - 1) }); + chardata.remove_prefix(nl + 1); } } } - boost::optional + std::optional EbuildCacheParser::get(const std::string & key) const { auto kvi = kvs.find(key); if (kvi == kvs.end()) { - return boost::optional(); + return {}; } - return Glib::ustring(kvi->second.first, kvi->second.second); + return Glib::ustring(kvi->second.data(), kvi->second.length()); } - boost::optional + std::optional EbuildCacheParser::getRange(const std::string & key) const { auto kvi = kvs.find(key); if (kvi == kvs.end()) { - return boost::optional(); + return {}; } return kvi->second; } diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.h b/gentoobrowse-api/service/utils/ebuildCacheParser.h index 3aa5573..ca6d6f4 100644 --- a/gentoobrowse-api/service/utils/ebuildCacheParser.h +++ b/gentoobrowse-api/service/utils/ebuildCacheParser.h @@ -3,7 +3,8 @@ #include #include -#include +#include +#include #include #include @@ -11,13 +12,12 @@ namespace Gentoo { namespace Utils { class EbuildCacheParser : public AdHoc::FileUtils::MemMap { public: - typedef std::pair Range; - typedef std::map KVs; + typedef std::map KVs; EbuildCacheParser(const boost::filesystem::path & p); - boost::optional get(const std::string & key) const; - boost::optional getRange(const std::string & key) const; + std::optional get(const std::string & key) const; + std::optional getRange(const std::string & key) const; private: KVs kvs; diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.cpp b/gentoobrowse-api/service/utils/splitEbuildProps.cpp index 97790b5..ce052ab 100644 --- a/gentoobrowse-api/service/utils/splitEbuildProps.cpp +++ b/gentoobrowse-api/service/utils/splitEbuildProps.cpp @@ -4,7 +4,7 @@ namespace Gentoo { namespace Utils { - SplitEbuildProps::SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const boost::optional & p) : + SplitEbuildProps::SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional & p) : entityId(e), colEntityName(ce), colPropName(cp), diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.h b/gentoobrowse-api/service/utils/splitEbuildProps.h index 4739b7e..c6ed14f 100644 --- a/gentoobrowse-api/service/utils/splitEbuildProps.h +++ b/gentoobrowse-api/service/utils/splitEbuildProps.h @@ -3,20 +3,20 @@ #include #include -#include +#include namespace Gentoo { namespace Utils { class SplitEbuildProps : public DB::SqlWriter { public: - SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const boost::optional & p); + SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional & p); void writeSql(AdHoc::Buffer & sql) override; void bindParams(DB::Command * c, unsigned int & offset) override; const int entityId; const std::string colEntityName, colPropName; - const boost::optional props; + const std::optional props; }; } } diff --git a/gentoobrowse-api/service/utils/xmlUtils.cpp b/gentoobrowse-api/service/utils/xmlUtils.cpp index 3fc3b44..03078d4 100644 --- a/gentoobrowse-api/service/utils/xmlUtils.cpp +++ b/gentoobrowse-api/service/utils/xmlUtils.cpp @@ -7,7 +7,7 @@ namespace Gentoo { { } - boost::optional + std::optional XmlDoc::getXPathValue(const Glib::ustring & xp) { auto ns = get_document()->get_root_node()->find(xp); @@ -19,7 +19,7 @@ namespace Gentoo { else if (ns.size() > 1) { throw std::logic_error("Ambiguous xpath " + xp); } - return boost::optional(); + return {}; } } } diff --git a/gentoobrowse-api/service/utils/xmlUtils.h b/gentoobrowse-api/service/utils/xmlUtils.h index 158e134..a02df6c 100644 --- a/gentoobrowse-api/service/utils/xmlUtils.h +++ b/gentoobrowse-api/service/utils/xmlUtils.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace Gentoo { namespace Utils { @@ -11,7 +11,7 @@ namespace Gentoo { public: XmlDoc(const boost::filesystem::path &); - boost::optional getXPathValue(const Glib::ustring &); + std::optional getXPathValue(const Glib::ustring &); }; } } -- cgit v1.2.3