From 15b942e9beaa6f40a396ade7f469515f00d62d3b Mon Sep 17 00:00:00 2001 From: Roker Date: Tue, 19 Mar 2019 14:34:58 +0100 Subject: [PATCH] add ascii_tolower() --- src/bodyparser.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/bodyparser.cc b/src/bodyparser.cc index 146773f..a8d0d13 100644 --- a/src/bodyparser.cc +++ b/src/bodyparser.cc @@ -16,6 +16,7 @@ namespace qi = boost::spirit::qi; std::string type; std::string subtype; std::vector params; + void tolower(); // only for ASCII chars, but that's sufficient here. }; BOOST_FUSION_ADAPT_STRUCT( @@ -34,6 +35,23 @@ BOOST_FUSION_ADAPT_STRUCT( ) +void ascii_tolower(std::string& s) +{ + for(char& c : s) + { + if(c>='A' && c<='Z') + { + c += 32; + } + } +} + +void ContentType::tolower() +{ + ascii_tolower(type); + ascii_tolower(subtype); +} + std::ostream& operator<<(std::ostream& o, const ContentType& ct) { return o << "CT:{" << ct.type << "/" << ct.subtype << ". params=" << ct.params << " } "; @@ -101,6 +119,7 @@ void parse_body(message* msg, const HeaderSection& headers, const std::deque { throw std::runtime_error( "Cannot parse \"" + std::string{cts} + "\" as ContentType"); } + ct.tolower(); std::cerr << ct << std::endl; }else{ // Non-MIME mail