X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhttp%2Fversion.cpp;fp=source%2Fhttp%2Fversion.cpp;h=f22b46eafe92523497d25403c3c772fd1fe46676;hb=cf8d2e48581eeb8f1b83e8c48321a0bc2ffa6d83;hp=0000000000000000000000000000000000000000;hpb=d683ca0964182e9579838fec8d7d100eeabddee0;p=libs%2Fnet.git diff --git a/source/http/version.cpp b/source/http/version.cpp new file mode 100644 index 0000000..f22b46e --- /dev/null +++ b/source/http/version.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include "version.h" + +using namespace std; + +namespace Msp { +namespace Http { + +Version parse_version(const std::string &ver) +{ + if(RegMatch match = Regex("^HTTP/([0-9]+).([0-9]+)$").match(ver)) + return lexical_cast(match[1].str)<<4 | lexical_cast(match[2].str); + else + throw invalid_argument("parse_version"); +} + +string version_str(Version ver) +{ + return format("HTTP/%u.%u", (ver>>4)&0xF, ver&0xF); +} + +} // namespace Http +} // namespace Msp