diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-01-04 14:28:11 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-01-04 15:52:05 +0000 |
commit | 47199a38d11c86f90a28b40ee21b3e5ec2b1aea2 (patch) | |
tree | bfb9b0d94315ace1a0bd545dcd17afd34e4df5af | |
parent | A single ycm config that gets its args from b2 (diff) | |
download | slicer-47199a38d11c86f90a28b40ee21b3e5ec2b1aea2.tar.bz2 slicer-47199a38d11c86f90a28b40ee21b3e5ec2b1aea2.tar.xz slicer-47199a38d11c86f90a28b40ee21b3e5ec2b1aea2.zip |
Split metadata helpers into their own file
-rw-r--r-- | slicer/slicer/metadata.cpp | 48 | ||||
-rw-r--r-- | slicer/slicer/metadata.h | 20 | ||||
-rw-r--r-- | slicer/slicer/parser.cpp | 33 | ||||
-rw-r--r-- | slicer/slicer/parser.h | 3 |
4 files changed, 69 insertions, 35 deletions
diff --git a/slicer/slicer/metadata.cpp b/slicer/slicer/metadata.cpp new file mode 100644 index 0000000..da861ca --- /dev/null +++ b/slicer/slicer/metadata.cpp @@ -0,0 +1,48 @@ +#include "metadata.h" +#include <boost/algorithm/string/predicate.hpp> +#include <boost/algorithm/string/split.hpp> +#include <boost/algorithm/string/classification.hpp> + +bool +Slicer::metaDataFlagSet(const std::list<std::string> & md, const std::string & flag) +{ + return std::find(md.cbegin(), md.cend(), flag) != md.cend(); +} + +bool +Slicer::metaDataFlagNotSet(const std::list<std::string> & md, const std::string & flag) +{ + return std::find(md.cbegin(), md.cend(), flag) == md.cend(); +} + +std::list<std::string> +Slicer::metaDataValues(const std::string & prefix, const std::list<std::string> & metadata) +{ + std::list<std::string> mds; + for (const auto & md : metadata) { + if (boost::algorithm::starts_with(md, prefix)) { + mds.push_back(md.substr(prefix.length())); + } + } + return mds; +} + +std::vector<std::string> +Slicer::metaDataSplit(const std::string & metadata) +{ + std::vector<std::string> parts; + boost::algorithm::split(parts, metadata, boost::algorithm::is_any_of(":"), boost::algorithm::token_compress_off); + return parts; +} + +boost::optional<std::string> +Slicer::metaDataValue(const std::string & prefix, const std::list<std::string> & metadata) +{ + for (const auto & md : metadata) { + if (boost::algorithm::starts_with(md, prefix)) { + return md.substr(prefix.length()); + } + } + return boost::optional<std::string>(); +} + diff --git a/slicer/slicer/metadata.h b/slicer/slicer/metadata.h new file mode 100644 index 0000000..2ed26b8 --- /dev/null +++ b/slicer/slicer/metadata.h @@ -0,0 +1,20 @@ +#ifndef SLICER_METADATA_H +#define SLICER_METADATA_H + +#include <string> +#include <list> +#include <vector> +#include <boost/optional.hpp> + +namespace Slicer { + // Flags + bool metaDataFlagSet(const std::list<std::string> &, const std::string & flag); + bool metaDataFlagNotSet(const std::list<std::string> &, const std::string & flag); + // Values + boost::optional<std::string> metaDataValue(const std::string & prefix, const std::list<std::string> & metadata); + std::list<std::string> metaDataValues(const std::string & prefix, const std::list<std::string> & metadata); + std::vector<std::string> metaDataSplit(const std::string & metadata); +} + +#endif + diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 9c72d09..bdd42ec 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -1,9 +1,8 @@ #include "parser.h" +#include "metadata.h" #include <Slice/Parser.h> #include <Slice/Preprocessor.h> #include <boost/algorithm/string/predicate.hpp> -#include <boost/algorithm/string/classification.hpp> -#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/trim.hpp> #include <Slice/CPlusPlusUtil.h> @@ -428,36 +427,6 @@ namespace Slicer { fprintf(cpp, "};\n\n"); } - boost::optional<std::string> - Slicer::metaDataValue(const std::string & prefix, const std::list<std::string> & metadata) - { - for (const auto & md : metadata) { - if (boost::algorithm::starts_with(md, prefix)) { - return md.substr(prefix.length()); - } - } - return boost::optional<std::string>(); - } - - std::list<std::string> - Slicer::metaDataValues(const std::string & prefix, const std::list<std::string> & metadata) - { - std::list<std::string> mds; - for (const auto & md : metadata) { - if (boost::algorithm::starts_with(md, prefix)) { - mds.push_back(md.substr(prefix.length())); - } - } - return mds; - } - - std::vector<std::string> - Slicer::metaDataSplit(const std::string & metadata) - { - std::vector<std::string> parts; - boost::algorithm::split(parts, metadata, boost::algorithm::is_any_of(":"), boost::algorithm::token_compress_off); - return parts; - } std::vector<Slicer::ConversionSpec> Slicer::getConversions(Slice::DataMemberPtr dm) diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h index f53e62e..9be2465 100644 --- a/slicer/slicer/parser.h +++ b/slicer/slicer/parser.h @@ -48,9 +48,6 @@ namespace Slicer { void defineConversions(Slice::DataMemberPtr dm) const; void copyMetadata(const std::list<std::string> & metadata) const; - static boost::optional<std::string> metaDataValue(const std::string & prefix, const std::list<std::string> & metadata); - static std::list<std::string> metaDataValues(const std::string & prefix, const std::list<std::string> & metadata); - static std::vector<std::string> metaDataSplit(const std::string & metadata); static std::vector<ConversionSpec> getConversions(Slice::DataMemberPtr); unsigned int components; |