]> git.tdb.fi Git - libs/net.git/blobdiff - source/misc.cpp
Initial revision
[libs/net.git] / source / misc.cpp
diff --git a/source/misc.cpp b/source/misc.cpp
new file mode 100644 (file)
index 0000000..6ac7c5d
--- /dev/null
@@ -0,0 +1,32 @@
+/* $Id$
+
+This file is part of libmsphttp
+Copyright © 2008  Mikkosoft Productions, Mikko Rasa
+Distributed under the LGPL
+*/
+
+#include <msp/strings/formatter.h>
+#include <msp/strings/lexicalcast.h>
+#include <msp/strings/regex.h>
+#include "misc.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<unsigned>(match[1].str)<<4 | lexical_cast<unsigned>(match[2].str);
+       else
+               throw InvalidParameterValue("Invalid HTTP version");
+}
+
+string version_str(Version ver)
+{
+       return format("HTTP/%u.%u", (ver>>4)&0xF, ver&0xF);
+}
+
+} // namespace Http
+} // namespace Msp