diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-15 19:24:36 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-04-12 20:31:55 +0100 | 
| commit | 411575edaf9ba586d77c8222ad25a1908b340739 (patch) | |
| tree | a138e468135d5b6217d65c298757be52d8de4033 | |
| parent | C++17 and Ice 3.7 (diff) | |
| download | gentoobrowse-api-411575edaf9ba586d77c8222ad25a1908b340739.tar.bz2 gentoobrowse-api-411575edaf9ba586d77c8222ad25a1908b340739.tar.xz gentoobrowse-api-411575edaf9ba586d77c8222ad25a1908b340739.zip | |
Apply some C++17 love.
| -rw-r--r-- | gentoobrowse-api/service/depend.cpp | 12 | ||||
| -rw-r--r-- | gentoobrowse-api/service/depend.h | 3 | ||||
| -rw-r--r-- | gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp | 4 | ||||
| -rw-r--r-- | gentoobrowse-api/service/utils/ebuildCacheParser.cpp | 22 | ||||
| -rw-r--r-- | gentoobrowse-api/service/utils/ebuildCacheParser.h | 10 | ||||
| -rw-r--r-- | gentoobrowse-api/service/utils/splitEbuildProps.cpp | 2 | ||||
| -rw-r--r-- | gentoobrowse-api/service/utils/splitEbuildProps.h | 6 | ||||
| -rw-r--r-- | gentoobrowse-api/service/utils/xmlUtils.cpp | 4 | ||||
| -rw-r--r-- | 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<Gentoo::DependencyPtr> -		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<Gentoo::DependencyPtr> -		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<Gentoo::DependencyPtr> parse(const std::string &); -				static std::vector<Gentoo::DependencyPtr> parse(const char *, const char *); +				static std::vector<Gentoo::DependencyPtr> parse(const std::string_view &);  				std::vector<Gentoo::DependencyPtr> 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 <string.h>  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<Glib::ustring> +		std::optional<Glib::ustring>  		EbuildCacheParser::get(const std::string & key) const  		{  			auto kvi = kvs.find(key);  			if (kvi == kvs.end()) { -				return boost::optional<Glib::ustring>(); +				return {};  			} -			return Glib::ustring(kvi->second.first, kvi->second.second); +			return Glib::ustring(kvi->second.data(), kvi->second.length());  		} -		boost::optional<EbuildCacheParser::Range> +		std::optional<std::string_view>  		EbuildCacheParser::getRange(const std::string & key) const  		{  			auto kvi = kvs.find(key);  			if (kvi == kvs.end()) { -				return boost::optional<Range>(); +				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 <fileUtils.h>  #include <map> -#include <boost/optional.hpp> +#include <string_view> +#include <optional>  #include <boost/filesystem/path.hpp>  #include <glibmm/ustring.h> @@ -11,13 +12,12 @@ namespace Gentoo {  	namespace Utils {  		class EbuildCacheParser : public AdHoc::FileUtils::MemMap {  			public: -				typedef std::pair<const char *, const char *> Range; -				typedef std::map<std::string, const Range> KVs; +				typedef std::map<std::string_view, const std::string_view> KVs;  				EbuildCacheParser(const boost::filesystem::path & p); -				boost::optional<Glib::ustring> get(const std::string & key) const; -				boost::optional<Range> getRange(const std::string & key) const; +				std::optional<Glib::ustring> get(const std::string & key) const; +				std::optional<std::string_view> 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<Glib::ustring> & p) : +		SplitEbuildProps::SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional<Glib::ustring> & 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 <sqlWriter.h>  #include <glibmm/ustring.h> -#include <boost/optional.hpp> +#include <optional>  namespace Gentoo {  	namespace Utils {  		class SplitEbuildProps : public DB::SqlWriter {  			public: -				SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const boost::optional<Glib::ustring> & p); +				SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const std::optional<Glib::ustring> & 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<Glib::ustring> props; +				const std::optional<Glib::ustring> 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<Glib::ustring> +		std::optional<Glib::ustring>  		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<Glib::ustring>(); +			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 <libxml++/parsers/domparser.h>  #include <boost/filesystem/path.hpp> -#include <boost/optional.hpp> +#include <optional>  namespace Gentoo {  	namespace Utils { @@ -11,7 +11,7 @@ namespace Gentoo {  			public:  				XmlDoc(const boost::filesystem::path &); -				boost::optional<Glib::ustring> getXPathValue(const Glib::ustring &); +				std::optional<Glib::ustring> getXPathValue(const Glib::ustring &);  		};  	}  } | 
