mirror of
https://github.com/boostorg/nowide.git
synced 2026-02-22 03:22:32 +00:00
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/build/*
|
||||
/nowide_standalone
|
||||
/.vscode
|
||||
/.vs
|
||||
# Don't ignore Jamfiles, also in subfolders
|
||||
!Jamfile.*
|
||||
@@ -12,7 +12,6 @@ project boost/nowide
|
||||
: source-location ../src
|
||||
: usage-requirements # pass these requirement to dependents (i.e. users)
|
||||
<link>shared:<define>BOOST_NOWIDE_DYN_LINK=1
|
||||
<link>static:<define>BOOST_NOWIDE_STATIC_LINK=1
|
||||
;
|
||||
|
||||
SOURCES = iostream ;
|
||||
@@ -20,7 +19,6 @@ SOURCES = iostream ;
|
||||
lib boost_nowide
|
||||
: $(SOURCES).cpp
|
||||
: <link>shared:<define>BOOST_NOWIDE_DYN_LINK=1
|
||||
<link>static:<define>BOOST_NOWIDE_STATIC_LINK=1
|
||||
;
|
||||
|
||||
boost-install boost_nowide ;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -215,7 +215,7 @@ Custom API</h2>
|
||||
<h2><a class="anchor" id="using_windows_h"></a>
|
||||
The windows.h header</h2>
|
||||
<p>The library does not include the <code>windows.h</code> in order to prevent namespace pollution with numerous defines and types. Instead, the library defines the prototypes of the Win32 API functions.</p>
|
||||
<p>However, you may request to use the <code>windows.h</code> header by defining <code>BOOST_NOWIDE_USE_WINDOWS_H</code> before including any of the Boost.Nowide headers</p>
|
||||
<p>However, you may request to use the <code>windows.h</code> header by defining <code>BOOST_USE_WINDOWS_H</code> before including any of the Boost.Nowide headers</p>
|
||||
<h2><a class="anchor" id="using_integration"></a>
|
||||
Integration with Boost.Filesystem</h2>
|
||||
<p>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 <code><a class="el" href="namespaceboost_1_1nowide.html#a7f94a60d0a9e5534a6dcc41bbc826ee8">boost::nowide::nowide_filesystem()</a></code> in the beginning of your program</p>
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> </div>
|
||||
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="preprocessor">#include <stddef.h></span></div>
|
||||
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> </div>
|
||||
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="preprocessor">#ifdef BOOST_NOWIDE_USE_WINDOWS_H</span></div>
|
||||
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="preprocessor">#ifdef BOOST_USE_WINDOWS_H</span></div>
|
||||
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor">#include <windows.h></span></div>
|
||||
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="preprocessor">#else</span></div>
|
||||
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div>
|
||||
|
||||
42
doc/main.txt
42
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: <code>int main(int argc,char **argv)</code>
|
||||
@@ -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 <code>War and Peace - Война и мир - מלחמה ושלום.zip</code>
|
||||
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
|
||||
|
||||
@@ -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<wargc;i++)
|
||||
for(int i=0;i<wargc;i++)
|
||||
args_[i] = arg_values_[i].convert(wargv[i]);
|
||||
argc = wargc;
|
||||
argv = &args_[0];
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace nowide {
|
||||
inline char *getenv(char const *key)
|
||||
{
|
||||
static stackstring value;
|
||||
|
||||
|
||||
wshort_stackstring name(key);
|
||||
|
||||
static const size_t buf_size = 64;
|
||||
@@ -58,7 +58,7 @@ namespace nowide {
|
||||
}
|
||||
///
|
||||
/// \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
|
||||
///
|
||||
|
||||
@@ -11,27 +11,19 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/nowide/replacement.hpp>
|
||||
|
||||
#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
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace nowide {
|
||||
std::basic_string<CharOut>
|
||||
basic_convert(CharIn const *begin,CharIn const *end)
|
||||
{
|
||||
|
||||
|
||||
std::basic_string<CharOut> result;
|
||||
result.reserve(end-begin);
|
||||
typedef std::back_insert_iterator<std::basic_string<CharOut> > 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<char>(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<char>(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<wchar_t>(s);
|
||||
}
|
||||
|
||||
@@ -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<typename CharType,typename Traits = std::char_traits<CharType> >
|
||||
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;ptr<p;ptr++)
|
||||
std::cerr << *ptr;
|
||||
if(e!=0) {
|
||||
std::cerr << "|";
|
||||
for(char *ptr = p;ptr<e;ptr++)
|
||||
std::cerr << *ptr;
|
||||
}
|
||||
std::cerr << "]" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void print_state()
|
||||
{
|
||||
std::cerr << "- Output:" << std::endl;
|
||||
print_buf(pbase(),pptr(),0);
|
||||
std::cerr << "- Input:" << std::endl;
|
||||
print_buf(eback(),gptr(),egptr());
|
||||
std::cerr << "- fpos: " << (file_ ? ftell(file_) : -1L) << std::endl;
|
||||
}
|
||||
|
||||
struct print_guard
|
||||
{
|
||||
print_guard(basic_filebuf *p,char const *func)
|
||||
{
|
||||
self = p;
|
||||
f=func;
|
||||
std::cerr << "In: " << f << std::endl;
|
||||
self->print_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<char> filebuf;
|
||||
|
||||
|
||||
#endif // windows
|
||||
|
||||
|
||||
} // nowide
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -43,30 +43,30 @@ namespace nowide {
|
||||
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
|
||||
typedef std::basic_istream<CharType,Traits> 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<internal_buffer_type> buf_;
|
||||
};
|
||||
@@ -120,7 +120,7 @@ namespace nowide {
|
||||
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
|
||||
typedef std::basic_ostream<CharType,Traits> 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<internal_buffer_type> buf_;
|
||||
};
|
||||
@@ -193,7 +193,7 @@ namespace nowide {
|
||||
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
|
||||
typedef std::basic_iostream<CharType,Traits> 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<internal_buffer_type> buf_;
|
||||
};
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp> // 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<console_input_buffer> 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 <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
|
||||
|
||||
#endif
|
||||
///
|
||||
|
||||
@@ -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<typename CharOut=wchar_t,typename CharIn = char,size_t BufferSize = 256>
|
||||
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];
|
||||
|
||||
@@ -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<boost::uint16_t *>(&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<boost::uint16_t *>(&std_state);
|
||||
while(to < to_end && from < from_end)
|
||||
{
|
||||
#ifdef DEBUG_CODECVT
|
||||
std::cout << "Entering IN--------------" << std::endl;
|
||||
std::cout << "State " << std::hex << state <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
char const *from_saved = from;
|
||||
|
||||
uint32_t ch=boost::locale::utf::utf_traits<char>::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::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -223,11 +196,6 @@ protected:
|
||||
boost::uint16_t &state = *reinterpret_cast<boost::uint16_t *>(&std_state);
|
||||
while(to < to_end && from < from_end)
|
||||
{
|
||||
#ifdef DEBUG_CODECVT
|
||||
std::cout << "Entering OUT --------------" << std::endl;
|
||||
std::cout << "State " << std::hex << state <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
boost::uint32_t ch=0;
|
||||
if(state != 0) {
|
||||
// if the state idecates that 1st surrogate pair was written
|
||||
@@ -258,7 +226,7 @@ protected:
|
||||
continue;
|
||||
}
|
||||
else if(0xDC00 <= ch && ch<=0xDFFF) {
|
||||
// if we observe second surrogate pair and
|
||||
// if we observe second surrogate pair and
|
||||
// first only may be expected we should break from the loop with error
|
||||
// as it is illegal input
|
||||
ch = BOOST_NOWIDE_REPLACEMENT_CHARACTER;
|
||||
@@ -281,25 +249,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 <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -388,15 +337,10 @@ protected:
|
||||
// and first pair is written, but no input consumed
|
||||
while(to < to_end && from < from_end)
|
||||
{
|
||||
#ifdef DEBUG_CODECVT
|
||||
std::cout << "Entering IN--------------" << std::endl;
|
||||
std::cout << "State " << std::hex << state <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
char const *from_saved = from;
|
||||
|
||||
|
||||
uint32_t ch=boost::locale::utf::utf_traits<char>::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 <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -445,11 +370,6 @@ protected:
|
||||
std::codecvt_base::result r=std::codecvt_base::ok;
|
||||
while(to < to_end && from < from_end)
|
||||
{
|
||||
#ifdef DEBUG_CODECVT
|
||||
std::cout << "Entering OUT --------------" << std::endl;
|
||||
std::cout << "State " << std::hex << state <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
boost::uint32_t ch=0;
|
||||
ch = *from;
|
||||
if(!boost::locale::utf::is_valid_codepoint(ch)) {
|
||||
@@ -467,25 +387,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 <<std::endl;
|
||||
std::cout << "Left in " << std::dec << from_end - from << " out " << to_end -to << std::endl;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#ifndef BOOST_NOWIDE_WINDOWS_HPP_INCLUDED
|
||||
#define BOOST_NOWIDE_WINDOWS_HPP_INCLUDED
|
||||
|
||||
#ifdef BOOST_NOWIDE_USE_WINDOWS_H
|
||||
#ifdef BOOST_USE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,21 @@
|
||||
//
|
||||
#define BOOST_NOWIDE_SOURCE
|
||||
#include <boost/nowide/iostream.hpp>
|
||||
|
||||
#ifndef BOOST_WINDOWS
|
||||
|
||||
namespace boost {
|
||||
namespace nowide {
|
||||
BOOST_NOWIDE_DECL void dummy_exported_function(){}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/nowide/convert.hpp>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#ifdef BOOST_WINDOWS
|
||||
|
||||
#ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
#endif
|
||||
@@ -52,7 +61,7 @@ namespace details {
|
||||
return -1;
|
||||
int n = static_cast<int>(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<int>(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<char>::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
size_t read()
|
||||
{
|
||||
namespace uf = boost::locale::utf;
|
||||
@@ -171,18 +180,18 @@ namespace details {
|
||||
out = uf::utf_traits<char>::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
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
# define NOWIDE_DECL __declspec(dllimport)
|
||||
# endif //NOWIDE_SOURCE
|
||||
# endif // DYN_LINK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NOWIDE_DECL
|
||||
# define NOWIDE_DECL
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
namespace nowide {
|
||||
namespace conv {
|
||||
///
|
||||
/// \addtogroup codepage
|
||||
/// \addtogroup codepage
|
||||
///
|
||||
/// @{
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<typename Iterator>
|
||||
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<typename Iterator>
|
||||
@@ -144,7 +144,7 @@ namespace utf {
|
||||
template<typename Iterator>
|
||||
static code_point decode_valid(Iterator &p);
|
||||
};
|
||||
|
||||
|
||||
#else
|
||||
|
||||
template<typename CharType,int size=sizeof(CharType)>
|
||||
@@ -154,8 +154,8 @@ namespace utf {
|
||||
struct utf_traits<CharType,1> {
|
||||
|
||||
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<typename Iterator>
|
||||
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<typename Iterator>
|
||||
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<typename CharType>
|
||||
struct utf_traits<CharType,4> {
|
||||
typedef CharType char_type;
|
||||
|
||||
@@ -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<wchar_t>());
|
||||
|
||||
|
||||
cvt_type const &cvt = std::use_facet<cvt_type>(l);
|
||||
std::vector<wchar_t> 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<wchar_t>());
|
||||
|
||||
|
||||
cvt_type const &cvt = std::use_facet<cvt_type>(l);
|
||||
std::vector<wchar_t> 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;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <boost/nowide/cstdio.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user