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

1325 lines
49 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <vector>
#include <list>
#include <string>
2015-05-21 21:49:35 +08:00
#include <stdarg.h>
2014-11-19 00:25:21 +08:00
#include <utility>
struct ACL_VSTRING;
struct ACL_LINE_STATE;
2014-11-19 00:25:21 +08:00
namespace acl {
2015-11-09 22:11:21 +08:00
class dbuf_pool;
2014-11-19 00:25:21 +08:00
/**
* std::string
* \0
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API string
{
public:
/**
*
* @param n {size_t}
* @param bin {bool} true
* += int|int64|short|char << int|int64|short|char
*
2014-11-19 00:25:21 +08:00
*/
2017-04-22 17:44:17 +08:00
string(void);
explicit string(size_t n);
string(size_t n, bool bin);
2014-11-19 00:25:21 +08:00
/**
*
* @param s {const string&}
*
2014-11-19 00:25:21 +08:00
*/
string(const string& s);
/**
*
* @param s {const char*} s
* \0
2014-11-19 00:25:21 +08:00
*/
string(const char* s);
/**
*
* @param s {const char*}
* @param n {size_t} s
2014-11-19 00:25:21 +08:00
*/
string(const void* s, size_t n);
#if defined(_WIN32) || defined(_WIN64)
/**
*
* @param fd {int}
* @param max {size_t}
* @param n {size_t}
*/
string(void* fd, size_t max, size_t n);
#else
string(int fd, size_t max, size_t n);
#endif
virtual ~string(void);
2014-11-19 00:25:21 +08:00
/**
*
* @param bin {bool} true
* true += int|int64|short|char
* << int|int64|short|char
*
2014-11-19 00:25:21 +08:00
* @return {string&}
*/
string& set_bin(bool bin);
/**
*
2014-11-19 00:25:21 +08:00
* @param max {int}
* @return {string&}
*/
string& set_max(int max);
/**
*
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool get_bin() const;
/**
* <= 0
2014-11-19 00:25:21 +08:00
* @return {int}
*/
int get_max(void) const;
/**
*
*
* @param n {size_t} >= 0 < )
*
* @return {char}
2014-11-19 00:25:21 +08:00
*/
char operator[](size_t n) const;
/**
*
*
* @param n {int} >= 0 < )
*
* @return {char}
2014-11-19 00:25:21 +08:00
*/
char operator[](int n) const;
/**
* 使
*
* @param n {size_t}
2014-11-19 00:25:21 +08:00
* @return {char&}
*/
char& operator[](size_t n);
/**
* 使
*
* @param n {int} >= 0
2014-11-19 00:25:21 +08:00
* @return {char&}
*/
char& operator[](int n);
/**
*
* @param s {const char*}
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(const char* s);
/**
*
* @param s {const string&}
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(const string& s);
/**
*
* @param s {const string*}
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(const string* s);
/**
*
* @param s {const std::string&}
* @return {string&} 便
*/
string& operator=(const std::string& s);
/**
*
* @param s {const std::string*}
* @return {string&} 便
*/
string& operator=(const std::string* s);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
*
* @param n {long long int} 64
* 便
*
2014-11-19 00:25:21 +08:00
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(__int64 n);
/**
*
* @param n {unsinged long long int} 64
* 便
*
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(unsigned __int64);
#else
string& operator=(long long int);
string& operator=(unsigned long long int);
#endif
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(char n);
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(unsigned char n);
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(long n);
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(unsigned long n);
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(int n);
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(unsigned int n);
/**
*
* @param n {char} ,
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(short n);
/**
*
* @param n {char}
* 便
* set_bin(bool)
* @return {string&} 便
2014-11-19 00:25:21 +08:00
*/
string& operator=(unsigned short n);
/**
*
* @param s {const char*}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(const char* s);
/**
*
* @param s {const string&}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(const string& s);
/**
*
* @param s {const string*}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(const string* s);
/**
*
* @param s {const std::string&}
* @return {string&}
*/
string& operator+=(const std::string& s);
/**
*
* @param s {const std::string*}
* @return {string&}
*/
string& operator+=(const std::string* s);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
*
*
* @param n {long long int} 64
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(__int64 n);
/**
*
*
* @param n {long long int} 64
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(unsigned __int64 n);
#else
string& operator+=(long long int n);
string& operator+=(unsigned long long int n);
#endif
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(long n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(unsigned long n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(int n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(unsigned int n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(short n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(unsigned short n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(char n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator+=(unsigned char n);
/**
*
* @param s {const string&}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(const string& s);
/**
*
* @param s {const string*}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(const string* s);
/**
*
* @param s {const std::string&}
* @return {string&}
*/
string& operator<<(const std::string& s);
/**
*
* @param s {const std::string*}
* @return {string&}
*/
string& operator<<(const std::string* s);
2014-11-19 00:25:21 +08:00
/**
*
* @param s {const char*}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(const char* s);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
*
*
* @param n {long long int} 64
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(__int64 n);
/**
*
*
* @param n {long long int} 64
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(unsigned __int64 n);
#else
string& operator<<(long long int n);
string& operator<<(unsigned long long int n);
#endif
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(long n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(unsigned long n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(int n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(unsigned int n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(short n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(unsigned short n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(char n);
/**
*
*
* @param n {long}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& operator<<(unsigned char n);
/**
*
* @param s {string*}
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(string* s);
/**
*
* @param s {string&}
* @return {size_t} empty() == true 0
*/
size_t operator>>(string& s);
/**
*
* @param s {std::string*}
* @return {size_t} empty() == true 0
*/
size_t operator>>(std::string* s);
/**
*
* @param s {std::string&}
* @return {size_t} empty() == true 0
*/
size_t operator>>(std::string& s);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
* 64
* @param n {string*} 64
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(__int64& n);
/**
* 64
* @param n {string*} 64
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(unsigned __int64& n);
#else
size_t operator>>(long long int&);
size_t operator>>(unsigned long long int&);
#endif
/**
* 32
* @param n {string*} 32
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(int& n);
/**
* 32
* @param n {string*} 32
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(unsigned int& n);
/**
* 16
* @param n {string*} 16
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(short& n);
/**
* 16
* @param n {string*} 16
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(unsigned short& n);
/**
* 8
* @param n {string*} 16
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(char& n);
/**
* 8
* @param n {string*} 16
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t operator>>(unsigned char& n);
/**
*
* @param s {const string&}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool operator==(const string& s) const;
/**
*
* @param s {const string&}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool operator==(const string* s) const;
/**
*
* @param s {const string&}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool operator==(const char* s) const;
/**
*
* @param s {const string&}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool operator!=(const string& s) const;
/**
*
* @param s {const string&}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool operator!=(const string* s) const;
/**
*
* @param s {const string&}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool operator!=(const char* s) const;
/**
*
* @param s {const string&}
* @return {bool} true
*
2014-11-19 00:25:21 +08:00
*/
bool operator<(const string& s) const;
/**
*
* @param s {const string&}
* @return {bool} true
*
2014-11-19 00:25:21 +08:00
*/
bool operator>(const string& s) const;
/**
*
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
operator const char*() const;
/**
*
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
operator const void*() const;
/**
*
* @param ch {char}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& push_back(char ch);
2015-11-09 22:11:21 +08:00
/**
*
* @param s {const string&}
* @param case_sensitive {bool} true
* @return {bool} true
2015-11-09 22:11:21 +08:00
*/
bool equal(const string& s, bool case_sensitive = true) const;
/**
* string
* @param s {const char*}
* @param case_sensitive {bool}
* @return {bool}
*/
bool begin_with(const char* s, bool case_sensitive = true) const;
bool begin_with(const char* s, size_t len, bool case_sensitive = true) const;
bool begin_with(const string& s, bool case_sensitive = true) const;
bool begin_with(const void* v, size_t len) const;
2018-10-07 21:35:46 +08:00
/**
* string
2018-10-07 21:35:46 +08:00
* @param s {const char*}
* @param case_sensitive {bool}
2018-10-07 21:35:46 +08:00
* @return {bool}
*/
bool end_with(const char* s, bool case_sensitive = true) const;
bool end_with(const char* s, size_t len, bool case_sensitive = true) const;
bool end_with(const string& s, bool case_sensitive = true) const;
bool end_with(const void* v, size_t len) const;
2014-11-19 00:25:21 +08:00
/**
*
* @param s {const string&}
* @return {int} 0 > 0
* < 0
2014-11-19 00:25:21 +08:00
*/
int compare(const string& s) const;
/**
*
* @param s {const string&}
* @return {int} 0 > 0
* < 0
2014-11-19 00:25:21 +08:00
*/
int compare(const string* s) const;
/**
*
* @param s {const string&}
* @param case_sensitive {bool} true
* @return {int} 0 > 0
* < 0
2014-11-19 00:25:21 +08:00
*/
int compare(const char* s, bool case_sensitive = true) const;
/**
*
* @param ptr {const void*}
* @param len {size_t} ptr
* @return {int} :
* 0
* > 0
* < 0
2014-11-19 00:25:21 +08:00
*/
int compare(const void* ptr, size_t len) const;
/**
*
* @param s {const void*}
* @param len {size_t} ptr
* @param case_sensitive {bool} true
* @return {int} 0 > 0
* < 0
2014-11-19 00:25:21 +08:00
*/
int ncompare(const char* s, size_t len, bool case_sensitive = true) const;
/**
*
*
* @param s {const void*}
* @param len {size_t} ptr
* @param case_sensitive {bool} true
* @return {int} 0
* > 0
* < 0
2014-11-19 00:25:21 +08:00
*/
int rncompare(const char* s, size_t len, bool case_sensitive = true) const;
/**
*
*
* @param left_count {int*}
* @param buf {string*} ()
* ()
*
* @return {int} 0 > 0
* (
* 0) < 0
*/
int find_blank_line(int* left_count = NULL, string* buf = NULL);
/**
* find_blank_line
*
* @return {string&}
*/
string& find_reset(void);
2014-11-19 00:25:21 +08:00
/**
* 0
* @param n {char}
* @return {int} < 0
2014-11-19 00:25:21 +08:00
*/
int find(char n) const;
/**
* 0
* @param needle {const char*}
* @param case_sensitive {bool} true
* @return {char*}
2014-11-19 00:25:21 +08:00
*/
char* find(const char* needle, bool case_sensitive=true) const;
/**
* 0
* @param needle {const char*}
* @param case_sensitive {bool} true
* @return {char*}
2014-11-19 00:25:21 +08:00
*/
char* rfind(const char* needle, bool case_sensitive=true) const;
/**
*
* @param npos {size_t}
*
* @return {string}
*
2014-11-19 00:25:21 +08:00
*/
string left(size_t npos);
/**
*
* @param npos {size_t}
*
* @return {const string}
*
2014-11-19 00:25:21 +08:00
*/
string right(size_t npos);
/**
*
* @param buf {void*}
* @param size {size_t} buf
* @param move {bool}
*
* @return {size_t} empty() == true 0
2014-11-19 00:25:21 +08:00
*/
size_t scan_buf(void* buf, size_t size, bool move = false);
/**
* ("\r\n")
*
*
* @param out {string&}
* @param nonl {bool} "\r\n" "\n"
* @param n {size_t*}
* nonl true 0
* @param move {bool}
*
* @return {bool} false
* empty() == true
2014-11-19 00:25:21 +08:00
*/
bool scan_line(string& out, bool nonl = true, size_t* n = NULL,
bool move = false);
/**
* 使 scan_xxx move
* 使
* @return {size_t}
2014-11-19 00:25:21 +08:00
*/
size_t scan_move();
/**
*
* @return {char*} NULL empty() == true
2014-11-19 00:25:21 +08:00
*/
char* buf_end(void);
/**
*
* @return {void*}
2014-11-19 00:25:21 +08:00
*/
void* buf() const;
/**
*
* @return {char*}
2014-11-19 00:25:21 +08:00
*/
char* c_str() const;
/**
* \0
* @return {size_t} >= 0
2014-11-19 00:25:21 +08:00
*/
size_t length() const;
/**
* \0 length
* @return {size_t} >= 0
2014-11-19 00:25:21 +08:00
*/
size_t size() const;
/**
* >=
* @return {size_t} > 0
2014-11-19 00:25:21 +08:00
*/
size_t capacity() const;
/**
* 0
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
bool empty() const;
/**
* acl C ACL_VSTRING
* @return {ACL_VSTRING*}
2014-11-19 00:25:21 +08:00
*/
ACL_VSTRING* vstring(void) const;
/**
*
* @param n {size_t} >= capacity
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& set_offset(size_t n);
/**
*
* @param n {size_t}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& space(size_t n);
/**
*
* @param sep {const char*}
* @param quoted {bool} true /
* sep /
* @return {std::list<string>&} list
*
2014-11-19 00:25:21 +08:00
*/
2016-04-15 09:45:07 +08:00
std::list<string>& split(const char* sep, bool quoted = false);
2014-11-19 00:25:21 +08:00
/**
*
* @param sep {const char*}
* @param quoted {bool} true /
* sep /
* @return {std::vector<string>&} vector
*
2014-11-19 00:25:21 +08:00
*/
2016-04-15 09:45:07 +08:00
std::vector<string>& split2(const char* sep, bool quoted = false);
2016-04-14 22:39:11 +08:00
2014-11-19 00:25:21 +08:00
/**
* '=' name/value
* '=' TAB
* @return {std::pair<string, string>&}
* name=value格式
* ,
2014-11-19 00:25:21 +08:00
*/
std::pair<string, string>& split_nameval(void);
/**
*
* @param ptr {const char*} '\0'
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& copy(const char* ptr);
/**
*
* @param ptr {const void*}
* @param len {size_t} ptr
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& copy(const void* ptr, size_t len);
/**
*
*
* @param src {const char*}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& memmove(const char* src);
/**
*
*
* @param src {const char*}
* @param len {size_t}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& memmove(const char* src, size_t len);
/**
*
* @param s {const string&}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& append(const string& s);
/**
*
* @param s {const string&}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& append(const string* s);
/**
*
* @param s {const string&}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& append(const char* s);
/**
*
* @param ptr {const void*}
* @param len {size_t} ptr
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& append(const void* ptr, size_t len);
/**
*
* @param s {const char*}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& prepend(const char* s);
/**
*
* @param ptr {const void*}
* @param len {size_t} ptr
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& prepend(const void* ptr, size_t len);
/**
*
* @param start {size_t}
* @param ptr {const void*}
* @param len {size_t}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& insert(size_t start, const void* ptr, size_t len);
/**
* sprintf
* @param fmt {const char*}
* @param ...
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& format(const char* fmt, ...) ACL_CPP_PRINTF(2, 3);
/**
* vsprintf
* @param fmt {const char*}
* @param ap {va_list}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& vformat(const char* fmt, va_list ap);
/**
*
* @param fmt {const char*}
* @param ...
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& format_append(const char* fmt, ...) ACL_CPP_PRINTF(2, 3);
/**
*
* @param fmt {const char*}
* @param ap {va_list}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& vformat_append(const char* fmt, va_list ap);
/**
*
* @param from {char}
* @param to {char}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& replace(char from, char to);
/**
*
* @param n {size_t} >=
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& truncate(size_t n);
/**
*
*
* @param needle {const char*}
* @param each {bool} true needle
*
* needle
* @return {string&}
* acl::string s("hello world!");
* s.strip("hel", true), s == "o word!"
* s.strip("hel", false), : s = "lo world!"
2014-11-19 00:25:21 +08:00
*/
string& strip(const char* needle, bool each = false);
/**
* TAB
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& trim_left_space();
/**
* TAB
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& trim_right_space();
/**
* TAB
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& trim_space();
/**
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& trim_left_line();
/**
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& trim_right_line();
/**
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& trim_line();
/**
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& clear();
/**
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& lower(void);
/**
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& upper(void);
/**
*
* @param out {string&}
* @param pos {size_t}
* @param len {size_t} pos 0
* pos
*
* @return {size_t} pos 0
*/
size_t substr(string& out, size_t pos = 0, size_t len = 0) const;
2014-11-19 00:25:21 +08:00
/**
* base64
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& base64_encode(void);
/**
* base64
* @param ptr {const void*}
* @param len {size_t}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& base64_encode(const void* ptr, size_t len);
/**
* base64
*
* @return {string&}
* string::empty() true
2014-11-19 00:25:21 +08:00
*/
string& base64_decode(void);
/**
* base64
* @param s {const char*} base64
* @return {string&}
* string::empty() true
2014-11-19 00:25:21 +08:00
*/
string& base64_decode(const char* s);
/**
* base64
* @param ptr {const void*} base64
* @param len {size_t} ptr
* @return {string&}
* string::empty() true
2014-11-19 00:25:21 +08:00
*/
string& base64_decode(const void* ptr, size_t len);
/**
* url
* @param s {const char*}
* @param dbuf {dbuf_pool*}
*
* 使 acl_mymalloc
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
2015-11-09 22:11:21 +08:00
string& url_encode(const char* s, dbuf_pool* dbuf = NULL);
2014-11-19 00:25:21 +08:00
/**
* url
* @param s {const char*} url
* @param dbuf {dbuf_pool*}
*
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
2015-11-09 22:11:21 +08:00
string& url_decode(const char* s, dbuf_pool* dbuf = NULL);
2014-11-19 00:25:21 +08:00
/**
* H2B
* @param s {const void*}
* @param len {size_t}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& hex_encode(const void* s, size_t len);
/**
* H2B
* @param s {const char*}
* @param len {size_t}
* @return {string&}
2014-11-19 00:25:21 +08:00
*/
string& hex_decode(const char* s, size_t len);
/**
*
* @param path {const char*}
* @return {string&}
*/
string& basename(const char* path);
/**
*
* @param path {const char*}
* @return {string&}
*/
string& dirname(const char* path);
2014-11-19 00:25:21 +08:00
/**
* 32 使线
* @param n {int} 32
* @return {string&} 线
2014-11-19 00:25:21 +08:00
*/
static string& parse_int(int n);
/**
* 32 使线
* @param n {int} 32
* @return {string&} 线
2014-11-19 00:25:21 +08:00
*/
static string& parse_int(unsigned int n);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
static string& parse_int64(__int64 n);
static string& parse_int64(unsigned __int64 n);
#else
/**
* 64 使线
* @param n {long long int} 64
* @return {string&} 线
2014-11-19 00:25:21 +08:00
*/
static string& parse_int64(long long int n);
/**
* 64 使线
* @param n {unsigned long long int} 64
* @return {string&} 线
2014-11-19 00:25:21 +08:00
*/
static string& parse_int64(unsigned long long int n);
#endif
/**
* :
* string s1, s2;
* T v;
* s1 = s2 + v;
*/
template<typename T>
string& operator+(T v)
{
*this += v;
return *this;
}
2014-11-19 00:25:21 +08:00
private:
bool use_bin_;
ACL_VSTRING* vbf_;
char* scan_ptr_;
std::list<string>* list_tmp_;
std::vector<string>* vector_tmp_;
std::pair<string, string>* pair_tmp_;
ACL_LINE_STATE* line_state_;
int line_state_offset_;
2014-11-19 00:25:21 +08:00
void init(size_t len);
};
/**
* :
* string s1, s2;
* T v;
* s1 = v + s2;
*/
template<typename T>
string operator+(T v, const string& rhs)
{
string s;
s = v;
s += rhs;
return s;
}
/**
* :
* string s, s1 = "hello", s2 = "world";
* s = s1 + " " + s2;
* s = ">" + s1 + " " + s2;
* s = 1000 + s1 + " " + s2 + 1000;
*/
2014-11-19 00:25:21 +08:00
} // namespce acl