mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-20 12:14:55 +00:00
Add split_mime() function.
This commit is contained in:
parent
148b60ee97
commit
05979e24a2
2 changed files with 54 additions and 0 deletions
|
@ -4,6 +4,17 @@
|
|||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <boost/spirit/include/qi_core.hpp>
|
||||
#include <boost/spirit/include/qi_parse.hpp>
|
||||
#include <boost/spirit/include/qi_lit.hpp>
|
||||
#include <boost/spirit/include/qi_char_.hpp>
|
||||
#include <boost/spirit/include/qi_plus.hpp>
|
||||
#include <boost/spirit/include/qi_raw.hpp>
|
||||
#include <boost/spirit/include/phoenix_bind.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/fusion/adapted/std_pair.hpp>
|
||||
#include <boost/phoenix/object/construct.hpp>
|
||||
#include <boost/phoenix/stl/container.hpp>
|
||||
|
||||
namespace din {
|
||||
using MagicCookie = std::unique_ptr<magic_set, void(*)(magic_t)>;
|
||||
|
@ -61,4 +72,41 @@ namespace din {
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
SplitMime split_mime (const std::string& parFull) {
|
||||
using boost::spirit::ascii::space;
|
||||
using boost::spirit::qi::char_;
|
||||
using boost::spirit::qi::lit;
|
||||
using boost::spirit::qi::raw;
|
||||
using boost::spirit::qi::_val;
|
||||
using boost::string_ref;
|
||||
using boost::phoenix::construct;
|
||||
using boost::spirit::_1;
|
||||
using boost::phoenix::begin;
|
||||
using boost::phoenix::size;
|
||||
namespace px = boost::phoenix;
|
||||
using RuleType = boost::spirit::qi::rule<std::string::const_iterator, string_ref(), boost::spirit::ascii::space_type>;
|
||||
|
||||
SplitMime retval;
|
||||
|
||||
auto full_it = parFull.begin();
|
||||
const auto beg = parFull.begin();
|
||||
RuleType mime_token = raw[+(char_ - ';')][_val = px::bind(&string_ref::substr, construct<string_ref>(px::ref(parFull)), begin(_1) - px::ref(beg), size(_1))];
|
||||
RuleType charset_token = raw[+(char_)][_val = px::bind(&string_ref::substr, construct<string_ref>(px::ref(parFull)), begin(_1) - px::ref(beg), size(_1))];
|
||||
|
||||
const bool parse_ret = boost::spirit::qi::phrase_parse(
|
||||
full_it,
|
||||
parFull.end(),
|
||||
mime_token >> ';' >> lit("charset=") >> charset_token,
|
||||
space,
|
||||
retval
|
||||
);
|
||||
|
||||
if (not parse_ret or parFull.end() != full_it) {
|
||||
return SplitMime();
|
||||
}
|
||||
else {
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
} //namespace din
|
||||
|
|
|
@ -20,8 +20,12 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace din {
|
||||
using SplitMime = std::pair<boost::string_ref, boost::string_ref>;
|
||||
|
||||
class MimeType {
|
||||
public:
|
||||
MimeType ( void );
|
||||
|
@ -35,6 +39,8 @@ namespace din {
|
|||
|
||||
std::unique_ptr<LocalData> m_local_data;
|
||||
};
|
||||
|
||||
SplitMime split_mime ( const std::string& parFull );
|
||||
} //namespace din
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue