UrlEncode() methods from core/misc.h are now thread safe
This commit is contained in:
@@ -678,14 +678,11 @@ int SelectFileType(const std::wstring & file_name);
|
||||
|
||||
|
||||
|
||||
// thread safe
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void UrlEncode(char c,
|
||||
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||
bool clear_out = true)
|
||||
template<typename StreamType>
|
||||
void UrlEncode(char c, StreamType & out, bool clear_out = true)
|
||||
{
|
||||
char buffer[10];
|
||||
size_t buflen = sizeof(buffer)/sizeof(char);
|
||||
char buffer[10];
|
||||
size_t buflen = sizeof(buffer)/sizeof(char);
|
||||
|
||||
if( clear_out )
|
||||
out.clear();
|
||||
@@ -710,11 +707,33 @@ size_t buflen = sizeof(buffer)/sizeof(char);
|
||||
}
|
||||
|
||||
|
||||
// thread safe
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void UrlEncode(const char * in,
|
||||
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||
bool clear_out = true)
|
||||
|
||||
template<typename StreamType>
|
||||
void UrlEncode(wchar_t c, StreamType & out, bool clear_out = true)
|
||||
{
|
||||
char buffer[10];
|
||||
size_t buflen = sizeof(buffer)/sizeof(char);
|
||||
|
||||
if( clear_out )
|
||||
out.clear();
|
||||
|
||||
// this conversion is not using surrogate pairs if wchar_t is 2 bytes long
|
||||
size_t utf8_len = pt::int_to_utf8(static_cast<int>(c), buffer, buflen);
|
||||
|
||||
if( utf8_len > 0 )
|
||||
{
|
||||
for(size_t i=0 ; i < utf8_len ; ++i)
|
||||
{
|
||||
UrlEncode(buffer[i], out, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename StreamType>
|
||||
void UrlEncode(const char * in, StreamType & out, bool clear_out = true)
|
||||
{
|
||||
if( clear_out )
|
||||
out.clear();
|
||||
@@ -724,67 +743,44 @@ void UrlEncode(const char * in,
|
||||
}
|
||||
|
||||
|
||||
// thread safe
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void UrlEncode(const std::string & in,
|
||||
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||
bool clear_out = true)
|
||||
|
||||
template<typename StreamType>
|
||||
void UrlEncode(const std::string & in, StreamType & out, bool clear_out = true)
|
||||
{
|
||||
UrlEncode(in.c_str(), out, clear_out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// not thread safe
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void UrlEncode(const wchar_t * in,
|
||||
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||
bool clear_out = true)
|
||||
template<typename StreamType>
|
||||
void UrlEncode(const wchar_t * in, StreamType & out, bool clear_out = true)
|
||||
{
|
||||
static std::string ain;
|
||||
|
||||
pt::wide_to_utf8(in, ain);
|
||||
|
||||
if( clear_out )
|
||||
out.clear();
|
||||
|
||||
for(size_t i=0 ; i < ain.size() ; ++i)
|
||||
UrlEncode(ain[i], out, false);
|
||||
for(size_t i=0 ; in[i] != 0 ; ++i)
|
||||
UrlEncode(in[i], out, false);
|
||||
}
|
||||
|
||||
|
||||
// not thread safe
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void UrlEncode(const std::wstring & in,
|
||||
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||
bool clear_out = true)
|
||||
template<typename StreamType>
|
||||
void UrlEncode(const std::wstring & in, StreamType & out, bool clear_out = true)
|
||||
{
|
||||
UrlEncode(in.c_str(), out, clear_out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// no thread safe
|
||||
template<class StringType>
|
||||
void UrlEncode(char c, StringType & out, bool clear_out = true)
|
||||
{
|
||||
static pt::TextStream tmp;
|
||||
|
||||
UrlEncode(c, tmp);
|
||||
tmp.to_str(out, clear_out);
|
||||
}
|
||||
|
||||
|
||||
// !! IMROVE ME we need some UrlEncode methods with pt::TextBuffer instead of std::string
|
||||
|
||||
|
||||
void UrlEncode(const char * in, std::string & out, bool clear_out = true);
|
||||
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
|
||||
void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true);
|
||||
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
||||
//void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true);
|
||||
//void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
||||
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out = true);
|
||||
void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out = true);
|
||||
|
||||
void UrlEncode(const pt::TextStream & in, pt::TextStream & out, bool clear_out = true);
|
||||
void UrlEncode(const pt::WTextStream & in, pt::WTextStream & out, bool clear_out = true);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user