2
0
mirror of https://github.com/boostorg/nowide.git synced 2026-02-23 15:52:19 +00:00

Some updates

This commit is contained in:
Artyom Beilis
2012-05-29 22:21:35 +03:00
parent 8c8c719c41
commit 81bf11eb10
12 changed files with 411 additions and 440 deletions

View File

@@ -1,33 +0,0 @@
cmake_minimum_required(VERSION 2.6)
include_directories(.)
if(NOT BOOST_PATH)
set(BOOST_PATH ${CMAKE_CURRENT_SOURCE_PATH})
endif()
include_directories(${BOOST_PATH})
enable_testing()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(BOOST_NOWIDE_TESTS
test_convert
test_env
test_stdio
test_fstream
test_iostream
)
foreach(TEST ${BOOST_NOWIDE_TESTS})
add_executable(${TEST} libs/nowide/test/${TEST}.cpp)
add_test(${TEST} ${TEST})
endforeach()
add_library(boost_nowide SHARED libs/nowide/src/iostream.cpp)
set_target_properties(boost_nowide PROPERTIES COMPILE_DEFINITIONS BOOST_NOWIDE_DYN_LINK)
set_target_properties(test_iostream PROPERTIES COMPILE_DEFINITIONS BOOST_NOWIDE_DYN_LINK)
target_link_libraries(test_iostream boost_nowide)
add_executable(test_system libs/nowide/test/test_system.cpp)
add_test(test_system_n test_system "-n")
add_test(test_system_w test_system "-w")

View File

@@ -16,112 +16,112 @@
#endif
namespace boost {
namespace nowide {
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
class args {
public:
args(int &,char **&) {}
args(int &,char **&,char **&){}
};
namespace nowide {
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
class args {
public:
args(int &,char **&) {}
args(int &,char **&,char **&){}
};
#else
#else
///
/// \brief args is a class that fixes standard main() function arguments and changes them to UTF-8 under
/// Microsoft Windows.
///
/// \note the class owns the memory of the newly allocated strings
///
class args {
public:
///
/// \brief args is a class that fixes standard main() function arguments and changes them to UTF-8 under
/// Microsoft Windows.
/// Fix command line agruments
///
/// \note the class owns the memory of the newly allocated strings
args(int &argc,char **&argv)
{
fix_args(argc,argv);
}
///
class args {
public:
///
/// Fix command line agruments
///
args(int &argc,char **&argv)
{
fix_args(argc,argv);
}
///
/// Fix command line agruments and environment
///
args(int &argc,char **&argv,char **&en)
{
fix_args(argc,argv);
fix_env(en);
}
private:
void fix_args(int &argc,char **&argv)
{
int wargc;
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(),&wargc);
if(!wargv) {
argc = 0;
static char *dummy = 0;
argv = &dummy;
return;
}
try{
args_.resize(wargc+1,0);
arg_values_.resize(wargc);
for(int i=0;i<wargc;i++) {
if(!arg_values_[i].convert(wargv[i])) {
wargc = i;
break;
}
args_[i] = arg_values_[i].c_str();
}
argc = wargc;
argv = &args_[0];
}
catch(...) {
LocalFree(wargv);
throw;
}
LocalFree(wargv);
}
void fix_env(char **&en)
{
/// Fix command line agruments and environment
///
args(int &argc,char **&argv,char **&en)
{
fix_args(argc,argv);
fix_env(en);
}
private:
void fix_args(int &argc,char **&argv)
{
int wargc;
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(),&wargc);
if(!wargv) {
argc = 0;
static char *dummy = 0;
en = &dummy;
wchar_t *wstrings = GetEnvironmentStringsW();
if(!wstrings)
return;
try {
wchar_t *wstrings_end = 0;
int count = 0;
for(wstrings_end = wstrings;*wstrings_end;wstrings_end+=wcslen(wstrings_end)+1)
count++;
if(env_.convert(wstrings,wstrings_end)) {
envp_.resize(count+1,0);
char *p=env_.c_str();
int pos = 0;
for(int i=0;i<count;i++) {
if(*p!='=')
envp_[pos++] = p;
p+=strlen(p)+1;
}
en = &envp_[0];
}
}
catch(...) {
FreeEnvironmentStringsW(wstrings);
throw;
}
FreeEnvironmentStringsW(wstrings);
argv = &dummy;
return;
}
try{
args_.resize(wargc+1,0);
arg_values_.resize(wargc);
for(int i=0;i<wargc;i++) {
if(!arg_values_[i].convert(wargv[i])) {
wargc = i;
break;
}
args_[i] = arg_values_[i].c_str();
}
argc = wargc;
argv = &args_[0];
}
catch(...) {
LocalFree(wargv);
throw;
}
LocalFree(wargv);
}
void fix_env(char **&en)
{
static char *dummy = 0;
en = &dummy;
wchar_t *wstrings = GetEnvironmentStringsW();
if(!wstrings)
return;
try {
wchar_t *wstrings_end = 0;
int count = 0;
for(wstrings_end = wstrings;*wstrings_end;wstrings_end+=wcslen(wstrings_end)+1)
count++;
if(env_.convert(wstrings,wstrings_end)) {
envp_.resize(count+1,0);
char *p=env_.c_str();
int pos = 0;
for(int i=0;i<count;i++) {
if(*p!='=')
envp_[pos++] = p;
p+=strlen(p)+1;
}
en = &envp_[0];
}
}
catch(...) {
FreeEnvironmentStringsW(wstrings);
throw;
}
FreeEnvironmentStringsW(wstrings);
std::vector<char *> args_;
std::vector<short_stackstring> arg_values_;
stackstring env_;
std::vector<char *> envp_;
};
}
#endif
std::vector<char *> args_;
std::vector<short_stackstring> arg_values_;
stackstring env_;
std::vector<char *> envp_;
};
} // nowide
} // boost
#endif
} // nowide
} // namespace boost
#endif
///

View File

@@ -20,106 +20,106 @@
#endif
namespace boost {
namespace nowide {
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using ::getenv;
using ::setenv;
using ::unsetenv;
using ::putenv;
#else
///
/// \brief UTF-8 aware getenv. Returns 0 if the variable is not set.
///
/// This function is not thread safe or reenterable as defined by the standard library
///
inline char *getenv(char const *key)
{
static stackstring value;
wshort_stackstring name;
if(!name.convert(key))
return 0;
namespace nowide {
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using ::getenv;
using ::setenv;
using ::unsetenv;
using ::putenv;
#else
///
/// \brief UTF-8 aware getenv. Returns 0 if the variable is not set.
///
/// This function is not thread safe or reenterable as defined by the standard library
///
inline char *getenv(char const *key)
{
static stackstring value;
wshort_stackstring name;
if(!name.convert(key))
return 0;
static const size_t buf_size = 64;
wchar_t buf[buf_size];
std::vector<wchar_t> tmp;
wchar_t *ptr = buf;
size_t n = GetEnvironmentVariableW(name.c_str(),buf,buf_size);
if(n == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
static const size_t buf_size = 64;
wchar_t buf[buf_size];
std::vector<wchar_t> tmp;
wchar_t *ptr = buf;
size_t n = GetEnvironmentVariableW(name.c_str(),buf,buf_size);
if(n == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return 0;
if(n >= buf_size) {
tmp.resize(n+1,L'\0');
n = GetEnvironmentVariableW(name.c_str(),&tmp[0],tmp.size() - 1);
// The size may have changed
if(n >= tmp.size() - 1)
return 0;
if(n >= buf_size) {
tmp.resize(n+1,L'\0');
n = GetEnvironmentVariableW(name.c_str(),&tmp[0],tmp.size() - 1);
// The size may have changed
if(n >= tmp.size() - 1)
return 0;
ptr = &tmp[0];
}
if(!value.convert(ptr))
return 0;
return value.c_str();
ptr = &tmp[0];
}
///
/// \brief UTF-8 aware setenv, \a key - the variable name, \a value is a new UTF-8 value,
///
/// if override is not 0, that the old value is always overridded, otherwise,
/// if the variable exists it remains unchanged
///
inline int setenv(char const *key,char const *value,int override)
{
wshort_stackstring name;
if(!name.convert(key))
return -1;
if(!override) {
wchar_t unused[2];
if(!(GetEnvironmentVariableW(name.c_str(),unused,2)==0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND))
return 0;
}
wstackstring wval;
if(!wval.convert(value))
return -1;
if(SetEnvironmentVariableW(name.c_str(),wval.c_str()))
return 0;
if(!value.convert(ptr))
return 0;
return value.c_str();
}
///
/// \brief UTF-8 aware setenv, \a key - the variable name, \a value is a new UTF-8 value,
///
/// if override is not 0, that the old value is always overridded, otherwise,
/// if the variable exists it remains unchanged
///
inline int setenv(char const *key,char const *value,int override)
{
wshort_stackstring name;
if(!name.convert(key))
return -1;
}
///
/// \brief Remove enviroment variable \a key
///
inline int unsetenv(char const *key)
{
wshort_stackstring name;
if(!name.convert(key))
return -1;
if(SetEnvironmentVariableW(name.c_str(),0))
if(!override) {
wchar_t unused[2];
if(!(GetEnvironmentVariableW(name.c_str(),unused,2)==0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND))
return 0;
return -1;
}
///
/// \brief UTF-8 aware putenv implementation, expects string in format KEY=VALUE
///
inline int putenv(char *string)
{
char const *key = string;
char const *key_end = string;
while(*key_end!='=' && key_end!='\0')
key_end++;
if(*key_end == '\0')
return -1;
wshort_stackstring wkey;
if(!wkey.convert(key,key_end))
return -1;
wstackstring wvalue;
if(!wvalue.convert(key_end+1))
return -1;
wstackstring wval;
if(!wval.convert(value))
return -1;
if(SetEnvironmentVariableW(name.c_str(),wval.c_str()))
return 0;
return -1;
}
///
/// \brief Remove enviroment variable \a key
///
inline int unsetenv(char const *key)
{
wshort_stackstring name;
if(!name.convert(key))
return -1;
if(SetEnvironmentVariableW(name.c_str(),0))
return 0;
return -1;
}
///
/// \brief UTF-8 aware putenv implementation, expects string in format KEY=VALUE
///
inline int putenv(char *string)
{
char const *key = string;
char const *key_end = string;
while(*key_end!='=' && key_end!='\0')
key_end++;
if(*key_end == '\0')
return -1;
wshort_stackstring wkey;
if(!wkey.convert(key,key_end))
return -1;
wstackstring wvalue;
if(!wvalue.convert(key_end+1))
return -1;
if(SetEnvironmentVariableW(wkey.c_str(),wvalue.c_str()))
return 0;
return -1;
}
#endif
} // nowide
} // boost
if(SetEnvironmentVariableW(wkey.c_str(),wvalue.c_str()))
return 0;
return -1;
}
#endif
} // nowide
} // namespace boost
#endif
///

View File

@@ -12,142 +12,142 @@
#include <boost/locale/encoding_utf.hpp>
namespace boost {
namespace nowide {
///
/// \brief Template function that converts a buffer of UTF sequence in range [source_begin,source_end)
/// to the output \a buffer of size \a buffer_size.
///
/// In case of success a NUL terminated string returned (buffer), otherwise 0 is returned.
///
/// If there is not enough room in the buffer or the source sequence contains invalid UTF
/// 0 is returned, and the contend of the buffer is undefined.
///
template<typename CharOut,typename CharIn>
CharOut *basic_convert(CharOut *buffer,size_t buffer_size,CharIn const *source_begin,CharIn const *source_end)
{
CharOut *rv = buffer;
if(buffer_size == 0)
return 0;
buffer_size --;
while(source_begin!=source_end) {
using namespace boost::locale::utf;
code_point c = utf_traits<CharIn>::template decode<CharIn const *>(source_begin,source_end);
if(c==illegal || c==incomplete) {
rv = 0;
break;
}
size_t width = utf_traits<CharOut>::width(c);
if(buffer_size < width) {
rv=0;
break;
}
buffer = utf_traits<CharOut>::template encode<CharOut *>(c,buffer);
buffer_size -= width;
namespace nowide {
///
/// \brief Template function that converts a buffer of UTF sequence in range [source_begin,source_end)
/// to the output \a buffer of size \a buffer_size.
///
/// In case of success a NUL terminated string returned (buffer), otherwise 0 is returned.
///
/// If there is not enough room in the buffer or the source sequence contains invalid UTF
/// 0 is returned, and the contend of the buffer is undefined.
///
template<typename CharOut,typename CharIn>
CharOut *basic_convert(CharOut *buffer,size_t buffer_size,CharIn const *source_begin,CharIn const *source_end)
{
CharOut *rv = buffer;
if(buffer_size == 0)
return 0;
buffer_size --;
while(source_begin!=source_end) {
using namespace boost::locale::utf;
code_point c = utf_traits<CharIn>::template decode<CharIn const *>(source_begin,source_end);
if(c==illegal || c==incomplete) {
rv = 0;
break;
}
*buffer++ = 0;
return rv;
}
/// \cond INTERNAL
namespace details {
//
// wcslen defined only in C99... So we will not use it
//
template<typename Char>
Char const *basic_strend(Char const *s)
{
while(*s)
s++;
return s;
size_t width = utf_traits<CharOut>::width(c);
if(buffer_size < width) {
rv=0;
break;
}
buffer = utf_traits<CharOut>::template encode<CharOut *>(c,buffer);
buffer_size -= width;
}
/// \endcond
*buffer++ = 0;
return rv;
}
///
/// Convert NUL terminated UTF source string to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline char *convert(char *output,size_t output_size,wchar_t const *source)
/// \cond INTERNAL
namespace details {
//
// wcslen defined only in C99... So we will not use it
//
template<typename Char>
Char const *basic_strend(Char const *s)
{
return basic_convert(output,output_size,source,details::basic_strend(source));
}
///
/// Convert UTF text in range [begin,end) to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline char *convert(char *output,size_t output_size,wchar_t const *begin,wchar_t const *end)
{
return basic_convert(output,output_size,begin,end);
}
///
/// Convert NUL terminated UTF source string to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline wchar_t *convert(wchar_t *output,size_t output_size,char const *source)
{
return basic_convert(output,output_size,source,details::basic_strend(source));
}
///
/// Convert UTF text in range [begin,end) to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline wchar_t *convert(wchar_t *output,size_t output_size,char const *begin,char const *end)
{
return basic_convert(output,output_size,begin,end);
while(*s)
s++;
return s;
}
}
/// \endcond
///
/// Convert NUL terminated UTF source string to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline char *convert(char *output,size_t output_size,wchar_t const *source)
{
return basic_convert(output,output_size,source,details::basic_strend(source));
}
///
/// Convert UTF text in range [begin,end) to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline char *convert(char *output,size_t output_size,wchar_t const *begin,wchar_t const *end)
{
return basic_convert(output,output_size,begin,end);
}
///
/// Convert NUL terminated UTF source string to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline wchar_t *convert(wchar_t *output,size_t output_size,char const *source)
{
return basic_convert(output,output_size,source,details::basic_strend(source));
}
///
/// Convert UTF text in range [begin,end) to NUL terminated \a output string of size at
/// most output_size (including NUL)
///
/// In case of surcess output is returned, if the input sequence is illegal,
/// or there is not enough room NULL is returned
///
inline wchar_t *convert(wchar_t *output,size_t output_size,char const *begin,char const *end)
{
return basic_convert(output,output_size,begin,end);
}
///
/// Convert between Wide - UTF-16/32 string and UTF-8 string.
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::string convert(wchar_t const *s)
{
return boost::locale::conv::utf_to_utf<char>(s);
}
///
/// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::wstring convert(char const *s)
{
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
///
/// Convert between Wide - UTF-16/32 string and UTF-8 string
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::string convert(std::wstring const &s)
{
return boost::locale::conv::utf_to_utf<char>(s);
}
///
/// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::wstring convert(std::string const &s)
{
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
///
/// Convert between Wide - UTF-16/32 string and UTF-8 string.
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::string convert(wchar_t const *s)
{
return boost::locale::conv::utf_to_utf<char>(s);
}
///
/// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::wstring convert(char const *s)
{
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
///
/// Convert between Wide - UTF-16/32 string and UTF-8 string
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::string convert(std::wstring const &s)
{
return boost::locale::conv::utf_to_utf<char>(s);
}
///
/// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform
///
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::wstring convert(std::string const &s)
{
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
} // nowide
} // boost
} // nowide
} // namespace boost
#endif
///

View File

@@ -90,7 +90,7 @@ inline int remove(char const *name)
}
#endif
} // nowide
} // boost
} // namespace boost
#ifdef BOOST_MSVC
#pragma warning(pop)

View File

@@ -396,7 +396,7 @@ namespace nowide {
#endif // windows
} // nowide
} // boost
} // namespace boost
#ifdef BOOST_MSVC
# pragma warning(pop)

View File

@@ -240,7 +240,7 @@ namespace nowide {
#endif
} // nowide
} // boost
} // namespace boost

View File

@@ -21,73 +21,73 @@
namespace boost {
namespace nowide {
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using std::cout;
using std::cerr;
using std::cin;
using std::clog;
#else
namespace nowide {
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using std::cout;
using std::cerr;
using std::cin;
using std::clog;
#else
/// \cond INTERNAL
namespace details {
class console_output_buffer;
class console_input_buffer;
/// \cond INTERNAL
namespace details {
class console_output_buffer;
class console_input_buffer;
class BOOST_NOWIDE_DECL winconsole_ostream : public std::ostream {
winconsole_ostream(winconsole_ostream const &);
void operator=(winconsole_ostream const &);
public:
winconsole_ostream(int fd);
~winconsole_ostream();
private:
boost::scoped_ptr<console_output_buffer> d;
};
class BOOST_NOWIDE_DECL winconsole_istream : public std::istream {
winconsole_istream(winconsole_istream const &);
void operator=(winconsole_istream const &);
public:
class BOOST_NOWIDE_DECL winconsole_ostream : public std::ostream {
winconsole_ostream(winconsole_ostream const &);
void operator=(winconsole_ostream const &);
public:
winconsole_ostream(int fd);
~winconsole_ostream();
private:
boost::scoped_ptr<console_output_buffer> d;
};
winconsole_istream();
~winconsole_istream();
private:
struct data;
boost::scoped_ptr<console_input_buffer> d;
};
} // details
/// \endcond
class BOOST_NOWIDE_DECL winconsole_istream : public std::istream {
winconsole_istream(winconsole_istream const &);
void operator=(winconsole_istream const &);
public:
winconsole_istream();
~winconsole_istream();
private:
struct data;
boost::scoped_ptr<console_input_buffer> d;
};
} // details
/// \endcond
///
/// \brief Same as std::cin, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_istream cin;
///
/// \brief Same as std::cout, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_ostream cout;
///
/// \brief Same as std::cerr, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_ostream cerr;
///
/// \brief Same as std::clog, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_ostream clog;
///
/// \brief Same as std::cin, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_istream cin;
///
/// \brief Same as std::cout, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_ostream cout;
///
/// \brief Same as std::cerr, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_ostream cerr;
///
/// \brief Same as std::clog, but uses UTF-8
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern BOOST_NOWIDE_DECL details::winconsole_ostream clog;
#endif
#endif
} // nowide
} // boost
} // nowide
} // namespace boost
#ifdef BOOST_MSVC
# pragma warning(pop)

View File

@@ -11,7 +11,7 @@
#include <string.h>
#include <algorithm>
namespace boost{
namespace boost {
namespace nowide {
///
@@ -30,34 +30,34 @@ public:
typedef CharIn input_char;
basic_stackstring(basic_stackstring const &other) :
mem_buffer_(0)
mem_buffer_(0)
{
clear();
if(other.mem_buffer_) {
size_t len = 0;
while(other.mem_buffer_[len])
len ++;
mem_buffer_ = new output_char[len + 1];
memcpy(mem_buffer_,other.mem_buffer_,sizeof(output_char) * (len+1));
}
else {
memcpy(buffer_,other.buffer_,buffer_size * sizeof(output_char));
}
clear();
if(other.mem_buffer_) {
size_t len = 0;
while(other.mem_buffer_[len])
len ++;
mem_buffer_ = new output_char[len + 1];
memcpy(mem_buffer_,other.mem_buffer_,sizeof(output_char) * (len+1));
}
else {
memcpy(buffer_,other.buffer_,buffer_size * sizeof(output_char));
}
}
void swap(basic_stackstring &other)
{
std::swap(mem_buffer_,other.mem_buffer_);
for(size_t i=0;i<buffer_size;i++)
std::swap(buffer_[i],other.buffer_[i]);
std::swap(mem_buffer_,other.mem_buffer_);
for(size_t i=0;i<buffer_size;i++)
std::swap(buffer_[i],other.buffer_[i]);
}
basic_stackstring &operator=(basic_stackstring const &other)
{
if(this != &other) {
basic_stackstring tmp(other);
swap(tmp);
}
return *this;
if(this != &other) {
basic_stackstring tmp(other);
swap(tmp);
}
return *this;
}
basic_stackstring() : mem_buffer_(0)
@@ -147,7 +147,7 @@ typedef basic_stackstring<char,wchar_t,16> short_stackstring;
} // nowide
} // boost
} // namespace boost
#endif
///

View File

@@ -38,8 +38,8 @@ inline int system(char const *cmd)
}
#endif
} // boost
} // nowide
} // namespace boost
#endif
///

View File

@@ -33,6 +33,10 @@ Boost.Nowide is a library implemented by Artyom Beilis
that make cross platform Unicode aware programming
easier.
The library provides an implementation of standard C and C++ library
functions, such that their inputs are UTF-8 aware on Windows without
requiring to use Wide API.
\subsection main_rationale Rationale
@@ -132,7 +136,7 @@ int main(int argc,char **argv)
}
int total_lines = 0
while(f) {
if(f.get() == '\n)
if(f.get() == '\n')
total_lines++;
}
f.close();
@@ -165,7 +169,7 @@ int main(int argc,char **argv)
}
int total_lines = 0
while(f) {
if(f.get() == '\n)
if(f.get() == '\n')
total_lines++;
}
f.close();

View File

@@ -254,7 +254,7 @@ namespace {
} // nowide
} // boost
} // namespace boost
#endif
///