diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc00fe4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/build/* +/nowide_standalone +/.vscode +/.vs +# Don't ignore Jamfiles, also in subfolders +!Jamfile.* diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 6246ffa..95d5632 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -12,7 +12,6 @@ project boost/nowide : source-location ../src : usage-requirements # pass these requirement to dependents (i.e. users) shared:BOOST_NOWIDE_DYN_LINK=1 - static:BOOST_NOWIDE_STATIC_LINK=1 ; SOURCES = iostream ; @@ -20,7 +19,6 @@ SOURCES = iostream ; lib boost_nowide : $(SOURCES).cpp : shared:BOOST_NOWIDE_DYN_LINK=1 - static:BOOST_NOWIDE_STATIC_LINK=1 ; boost-install boost_nowide ; diff --git a/doc/Doxyfile b/doc/Doxyfile index 95f09d5..36a6539 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -581,7 +581,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = ../include/boost/nowide ../include/boost/nowide/integration \ +INPUT = ../include/boost/nowide ../include/boost/nowide/integration \ . # This tag can be used to specify the character encoding of the source files @@ -599,7 +599,7 @@ INPUT_ENCODING = UTF-8 # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 -FILE_PATTERNS = *.hpp *.txt +FILE_PATTERNS = *.hpp *.txt # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. @@ -793,7 +793,7 @@ HTML_FILE_EXTENSION = .html # each generated HTML page. If it is left blank doxygen will generate a # standard header. -HTML_HEADER = +HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a diff --git a/doc/html/index.html b/doc/html/index.html index b81da7b..15d1db6 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -215,7 +215,7 @@ Custom API

The windows.h header

The library does not include the windows.h in order to prevent namespace pollution with numerous defines and types. Instead, the library defines the prototypes of the Win32 API functions.

-

However, you may request to use the windows.h header by defining BOOST_NOWIDE_USE_WINDOWS_H before including any of the Boost.Nowide headers

+

However, you may request to use the windows.h header by defining BOOST_USE_WINDOWS_H before including any of the Boost.Nowide headers

Integration with Boost.Filesystem

Boost.Filesystem supports selection of narrow encoding. Unfortunatelly the default narrow encoding on Windows isn't UTF-8, you can enable UTF-8 as default encoding on Boost.Filesystem by calling boost::nowide::nowide_filesystem() in the beginning of your program

diff --git a/doc/html/windows_8hpp_source.html b/doc/html/windows_8hpp_source.html index 63a4669..6120a27 100644 --- a/doc/html/windows_8hpp_source.html +++ b/doc/html/windows_8hpp_source.html @@ -61,7 +61,7 @@
10 
11 #include <stddef.h>
12 
-
13 #ifdef BOOST_NOWIDE_USE_WINDOWS_H
+
13 #ifdef BOOST_USE_WINDOWS_H
14 #include <windows.h>
15 #else
16 
diff --git a/doc/main.txt b/doc/main.txt index f47a6b9..1c4fba2 100644 --- a/doc/main.txt +++ b/doc/main.txt @@ -13,19 +13,19 @@ Table of Contents: -- \ref main -- \ref main_rationale - - \ref main_the_problem - - \ref main_the_solution - - \ref main_wide - - \ref main_reading +- \ref main +- \ref main_rationale + - \ref main_the_problem + - \ref main_the_solution + - \ref main_wide + - \ref main_reading - \ref using - \ref using_standard - \ref using_custom - \ref using_integration -- \ref technical - - \ref technical_imple - - \ref technical_cio +- \ref technical + - \ref technical_imple + - \ref technical_cio - \ref qna - \ref standalone_version - \ref sources @@ -45,7 +45,7 @@ requiring to use Wide API. \section main_rationale Rationale \subsection main_the_problem The Problem -Consider a simple application that splits a big file into chunks, such that +Consider a simple application that splits a big file into chunks, such that they can be sent by e-mail. It requires doing a few very simple tasks: - Access command line arguments: int main(int argc,char **argv) @@ -57,7 +57,7 @@ Unfortunately it is impossible to implement this simple task in plain C++ if the file names contain non-ASCII characters. The simple program that uses the API would work on the systems that use UTF-8 -internally -- the vast majority of Unix-Line operating systems: Linux, Mac OS X, +internally -- the vast majority of Unix-Line operating systems: Linux, Mac OS X, Solaris, BSD. But it would fail on files like War and Peace - Война и мир - מלחמה ושלום.zip under Microsoft Windows because the native Windows Unicode aware API is Wide-API -- UTF-16. @@ -65,7 +65,7 @@ This incredibly trivial task is very hard to implement in a cross platform manne \subsection main_the_solution The Solution -Boost.Nowide provides a set of standard library functions that are UTF-8 aware and +Boost.Nowide provides a set of standard library functions that are UTF-8 aware and makes Unicode aware programming easier. The library provides: @@ -91,10 +91,10 @@ The library provides: - \c cout - \c cerr - \c clog - - \c cin + - \c cin -\subsection main_wide Why Not Narrow and Wide? +\subsection main_wide Why Not Narrow and Wide? Why not provide both Wide and Narrow implementations so the developer can choose to use Wide characters on Unix-like platforms? @@ -183,7 +183,7 @@ int main(int argc,char **argv) \endcode This very simple and straightforward approach helps writing Unicode aware programs. - + \subsection using_custom Custom API Of course, this simple set of functions does not cover all needs. If you need @@ -197,7 +197,7 @@ CopyFileW( boost::nowide::widen(existing_file).c_str(), TRUE); \endcode -The conversion is done at the last stage, and you continue using UTF-8 +The conversion is done at the last stage, and you continue using UTF-8 strings everywhere else. You only switch to the Wide API at glue points. \c boost::nowide::widen returns \c std::string. Sometimes @@ -226,20 +226,20 @@ buffers. If the string is longer, they fall back to memory allocation. The library does not include the \c windows.h in order to prevent namespace pollution with numerous defines and types. Instead, the library defines the prototypes of the Win32 API functions. -However, you may request to use the \c windows.h header by defining \c BOOST_NOWIDE_USE_WINDOWS_H +However, you may request to use the \c windows.h header by defining \c BOOST_USE_WINDOWS_H before including any of the Boost.Nowide headers \subsection using_integration Integration with Boost.Filesystem Boost.Filesystem supports selection of narrow encoding. Unfortunatelly the default narrow encoding on Windows isn't UTF-8, you can enable UTF-8 as default encoding on Boost.Filesystem -by calling `boost::nowide::nowide_filesystem()` in the beginning of your program +by calling `boost::nowide::nowide_filesystem()` in the beginning of your program \section technical Technical Details \subsection technical_imple Windows vs POSIX For Microsoft Windows, the library provides UTF-8 aware variants of some \c std:: functions in the \c boost::nowide namespace. -For example, \c std::fopen becomes \c boost::nowide::fopen. +For example, \c std::fopen becomes \c boost::nowide::fopen. Under POSIX platforms, the functions in boost::nowide are aliases of their standard library counterparts: @@ -274,7 +274,7 @@ fonts are used the Unicode aware input and output works as intended. A: It is inherently incorrect to convert strings to/from locale encodings on POSIX platforms. -You can create a file named "\xFF\xFF.txt" (invalid UTF-8), remove it, pass its name as a parameter to a program +You can create a file named "\xFF\xFF.txt" (invalid UTF-8), remove it, pass its name as a parameter to a program and it would work whether the current locale is UTF-8 or not. Also, changing the locale from let's say \c en_US.UTF-8 to \c en_US.ISO-8859-1 would not magically change all files in the OS or the strings a user may pass to the program (which is different on Windows) @@ -283,7 +283,7 @@ POSIX OSs treat strings as \c NULL terminated cookies. So altering their content according to the locale would actually lead to incorrect behavior. - + For example, this is a naive implementation of a standard program "rm" \code diff --git a/include/boost/nowide/args.hpp b/include/boost/nowide/args.hpp index 180fb6d..514c0a7 100644 --- a/include/boost/nowide/args.hpp +++ b/include/boost/nowide/args.hpp @@ -28,7 +28,7 @@ namespace nowide { #else /// - /// \brief args is a class that fixes standard main() function arguments and changes them to UTF-8 under + /// \brief args is a class that fixes standard main() function arguments and changes them to UTF-8 under /// Microsoft Windows. /// /// The class uses \c GetCommandLineW(), \c CommandLineToArgvW() and \c GetEnvironmentStringsW() @@ -41,9 +41,9 @@ namespace nowide { /// class args { public: - + /// - /// Fix command line agruments + /// Fix command line agruments /// args(int &argc,char **&argv) : old_argc_(argc), @@ -78,10 +78,10 @@ namespace nowide { *old_argc_ptr_ = old_argc_; if(old_argv_ptr_) *old_argv_ptr_ = old_argv_; - if(old_env_ptr_) + if(old_env_ptr_) *old_env_ptr_ = old_env_; } - private: + private: void fix_args(int &argc,char **&argv) { int wargc; @@ -92,10 +92,10 @@ namespace nowide { argv = &dummy; return; } - try{ + try{ args_.resize(wargc+1,0); arg_values_.resize(wargc); - for(int i=0;i #include -#ifndef BOOST_SYMBOL_VISIBLE -# define BOOST_SYMBOL_VISIBLE -#endif - -#ifdef BOOST_HAS_DECLSPEC -# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_NOWIDE_DYN_LINK) -# ifdef BOOST_NOWIDE_SOURCE -# define BOOST_NOWIDE_DECL BOOST_SYMBOL_EXPORT -# else -# define BOOST_NOWIDE_DECL BOOST_SYMBOL_IMPORT -# endif // BOOST_NOWIDE_SOURCE -# endif // DYN_LINK -#endif // BOOST_HAS_DECLSPEC - -#ifndef BOOST_NOWIDE_DECL -# define BOOST_NOWIDE_DECL -#endif +#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_NOWIDE_DYN_LINK) +# ifdef BOOST_NOWIDE_SOURCE +# define BOOST_NOWIDE_DECL BOOST_SYMBOL_EXPORT +# else +# define BOOST_NOWIDE_DECL BOOST_SYMBOL_IMPORT +# endif // BOOST_NOWIDE_SOURCE +#else +# define BOOST_NOWIDE_DECL +#endif // DYN_LINK // -// Automatically link to the correct build variant where possible. -// +// Automatically link to the correct build variant where possible. +// #if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_NOWIDE_NO_LIB) && !defined(BOOST_NOWIDE_SOURCE) // // Set the name of our library, this will get undef'ed by auto_link.hpp diff --git a/include/boost/nowide/convert.hpp b/include/boost/nowide/convert.hpp index 4240f09..138d5ae 100644 --- a/include/boost/nowide/convert.hpp +++ b/include/boost/nowide/convert.hpp @@ -57,7 +57,7 @@ namespace nowide { std::basic_string basic_convert(CharIn const *begin,CharIn const *end) { - + std::basic_string result; result.reserve(end-begin); typedef std::back_insert_iterator > inserter_type; @@ -73,7 +73,7 @@ namespace nowide { } return result; } - + /// \cond INTERNAL namespace details { // @@ -88,7 +88,7 @@ namespace nowide { } } /// \endcond - + /// /// \brief Template function that converts a string \a s from one type of UTF to another UTF and returns a string containing converted value /// @@ -117,9 +117,9 @@ namespace nowide { /// /// Convert NULL terminated UTF source string to NULL terminated \a output string of size at /// most output_size (including NULL) - /// + /// /// In case of success output is returned, if the input sequence is illegal, - /// or there is not enough room NULL is returned + /// or there is not enough room NULL is returned /// inline char *narrow(char *output,size_t output_size,wchar_t const *source) { @@ -128,9 +128,9 @@ namespace nowide { /// /// Convert UTF text in range [begin,end) to NULL terminated \a output string of size at /// most output_size (including NULL) - /// + /// /// In case of success output is returned, if the input sequence is illegal, - /// or there is not enough room NULL is returned + /// or there is not enough room NULL is returned /// inline char *narrow(char *output,size_t output_size,wchar_t const *begin,wchar_t const *end) { @@ -139,9 +139,9 @@ namespace nowide { /// /// Convert NULL terminated UTF source string to NULL terminated \a output string of size at /// most output_size (including NULL) - /// + /// /// In case of success output is returned, if the input sequence is illegal, - /// or there is not enough room NULL is returned + /// or there is not enough room NULL is returned /// inline wchar_t *widen(wchar_t *output,size_t output_size,char const *source) { @@ -150,9 +150,9 @@ namespace nowide { /// /// Convert UTF text in range [begin,end) to NULL terminated \a output string of size at /// most output_size (including NULL) - /// + /// /// In case of success output is returned, if the input sequence is illegal, - /// or there is not enough room NULL is returned + /// or there is not enough room NULL is returned /// inline wchar_t *widen(wchar_t *output,size_t output_size,char const *begin,char const *end) { @@ -170,7 +170,7 @@ namespace nowide { return basic_convert(s); } /// - /// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform + /// Convert between UTF-8 and UTF-16 string /// /// boost::locale::conv::conversion_error is thrown in a case of a error /// @@ -183,16 +183,16 @@ namespace nowide { /// /// boost::locale::conv::conversion_error is thrown in a case of a error /// - inline std::string narrow(std::wstring const &s) + inline std::string narrow(std::wstring const &s) { return basic_convert(s); } /// - /// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform + /// Convert between UTF-8 and UTF-16 string /// /// boost::locale::conv::conversion_error is thrown in a case of a error /// - inline std::wstring widen(std::string const &s) + inline std::wstring widen(std::string const &s) { return basic_convert(s); } diff --git a/include/boost/nowide/filebuf.hpp b/include/boost/nowide/filebuf.hpp index 6b54ff9..c4be9d5 100644 --- a/include/boost/nowide/filebuf.hpp +++ b/include/boost/nowide/filebuf.hpp @@ -26,7 +26,7 @@ namespace nowide { using std::basic_filebuf; using std::filebuf; #else // Windows - + /// /// \brief This forward declaration defined the basic_filebuf type. /// @@ -35,7 +35,7 @@ namespace nowide { /// template > class basic_filebuf; - + /// /// \brief This is implementation of std::filebuf /// @@ -48,7 +48,7 @@ namespace nowide { /// /// Creates new filebuf /// - basic_filebuf() : + basic_filebuf() : buffer_size_(4), buffer_(0), file_(0), @@ -58,7 +58,7 @@ namespace nowide { setg(0,0,0); setp(0,0); } - + virtual ~basic_filebuf() { if(file_) { @@ -68,7 +68,7 @@ namespace nowide { if(own_ && buffer_) delete [] buffer_; } - + /// /// Same as std::filebuf::open but s is UTF-8 string /// @@ -139,7 +139,7 @@ namespace nowide { } } protected: - + virtual std::streambuf *setbuf(char *s,std::streamsize n) { if(!buffer_ && n>=0) { @@ -149,68 +149,12 @@ namespace nowide { } return this; } - -#ifdef BOOST_NOWIDE_DEBUG_FILEBUF - void print_buf(char *b,char *p,char *e) - { - std::cerr << "-- Is Null: " << (b==0) << std::endl;; - if(b==0) - return; - if(e != 0) - std::cerr << "-- Total: " << e - b <<" offset from start " << p - b << std::endl; - else - std::cerr << "-- Total: " << p - b << std::endl; - - std::cerr << "-- ["; - for(char *ptr = b;ptrprint_state(); - } - ~print_guard() - { - std::cerr << "Out: " << f << std::endl; - self->print_state(); - } - basic_filebuf *self; - char const *f; - }; -#else -#endif - int overflow(int c) { -#ifdef BOOST_NOWIDE_DEBUG_FILEBUF - print_guard g(this,__FUNCTION__); -#endif if(!file_) return EOF; - + if(fixg() < 0) return EOF; @@ -234,8 +178,8 @@ namespace nowide { } return 0; } - - + + int sync() { return overflow(EOF); @@ -243,9 +187,6 @@ namespace nowide { int underflow() { -#ifdef BOOST_NOWIDE_DEBUG_FILEBUF - print_guard g(this,__FUNCTION__); -#endif if(!file_) return EOF; if(fixp() < 0) @@ -276,9 +217,6 @@ namespace nowide { std::ios_base::seekdir seekdir, std::ios_base::openmode /*m*/) { -#ifdef BOOST_NOWIDE_DEBUG_FILEBUF - print_guard g(this,__FUNCTION__); -#endif if(!file_) return EOF; if(fixp() < 0 || fixg() < 0) @@ -315,7 +253,7 @@ namespace nowide { setg(0,0,0); return 0; } - + int fixp() { if(pptr()!=0) { @@ -335,8 +273,8 @@ namespace nowide { } file_ = f; } - - + + static wchar_t const *get_mode(std::ios_base::openmode mode) { // @@ -381,9 +319,9 @@ namespace nowide { return L"a+b"; if(mode == (std::ios_base::binary | std::ios_base::in | std::ios_base::app)) return L"a+b"; - return 0; + return 0; } - + size_t buffer_size_; char *buffer_; FILE *file_; @@ -391,14 +329,14 @@ namespace nowide { char last_char_; std::ios::openmode mode_; }; - + /// /// \brief Convinience typedef /// typedef basic_filebuf filebuf; - + #endif // windows - + } // nowide } // namespace boost diff --git a/include/boost/nowide/fstream.hpp b/include/boost/nowide/fstream.hpp index 10265e5..dbcd214 100644 --- a/include/boost/nowide/fstream.hpp +++ b/include/boost/nowide/fstream.hpp @@ -43,30 +43,30 @@ namespace nowide { typedef basic_filebuf internal_buffer_type; typedef std::basic_istream internal_stream_type; - basic_ifstream() : + basic_ifstream() : internal_stream_type(0) { buf_.reset(new internal_buffer_type()); std::ios::rdbuf(buf_.get()); } - - explicit basic_ifstream(char const *file_name,std::ios_base::openmode mode = std::ios_base::in) : - internal_stream_type(0) + + explicit basic_ifstream(char const *file_name,std::ios_base::openmode mode = std::ios_base::in) : + internal_stream_type(0) { buf_.reset(new internal_buffer_type()); std::ios::rdbuf(buf_.get()); open(file_name,mode); } - explicit basic_ifstream(std::string const &file_name,std::ios_base::openmode mode = std::ios_base::in) : - internal_stream_type(0) + explicit basic_ifstream(std::string const &file_name,std::ios_base::openmode mode = std::ios_base::in) : + internal_stream_type(0) { buf_.reset(new internal_buffer_type()); std::ios::rdbuf(buf_.get()); open(file_name,mode); } - + void open(std::string const &file_name,std::ios_base::openmode mode = std::ios_base::in) { open(file_name.c_str(),mode); @@ -104,7 +104,7 @@ namespace nowide { { buf_->close(); } - + private: boost::scoped_ptr buf_; }; @@ -120,7 +120,7 @@ namespace nowide { typedef basic_filebuf internal_buffer_type; typedef std::basic_ostream internal_stream_type; - basic_ofstream() : + basic_ofstream() : internal_stream_type(0) { buf_.reset(new internal_buffer_type()); @@ -177,7 +177,7 @@ namespace nowide { { buf_->close(); } - + private: boost::scoped_ptr buf_; }; @@ -193,7 +193,7 @@ namespace nowide { typedef basic_filebuf internal_buffer_type; typedef std::basic_iostream internal_stream_type; - basic_fstream() : + basic_fstream() : internal_stream_type(0) { buf_.reset(new internal_buffer_type()); @@ -250,7 +250,7 @@ namespace nowide { { buf_->close(); } - + private: boost::scoped_ptr buf_; }; diff --git a/include/boost/nowide/iostream.hpp b/include/boost/nowide/iostream.hpp index 6ab004a..0bc8643 100644 --- a/include/boost/nowide/iostream.hpp +++ b/include/boost/nowide/iostream.hpp @@ -14,6 +14,8 @@ #include #include +#include // must be the last #include + #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable : 4251) @@ -28,12 +30,12 @@ namespace nowide { using std::cin; using std::clog; #else - - /// \cond INTERNAL + + /// \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 &); @@ -48,40 +50,39 @@ namespace nowide { winconsole_istream(winconsole_istream const &); void operator=(winconsole_istream const &); public: - + winconsole_istream(); ~winconsole_istream(); private: - struct data; boost::scoped_ptr d; }; - } // details - + } // 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; #endif @@ -93,6 +94,7 @@ namespace nowide { # pragma warning(pop) #endif +#include // pops abi_prefix.hpp pragmas #endif /// diff --git a/include/boost/nowide/stackstring.hpp b/include/boost/nowide/stackstring.hpp index 0317842..f201d4e 100644 --- a/include/boost/nowide/stackstring.hpp +++ b/include/boost/nowide/stackstring.hpp @@ -21,16 +21,16 @@ namespace nowide { /// and allocated a buffer on the heap if the size of the buffer is too small /// /// If invalid UTF charracters are detected they are replaced with U+FFFD substutution charracter -/// +/// template class basic_stackstring { public: - - static const size_t buffer_size = BufferSize; + + static const size_t buffer_size = BufferSize; typedef CharOut output_char; typedef CharIn input_char; - basic_stackstring(basic_stackstring const &other) : + basic_stackstring(basic_stackstring const &other) : mem_buffer_(0) { clear(); @@ -45,7 +45,7 @@ public: std::memcpy(buffer_,other.buffer_,buffer_size * sizeof(output_char)); } } - + void swap(basic_stackstring &other) { std::swap(mem_buffer_,other.mem_buffer_); @@ -56,7 +56,7 @@ public: { if(this != &other) { basic_stackstring tmp(other); - swap(tmp); + swap(tmp); } return *this; } @@ -116,11 +116,11 @@ private: { if(insize <= outsize) return in; - else if(insize == 2 && outsize == 1) + else if(insize == 2 && outsize == 1) return 3 * in; - else if(insize == 4 && outsize == 1) + else if(insize == 4 && outsize == 1) return 4 * in; - else // if(insize == 4 && outsize == 2) + else // if(insize == 4 && outsize == 2) return 2 * in; } output_char buffer_[buffer_size]; diff --git a/include/boost/nowide/utf8_codecvt.hpp b/include/boost/nowide/utf8_codecvt.hpp index 1f711ab..54a2783 100644 --- a/include/boost/nowide/utf8_codecvt.hpp +++ b/include/boost/nowide/utf8_codecvt.hpp @@ -44,9 +44,6 @@ protected: virtual std::codecvt_base::result do_unshift(std::mbstate_t &s,char *from,char * /*to*/,char *&next) const { boost::uint16_t &state = *reinterpret_cast(&s); -#ifdef DEBUG_CODECVT - std::cout << "Entering unshift " << std::hex << state << std::dec << std::endl; -#endif if(state != 0) return std::codecvt_base::error; next=from; @@ -130,11 +127,6 @@ protected: boost::uint16_t &state = *reinterpret_cast(&std_state); while(to < to_end && from < from_end) { -#ifdef DEBUG_CODECVT - std::cout << "Entering IN--------------" << std::endl; - std::cout << "State " << std::hex << state <::decode(from,from_end); @@ -181,25 +173,6 @@ protected: to_next=to; if(r == std::codecvt_base::ok && (from!=from_end || state!=0)) r = std::codecvt_base::partial; -#ifdef DEBUG_CODECVT - std::cout << "Returning "; - switch(r) { - case std::codecvt_base::ok: - std::cout << "ok" << std::endl; - break; - case std::codecvt_base::partial: - std::cout << "partial" << std::endl; - break; - case std::codecvt_base::error: - std::cout << "error" << std::endl; - break; - default: - std::cout << "other" << std::endl; - break; - } - std::cout << "State " << std::hex << state <(&std_state); while(to < to_end && from < from_end) { -#ifdef DEBUG_CODECVT - std::cout << "Entering OUT --------------" << std::endl; - std::cout << "State " << std::hex << state <::decode(from,from_end); - + if(ch==boost::locale::utf::illegal) { ch = BOOST_NOWIDE_REPLACEMENT_CHARACTER; } @@ -411,25 +355,6 @@ protected: to_next=to; if(r == std::codecvt_base::ok && from!=from_end) r = std::codecvt_base::partial; -#ifdef DEBUG_CODECVT - std::cout << "Returning "; - switch(r) { - case std::codecvt_base::ok: - std::cout << "ok" << std::endl; - break; - case std::codecvt_base::partial: - std::cout << "partial" << std::endl; - break; - case std::codecvt_base::error: - std::cout << "error" << std::endl; - break; - default: - std::cout << "other" << std::endl; - break; - } - std::cout << "State " << std::hex << state < #else // -// These are function prototypes... Allow to to include windows.h +// These are function prototypes... Allow to avoid including windows.h // extern "C" { @@ -28,7 +28,7 @@ __declspec(dllimport) unsigned long __stdcall GetEnvironmentVariableW(wchar_t } -#endif +#endif diff --git a/src/iostream.cpp b/src/iostream.cpp index c71a4e5..8c3691f 100644 --- a/src/iostream.cpp +++ b/src/iostream.cpp @@ -7,12 +7,21 @@ // #define BOOST_NOWIDE_SOURCE #include + +#ifndef BOOST_WINDOWS + +namespace boost { +namespace nowide { + BOOST_NOWIDE_DECL void dummy_exported_function(){} +} +} + +#else + #include #include #include -#ifdef BOOST_WINDOWS - #ifndef NOMINMAX # define NOMINMAX #endif @@ -52,7 +61,7 @@ namespace details { return -1; int n = static_cast(pptr() - pbase()); int r = 0; - + if(n > 0 && (r=write(pbase(),n)) < 0) return -1; if(r < n) { @@ -65,7 +74,7 @@ namespace details { return 0; } private: - + int write(char const *p,int n) { namespace uf = boost::locale::utf; @@ -87,33 +96,33 @@ namespace details { return -1; return static_cast(decoded); } - + static const int buffer_size = 1024; char buffer_[buffer_size]; wchar_t wbuffer_[buffer_size]; // for null HANDLE handle_; }; - + class console_input_buffer: public std::streambuf { public: console_input_buffer(HANDLE h) : handle_(h), wsize_(0) { - } - + } + protected: int pbackfail(int c) { if(c==traits_type::eof()) return traits_type::eof(); - + if(gptr()!=eback()) { gbump(-1); *gptr() = c; return 0; } - + if(pback_buffer_.empty()) { pback_buffer_.resize(4); char *b = &pback_buffer_[0]; @@ -133,7 +142,7 @@ namespace details { *p = c; setg(b,p,e); } - + return 0; } @@ -143,16 +152,16 @@ namespace details { return -1; if(!pback_buffer_.empty()) pback_buffer_.clear(); - + size_t n = read(); setg(buffer_,buffer_,buffer_+n); if(n == 0) return traits_type::eof(); return std::char_traits::to_int_type(*gptr()); } - + private: - + size_t read() { namespace uf = boost::locale::utf; @@ -171,18 +180,18 @@ namespace details { out = uf::utf_traits::encode(c,out); wsize_ = e-p; } - + if(c==uf::illegal) return 0; - - + + if(c==uf::incomplete) { std::memmove(b,e-wsize_,sizeof(wchar_t)*wsize_); } - + return out - buffer_; } - + static const size_t buffer_size = 1024 * 3; static const size_t wbuffer_size = 1024; char buffer_[buffer_size]; @@ -230,18 +239,18 @@ namespace details { std::istream::rdbuf(std::cin.rdbuf()); } } - + winconsole_istream::~winconsole_istream() { } - + } // details - -BOOST_NOWIDE_DECL details::winconsole_istream cin; -BOOST_NOWIDE_DECL details::winconsole_ostream cout(1); -BOOST_NOWIDE_DECL details::winconsole_ostream cerr(2); -BOOST_NOWIDE_DECL details::winconsole_ostream clog(2); - + +details::winconsole_istream cin; +details::winconsole_ostream cout(1); +details::winconsole_ostream cerr(2); +details::winconsole_ostream clog(2); + namespace { struct initialize { initialize() @@ -254,7 +263,7 @@ namespace { } - + } // nowide } // namespace boost diff --git a/standalone/config.hpp b/standalone/config.hpp index 89c1f51..b8aca3e 100644 --- a/standalone/config.hpp +++ b/standalone/config.hpp @@ -25,7 +25,7 @@ # define NOWIDE_DECL __declspec(dllimport) # endif //NOWIDE_SOURCE # endif // DYN_LINK -#endif +#endif #ifndef NOWIDE_DECL # define NOWIDE_DECL diff --git a/standalone/encoding_errors.hpp b/standalone/encoding_errors.hpp index 631e410..52d219e 100644 --- a/standalone/encoding_errors.hpp +++ b/standalone/encoding_errors.hpp @@ -20,7 +20,7 @@ namespace nowide { namespace conv { /// - /// \addtogroup codepage + /// \addtogroup codepage /// /// @{ diff --git a/standalone/run_convert_and_build.sh b/standalone/run_convert_and_build.sh index 6f3dce3..75e4c66 100755 --- a/standalone/run_convert_and_build.sh +++ b/standalone/run_convert_and_build.sh @@ -5,7 +5,7 @@ rm -fr /tmp/nwlin /tmp/nw pushd . ./convert && mkdir nowide/build && cd nowide/build && cmake -DCMAKE_TOOLCHAIN_FILE=../../MinGW.cmake -DCMAKE_INSTALL_PREFIX=/tmp/nw -DRUN_WITH_WINE=ON .. && make && make test && make install -popd +popd pushd . ./convert && mkdir nowide/build && cd nowide/build && cmake -DLIBDIR=lin64 -DCMAKE_INSTALL_PREFIX=/tmp/nwlin .. && make && make test && make install diff --git a/standalone/scoped_ptr.hpp b/standalone/scoped_ptr.hpp index 1d57e78..497fa1f 100644 --- a/standalone/scoped_ptr.hpp +++ b/standalone/scoped_ptr.hpp @@ -2,7 +2,7 @@ #define NOWIDE_SCOPED_PTR_HPP // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. -// Copyright (c) 2001, 2002 Peter Dimov, +// Copyright (c) 2001, 2002 Peter Dimov, // Copyright (C) 2012 Artyom Beilis // // Distributed under the Boost Software License, Version 1.0. (See diff --git a/standalone/utf.hpp b/standalone/utf.hpp index 783b7e6..86236ed 100644 --- a/standalone/utf.hpp +++ b/standalone/utf.hpp @@ -24,7 +24,7 @@ namespace utf { namespace nowide { /// -/// \brief Namespace that holds basic operations on UTF encoded sequences +/// \brief Namespace that holds basic operations on UTF encoded sequences /// /// All functions defined in this namespace do not require linking with Boost.Locale library /// @@ -89,7 +89,7 @@ namespace utf { /// Postconditions /// /// - p points to the last consumed character - /// + /// template static code_point decode(Iterator &p,Iterator e); @@ -113,7 +113,7 @@ namespace utf { /// Get the size of the trail part of variable length encoded sequence. /// /// Returns -1 if C is not valid lead character - /// + /// static int trail_length(char_type c); /// /// Returns true if c is trail code unit, always false for UTF-32 @@ -127,11 +127,11 @@ namespace utf { /// /// Convert valid Unicode code point \a value to the UTF sequence. /// - /// Requirements: + /// Requirements: /// /// - \a value is valid code point /// - \a out is an output iterator should be able to accept at least width(value) units - /// + /// /// Returns the iterator past the last written code unit. /// template @@ -144,7 +144,7 @@ namespace utf { template static code_point decode_valid(Iterator &p); }; - + #else template @@ -154,8 +154,8 @@ namespace utf { struct utf_traits { typedef CharType char_type; - - static int trail_length(char_type ci) + + static int trail_length(char_type ci) { unsigned char c = ci; if(c < 128) @@ -170,7 +170,7 @@ namespace utf { return 3; return -1; } - + static const int max_width = 4; static int width(code_point value) @@ -199,7 +199,7 @@ namespace utf { { return !is_trail(ci); } - + template static code_point decode(Iterator &p,Iterator e) { @@ -220,7 +220,7 @@ namespace utf { // if(trail_size == 0) return lead; - + code_point c = lead & ((1<<(6-trail_size))-1); // Read the rest @@ -261,7 +261,7 @@ namespace utf { return c; } - + template static code_point decode_valid(Iterator &p) { @@ -277,7 +277,7 @@ namespace utf { trail_size = 2; else trail_size = 3; - + code_point c = lead & ((1<<(6-trail_size))-1); switch(trail_size) { @@ -408,7 +408,7 @@ namespace utf { } }; // utf16; - + template struct utf_traits { typedef CharType char_type; diff --git a/test/test_codecvt.cpp b/test/test_codecvt.cpp index 3cfac58..502d85d 100644 --- a/test/test_codecvt.cpp +++ b/test/test_codecvt.cpp @@ -209,11 +209,11 @@ void test_codecvt_err() TEST(to[2] == L'\uFFFD'); TEST(to[3] == L'\u05e9'); } - } - + } + std::cout << "- UTF-16/32" << std::endl; { - + char buf[32]; char *to=buf; char *to_end = buf+32; @@ -230,17 +230,17 @@ void test_codecvt_err() TEST(to_next == to + 4); TEST(std::memcmp(to,"1\xEF\xBF\xBD",4)==0); } - } - + } + } std::wstring codecvt_to_wide(std::string const &s) { std::locale l(std::locale::classic(),new boost::nowide::utf8_codecvt()); - + cvt_type const &cvt = std::use_facet(l); std::vector output(s.size()+1); - + std::mbstate_t mb=std::mbstate_t(); char const *from=s.c_str(); char const *from_end = from + s.size(); @@ -250,7 +250,7 @@ std::wstring codecvt_to_wide(std::string const &s) wchar_t *to=&buf[0]; wchar_t *to_end = to + buf.size(); wchar_t *to_next = to; - + TEST(cvt.in(mb,from,from_end,from_next,to,to_end,to_next)==cvt_type::ok); std::wstring res(to,to_next); @@ -262,10 +262,10 @@ std::wstring codecvt_to_wide(std::string const &s) std::string codecvt_to_narrow(std::wstring const &s) { std::locale l(std::locale::classic(),new boost::nowide::utf8_codecvt()); - + cvt_type const &cvt = std::use_facet(l); std::vector output(s.size()+1); - + std::mbstate_t mb=std::mbstate_t(); wchar_t const *from=s.c_str(); wchar_t const *from_end = from + s.size(); @@ -275,7 +275,7 @@ std::string codecvt_to_narrow(std::wstring const &s) char *to=&buf[0]; char *to_end = to + buf.size(); char *to_next = to; - + TEST(cvt.out(mb,from,from_end,from_next,to,to_end,to_next)==cvt_type::ok); std::string res(to,to_next); @@ -291,12 +291,12 @@ void test_codecvt_subst() } int main() -{ +{ try { test_codecvt_conv(); test_codecvt_err(); test_codecvt_subst(); - + } catch(std::exception const &e) { std::cerr << "Failed : " << e.what() << std::endl; diff --git a/test/test_fstream.cpp b/test/test_fstream.cpp index 658944f..255bba9 100644 --- a/test/test_fstream.cpp +++ b/test/test_fstream.cpp @@ -14,7 +14,6 @@ #include #include #include - #include "test.hpp" @@ -24,7 +23,7 @@ int main() std::string example_str = prefix + "\xd7\xa9-\xd0\xbc-\xce\xbd" ".txt"; std::wstring wexample_str = boost::nowide::widen( prefix ) + L"\u05e9-\u043c-\u03bd.txt"; - + char const * example = example_str.c_str(); #ifdef BOOST_WINDOWS wchar_t const * wexample = wexample_str.c_str(); @@ -32,7 +31,7 @@ int main() try { namespace nw=boost::nowide; - + std::cout << "Testing fstream" << std::endl; { nw::ofstream fo; @@ -70,7 +69,7 @@ int main() TEST(tmp=="test"); fi.close(); } - #if defined(BOOST_WINDOWS) || defined(BOOST_NOWIDE_FSTREAM_TESTS) + #if defined(BOOST_WINDOWS) || defined(BOOST_NOWIDE_FSTREAM_TESTS) // C++11 interfaces aren't enabled at all platforms so need to skip // for std::*fstream { @@ -129,16 +128,16 @@ int main() } nw::remove(example); } - + for(int i=-1;i<16;i++) { std::cout << "Complex io with buffer = " << i << std::endl; char buf[16]; nw::fstream f; if(i==0) f.rdbuf()->pubsetbuf(0,0); - else if (i > 0) + else if (i > 0) f.rdbuf()->pubsetbuf(buf,i); - + f.open(example,nw::fstream::in | nw::fstream::out | nw::fstream::trunc | nw::fstream::binary); f.put('a'); f.put('b'); @@ -187,7 +186,7 @@ int main() #endif f.close(); TEST(boost::nowide::remove(example)==0); - + } } catch(std::exception const &e) { diff --git a/test/test_iostream.cpp b/test/test_iostream.cpp index 399d002..811cf3d 100644 --- a/test/test_iostream.cpp +++ b/test/test_iostream.cpp @@ -25,7 +25,7 @@ bool isValidUTF8(const std::string& s){ int main(int argc,char **argv) { - + char const *example = "Basic letters: \xd7\xa9-\xd0\xbc-\xce\xbd\n" "East Asian Letters: \xe5\x92\x8c\xe5\xb9\xb3\n" "Non-BMP letters: \xf0\x9d\x84\x9e\n" diff --git a/test/test_sets.hpp b/test/test_sets.hpp index a1a440b..a6b9560 100644 --- a/test/test_sets.hpp +++ b/test/test_sets.hpp @@ -23,7 +23,7 @@ struct wide_to_utf8 { utf8_to_wide n2w_tests[] = { - { + { "\xf0\x9d\x92\x9e-\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82.txt", L"\U0001D49E-\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042.txt" }, @@ -46,7 +46,7 @@ utf8_to_wide n2w_tests[] = { }; utf8_to_wide u2w_tests[] = { - { + { "\xf0\x9d\x92\x9e-\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82.txt", L"\U0001D49E-\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042.txt" }, @@ -70,23 +70,23 @@ utf8_to_wide u2w_tests[] = { wide_to_utf8 w2n_tests_utf16[] = { - { + { L"\U0001D49E-\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042.txt", "\xf0\x9d\x92\x9e-\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82.txt", }, - { + { L"\xD800\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xEF\xBF\xBD\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" }, - { + { L"\xDC00\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xEF\xBF\xBD \xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" }, - { + { L"\u3084\u3042\xD800\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xE3\x82\x84\xE3\x81\x82\xEF\xBF\xBD\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" }, - { + { L"\u3084\u3042\xDC00\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xE3\x82\x84\xE3\x81\x82\xEF\xBF\xBD \xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" } @@ -94,23 +94,23 @@ wide_to_utf8 w2n_tests_utf16[] = { wide_to_utf8 w2n_tests_utf32[] = { - { + { L"\U0001D49E-\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042.txt", "\xf0\x9d\x92\x9e-\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82.txt", }, - { + { L"\xD800\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xEF\xBF\xBD \xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" }, - { + { L"\xDC00\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xEF\xBF\xBD \xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" }, - { + { L"\u3084\u3042\xD800\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xE3\x82\x84\xE3\x81\x82\xEF\xBF\xBD \xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" }, - { + { L"\u3084\u3042\xDC00\x20\u043F\u0440\u0438\u0432\u0435\u0442-\u3084\u3042", "\xE3\x82\x84\xE3\x81\x82\xEF\xBF\xBD \xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82" } diff --git a/test/test_system.cpp b/test/test_system.cpp index e5bdcf5..2287079 100644 --- a/test/test_system.cpp +++ b/test/test_system.cpp @@ -44,7 +44,7 @@ int main(int argc,char **argv,char **env) } else if(argc==2 && argv[1][0]=='-') { switch(argv[1][1]) { - case 'w': + case 'w': { #ifdef BOOST_WINDOWS std::wstring env = L"BOOST_NOWIDE_TEST=" + wexample;