diff options
Diffstat (limited to 'tools/libskrewt.c')
-rw-r--r-- | tools/libskrewt.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/libskrewt.c b/tools/libskrewt.c new file mode 100644 index 0000000..a756863 --- /dev/null +++ b/tools/libskrewt.c @@ -0,0 +1,49 @@ +#include <iostream> +#include "libskrewt.h" + +using namespace std; + +void parse_content(const string type_spec_line, + string &maintype, string &boundary) { + //xxx cerr << "parser called with: " << type_spec_line << endl; + string get_type(type_spec_line); + + size_t where = get_type.find_first_of(" \t;\n"); + string rest; + if (where == string::npos) { + // keep whole string + } + else { + rest = get_type.substr(where+1); + get_type = get_type.substr(0,where); + } + where = get_type.find("/"); + if (where == string::npos){ + maintype = ""; + cerr << "could not find / in " << get_type << endl; + } else { + maintype = get_type.substr(0, where); + } + +// now need to find boundary + + string srch = "boundary="; + where = rest.find(srch); + if (where != string::npos) { + where += srch.length(); + boundary = rest.substr(where); + if (boundary[0] == '"') { + boundary = boundary.substr(1); + where = boundary.find_first_of("\""); + } else { + where = boundary.find_first_of(" \t;\n"); + } + if (where == string::npos) { + /* do nothing, boundary=boundary as a whole */ + } else { + boundary = boundary.substr(0, where); + } + } else { + //xxxxxxx cerr << "boundary= not found in " << type_spec_line << endl; + } +} |