libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00037 #ifndef FM_LAST_MOOST_MURCL_URI_ENCODER_HPP__ 00038 #define FM_LAST_MOOST_MURCL_URI_ENCODER_HPP__ 00039 00040 #include <string> 00041 00042 #include <curl/curl.h> 00043 00044 #include "../utils/scope_exit.hpp" 00045 00046 #include <boost/cast.hpp> 00047 00048 namespace moost { namespace murcl { 00049 00053 struct uri_encoder 00054 { 00055 typedef moost::utils::scope_exit::type<char *> 00056 ::call_free_function_with_val encoded_t; 00057 00067 static std::string encode(std::string const & uri) 00068 { 00069 std::string encoded_uri; 00070 00071 if(!uri.empty()) 00072 { 00073 encoded_t encoded( 00074 curl_escape(uri.c_str(), 00075 boost::numeric_cast<int>(uri.size())), 00076 curl_free); 00077 00078 encoded_uri = encoded->get(); 00079 } 00080 00081 return encoded_uri; 00082 } 00083 }; 00084 00085 }} 00086 00087 00088 #endif // FM_LAST_MOOST_MURCL_URI_ENCODER_HPP__