Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-05-21 17:40:59


Author: drrngrvy
Date: 2008-05-21 17:40:58 EDT (Wed, 21 May 2008)
New Revision: 45628
URL: http://svn.boost.org/trac/boost/changeset/45628

Log:
Missing file.
Added:
   sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/url_decode.ipp (contents, props changed)

Added: sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/url_decode.ipp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/boost/cgi/detail/url_decode.ipp 2008-05-21 17:40:58 EDT (Wed, 21 May 2008)
@@ -0,0 +1,101 @@
+// -- url_decode.ipp --
+//
+// Copyright (c) Darren Garvey 2007.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+#ifndef CGI_DETAIL_URL_DECODE_IPP_INCLUDED__
+#define CGI_DETAIL_URL_DECODE_IPP_INCLUDED__
+
+#include "boost/cgi/detail/url_decode.hpp"
+
+namespace cgi {
+ namespace detail {
+
+ /// Convert a char into a hexadecimal value
+ BOOST_CGI_INLINE std::string char_to_hex(char const& ch)
+ {
+ return std::string(); // **FIXME**
+ }
+
+ /// Convert two characters into a single, hex-encoded character
+ BOOST_CGI_INLINE char hex_to_char(char const& c1, char const& c2)
+ {
+ int ret ( ( std::isalpha(c1)
+ ? ((c1 & 0xdf) - 'A') + 10
+ : (c1 - '0')
+ ) << 4
+ );
+
+ ret += ( std::isalpha(c2)
+ ? ((c2 & 0xdf) - 'A') + 10
+ : (c2 - '0')
+ );
+
+ return static_cast<char>(ret);
+ }
+
+ /// Take two characters (a hex sequence) and return a char
+ // **DEPRECATED**
+ BOOST_CGI_INLINE char url_decode( const char& c1, const char& c2 )
+ {
+ int ret = ( (c1 >= 'A' && c1 <= 'Z') || (c1 >= 'a' && c1 <= 'z')
+ ? ((c1 & 0xdf) - 'A') + 10
+ : (c1 - '0')
+ ) << 4;
+
+ ret += ( (c2 >= 'A' && c2 <= 'Z') || (c2 >= 'a' && c2 <= 'z')
+ ? ((c2 & 0xdf) - 'A') + 10
+ : (c2 - '0')
+ );
+
+ return static_cast<char>(ret);
+ }
+
+ /// URL-decode a string
+ BOOST_CGI_INLINE std::string url_decode( const std::string& str )
+ {
+ typedef std::string string_type;
+ string_type ret;
+
+ for( string_type::const_iterator iter = str.begin(), end = str.end()
+ ; iter != end; ++iter )
+ {
+ switch( *iter )
+ {
+ case ' ':
+ break;
+ case '+':
+ ret.append(1, ' ');
+ break;
+ case '%':
+ if (std::distance(iter, end) >= 2
+ && std::isxdigit(*(iter+1))
+ && std::isxdigit(*(iter+2)))
+ {
+ char ch = *++iter; // need this because order of function arg
+ // evaluation is UB.
+ ret.append(1, hex_to_char(ch, *++iter));
+ }
+ else // we're not dealing with a properly encoded hex value.
+ {
+ ret.append(1, '%');
+ }
+ break;
+ default:
+ ret.append(1, *iter);
+ }
+ }
+
+ return ret;
+ }
+
+ } // namespace detail
+} // namespace cgi
+
+#include "boost/cgi/detail/pop_options.hpp"
+
+#endif // CGI_DETAIL_URL_DECODE_IPP_INCLUDED__
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk