]> git.tdb.fi Git - libs/net.git/blob - source/version.cpp
Rename data to content in Message
[libs/net.git] / source / version.cpp
1 /* $Id$
2
3 This file is part of libmsphttp
4 Copyright © 2008  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #include <msp/strings/formatter.h>
9 #include <msp/strings/lexicalcast.h>
10 #include <msp/strings/regex.h>
11 #include "version.h"
12
13 using namespace std;
14
15 namespace Msp {
16 namespace Http {
17
18 Version parse_version(const std::string &ver)
19 {
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);
22         else
23                 throw InvalidParameterValue("Invalid HTTP version");
24 }
25
26 string version_str(Version ver)
27 {
28         return format("HTTP/%u.%u", (ver>>4)&0xF, ver&0xF);
29 }
30
31 } // namespace Http
32 } // namespace Msp