acl/lib_acl_cpp/include/acl_cpp/stdlib/url_coder.hpp

122 lines
3.0 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include "dbuf_pool.hpp"
2014-11-19 00:25:21 +08:00
#include <vector>
namespace acl {
class string;
struct URL_NV
{
char* name;
char* value;
};
class ACL_CPP_API url_coder : public dbuf_obj
2014-11-19 00:25:21 +08:00
{
public:
/**
*
* @param nocase {bool} true
* @param dbuf {dbuf_guard*}
2014-11-19 00:25:21 +08:00
*/
url_coder(bool nocase = true, dbuf_guard* dbuf = NULL);
2014-11-19 00:25:21 +08:00
/**
*
2014-11-19 00:25:21 +08:00
* @param coder {const url_coder&}
* @param dbuf {dbuf_guard*}
2014-11-19 00:25:21 +08:00
*/
url_coder(const url_coder& coder, dbuf_guard* dbuf = NULL);
2014-11-19 00:25:21 +08:00
~url_coder();
/**
* params_ url
* @param buf {string&}
* @param clean {bool} buf
2014-11-19 00:25:21 +08:00
*/
void encode(string& buf, bool clean = true) const;
/**
*
2014-11-19 00:25:21 +08:00
* @return {const string&}
*/
const string& to_string() const;
/**
* URL
* @param str {const char*} url
2014-11-19 00:25:21 +08:00
*/
void decode(const char* str);
/**
* url
* @param name {const char*}
* @param value
* @param override {bool}
* @return url_coder
2014-11-19 00:25:21 +08:00
*/
url_coder& set(const char* name, const char* value,
bool override = true);
url_coder& set(const char* name, int value, bool override = true);
url_coder& set(const char* name, bool override, const char* fmt, ...)
ACL_CPP_PRINTF(4, 5);
url_coder& set(const char* name, const char* fmt, va_list ap,
bool override = true);
/**
* URL params_
* @param name {const char*}
* @return {const char*} NULL
2014-11-19 00:25:21 +08:00
*/
const char* get(const char* name) const;
/**
* URL params_
* @param name {const char*}
* @return {const char*} NULL
2014-11-19 00:25:21 +08:00
*/
const char* operator[](const char* name) const;
/**
* URL
* @param coder {const url_coder&} URL
2014-11-19 00:25:21 +08:00
* @return {const url_coder&}
*/
const url_coder& operator =(const url_coder& coder);
/**
*
2014-11-19 00:25:21 +08:00
* @return {std::vector<URL_NV*>&}
*/
const std::vector<URL_NV*>& get_params() const
{
return params_;
}
/**
* params_
* @param name {const char*}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool del(const char* name);
/**
*
2014-11-19 00:25:21 +08:00
*/
void reset();
private:
bool nocase_;
dbuf_guard* dbuf_;
dbuf_guard* dbuf_internal_;
2014-11-19 00:25:21 +08:00
std::vector<URL_NV*> params_;
string* buf_;
void init_dbuf(dbuf_guard* dbuf);
2014-11-19 00:25:21 +08:00
};
} // namespace acl end