changed: now we do not use std::string and char* in the Winix API

everywhere we are using std::wstring and wchar_t*
         (std::string and char* is used only locally in some places
         especially when creating a path to OS file system etc.)
added:   to the special thread when winix closes:
         a write function for curl: FetchPageOnExitCurlCallback()
         without this function the curl library will print
         the page's content to the standart output
changed: TextStream<> class from core can make
         UTF8<->wide strings conversions
removed: from config: utf8 option
         now winix expects UTF8 from the user's input (html forms, url-es)
         and outputs strings in the UTF8 format




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@965 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2014-10-09 20:44:56 +00:00
parent 4abf6642f7
commit 8196fb77d1
74 changed files with 1911 additions and 1612 deletions

View File

@@ -41,6 +41,7 @@
#include "space/space.h"
#include "date/date.h"
#include "textstream/textstream.h"
#include "utf8/utf8.h"
namespace Winix
@@ -54,7 +55,17 @@ namespace Winix
similar to std::ostringstream
StringType can be either std::string or std::wstring
this class doesn't use UTF-8 in any kind
this class uses UTF-8 <-> wide characters conversions:
if StringType is std::string:
operator<<(const char*) only copies the input string
operator<<(const wchar_t*) converts from wide characters to UTF-8
(similary for an operator with std::string and std::wstring)
if StringType is std::wstring:
operator<<(const char*) converts from UTF-8 to wide characters
operator<<(const wchar_t*) only copies the input string
(similary for an operator with std::string and std::wstring)
*/
template<class StringType>
class TextStream
@@ -99,16 +110,35 @@ public:
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
TextStream & operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
TextStream & Write(const char * buf, size_t len);
TextStream & Write(const char * buf, size_t len);
TextStream & Write(const wchar_t * buf, size_t len);
TextStream & write(const char * buf, size_t len); // for compatibility with standard library (Ezc uses it)
TextStream & write(const char * buf, size_t len); // for compatibility with standard library (Ezc uses it)
TextStream & write(const wchar_t * buf, size_t len);
protected:
StringType buffer;
std::wstring space_str; // for using with spaces
void Convert(wchar_t c, std::string & dst);
void Convert(wchar_t c, std::wstring & dst);
void Convert(const char * src, size_t len, std::wstring & dst);
void Convert(const char * src, std::wstring & dst);
void Convert(const std::string & src, std::wstring & dst);
void Convert(const wchar_t * src, size_t len, std::string & dst);
void Convert(const wchar_t * src, std::string & dst);
void Convert(const std::wstring & src, std::string & dst);
void Convert(const char * src, size_t len, std::string & dst);
void Convert(const char * src, std::string & dst);
void Convert(const std::string & src, std::string & dst);
void Convert(const wchar_t * src, size_t len, std::wstring & dst);
void Convert(const wchar_t * src, std::wstring & dst);
void Convert(const std::wstring & src, std::wstring & dst);
};
@@ -178,7 +208,7 @@ typename TextStream<StringType>::CharType TextStream<StringType>::operator[](siz
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
{
AssignString(str, buffer, false);
Convert(str, buffer);
return *this;
}
@@ -187,7 +217,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
{
AssignString(*str, buffer, false);
Convert(*str, buffer);
return *this;
}
@@ -196,7 +226,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
{
AssignString(str, buffer, false);
Convert(str, buffer);
return *this;
}
@@ -206,7 +236,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
{
AssignString(str, buffer, false);
Convert(str, buffer);
return *this;
}
@@ -215,7 +245,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
{
AssignString(*str, buffer, false);
Convert(*str, buffer);
return *this;
}
@@ -224,7 +254,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
{
AssignString(str, buffer, false);
Convert(str, buffer);
return *this;
}
@@ -234,6 +264,10 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(char v)
{
/*
* there is no any possibility to treat 'v' as UTF-8 character if we have got
* only one character so we only copy it
*/
buffer += v;
return *this;
@@ -243,7 +277,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
{
buffer += static_cast<CharType>(v);
Convert(v, buffer);
return *this;
}
@@ -256,7 +290,7 @@ wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
Convert(buf, buffer);
return *this;
}
@@ -269,7 +303,7 @@ wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
Convert(buf, buffer);
return *this;
}
@@ -282,7 +316,7 @@ wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
Convert(buf, buffer);
return *this;
}
@@ -295,7 +329,7 @@ wchar_t buf[50];
size_t len = sizeof(buf) / sizeof(wchar_t);
Toa(v, buf, len);
AssignString(buf, buffer, false);
Convert(buf, buffer);
return *this;
}
@@ -307,7 +341,7 @@ TextStream<StringType> & TextStream<StringType>::operator<<(double v)
char buf[50];
sprintf(buf, "%f", v);
AssignString(buf, buffer, false);
Convert(buf, buffer);
return *this;
}
@@ -323,7 +357,7 @@ size_t len = sizeof(buf) / sizeof(wchar_t);
buf[1] = 'x';
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
AssignString(buf, buffer, false);
Convert(buf, buffer);
return *this;
}
@@ -332,7 +366,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
{
AssignString(buf, len, buffer, false);
Convert(buf, len, buffer);
return *this;
}
@@ -348,7 +382,7 @@ TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t
template<class StringType>
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
{
AssignString(buf, len, buffer, false);
Convert(buf, len, buffer);
return *this;
}
@@ -396,6 +430,124 @@ return *this;
template<class StringType>
void TextStream<StringType>::Convert(wchar_t c, std::string & dst)
{
PT::IntToUTF8((int)c, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(wchar_t c, std::wstring & dst)
{
dst += c;
}
template<class StringType>
void TextStream<StringType>::Convert(const char * src, size_t len, std::wstring & dst)
{
PT::UTF8ToWide(src, len, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const char * src, std::wstring & dst)
{
PT::UTF8ToWide(src, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const std::string & src, std::wstring & dst)
{
PT::UTF8ToWide(src, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::string & dst)
{
PT::WideToUTF8(src, len, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const wchar_t * src, std::string & dst)
{
PT::WideToUTF8(src, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const std::wstring & src, std::string & dst)
{
PT::WideToUTF8(src, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const char * src, size_t len, std::string & dst)
{
// we suppose that append is smart enough and we don't have to use reserve()
dst.append(src, len);
}
template<class StringType>
void TextStream<StringType>::Convert(const char * src, std::string & dst)
{
size_t len;
for(len=0 ; src[len] ; ++len){}
Convert(src, len, dst);
}
template<class StringType>
void TextStream<StringType>::Convert(const std::string & src, std::string & dst)
{
dst.append(src);
}
template<class StringType>
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::wstring & dst)
{
// we suppose that append is smart enough and we don't have to use reserve()
dst.append(src, len);
}
template<class StringType>
void TextStream<StringType>::Convert(const wchar_t * src, std::wstring & dst)
{
size_t len;
for(len=0 ; src[len] ; ++len){}
Convert(src, len, dst);
}
template<class StringType>
void TextStream<StringType>::Convert(const std::wstring & src, std::wstring & dst)
{
dst.append(src);
}
} // namespace Winix