Hi, experts,
I using boost.regex parse the content-type header's value in MIME.
A typical content-type's BNF like following:
Content-Type = "Content-Type:" SP media-type
media-type = type "/" subtype *( ";" gen-param )
type = token
subtype = token
gen-param = pname [ "=" pval ]
pname = token
pval = token / quoted-string
An example content-type as following:
multipart/mixed; boundary="theboundary" ;id=33
There may be zero or one more parameters in content-type.
My parse code as following:
#include
#include <iostream>
#include <string>
#define COUT(x) std::cout << x << std::endl
#define VAR(v) std::cout << #v << ": " << v << std::endl
#define TOKEN "[a-zA-Z0-9]+"
#define TYPE "(" TOKEN ")"
#define SUBTYPE "(" TOKEN ")"
#define PNAME "(" TOKEN ")"
#define PVALUE "(" TOKEN ")"
#define PARAM "(;" PNAME "=" PVALUE ")"
#define CONTENT_TYPE_EXPRESS TYPE "/" SUBTYPE PARAM "*"
int main()
{
std::string ct("multipart/mixed;boundary=theboundary;id=33");
COUT(CONTENT_TYPE_EXPRESS);
boost::regex regex_content_type(CONTENT_TYPE_EXPRESS);
boost::smatch result;
if (boost::regex_match(ct, result, regex_content_type)) {
VAR(result.size());
for (unsigned int i=0; i