3 This file is part of libmsphttp
4 Copyright © 2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
8 #include <msp/strings/formatter.h>
9 #include <msp/strings/lexicalcast.h>
10 #include <msp/strings/regex.h>
18 Version parse_version(const std::string &ver)
20 if(RegMatch match=Regex("^HTTP/([0-9]+).([0-9]+)$").match(ver))
21 return lexical_cast<unsigned>(match[1].str)<<4 | lexical_cast<unsigned>(match[2].str);
23 throw InvalidParameterValue("Invalid HTTP version");
26 string version_str(Version ver)
28 return format("HTTP/%u.%u", (ver>>4)&0xF, ver&0xF);