CMakified project

This commit is contained in:
2016-11-09 19:01:48 +01:00
parent b72ec8e1dd
commit fe19a81484
26 changed files with 256 additions and 1285 deletions
@@ -5,19 +5,19 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_ARGS_HPP_INCLUDED
#define NOWIDE_ARGS_HPP_INCLUDED
#ifndef BOOST_NOWIDE_ARGS_HPP_INCLUDED
#define BOOST_NOWIDE_ARGS_HPP_INCLUDED
#include <nowide/config.hpp>
#include <nowide/stackstring.hpp>
#include <boost/config.hpp>
#include <boost/nowide/stackstring.hpp>
#include <vector>
#ifdef NOWIDE_WINDOWS
#include <nowide/windows.hpp>
#ifdef BOOST_WINDOWS
#include <boost/nowide/windows.hpp>
#endif
namespace boost {
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
class args {
public:
args(int &,char **&) {}
@@ -160,7 +160,7 @@ namespace nowide {
#endif
} // nowide
} // namespace boost
#endif
///
@@ -5,23 +5,23 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_CENV_H_INCLUDED
#define NOWIDE_CENV_H_INCLUDED
#ifndef BOOST_NOWIDE_CENV_H_INCLUDED
#define BOOST_NOWIDE_CENV_H_INCLUDED
#include <string>
#include <stdexcept>
#include <stdlib.h>
#include <nowide/config.hpp>
#include <nowide/stackstring.hpp>
#include <boost/config.hpp>
#include <boost/nowide/stackstring.hpp>
#include <vector>
#ifdef NOWIDE_WINDOWS
#include <nowide/windows.hpp>
#ifdef BOOST_WINDOWS
#include <boost/nowide/windows.hpp>
#endif
namespace boost {
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using ::getenv;
using ::setenv;
using ::unsetenv;
@@ -119,7 +119,7 @@ namespace nowide {
}
#endif
} // nowide
} // namespace boost
#endif
///
+54
View File
@@ -0,0 +1,54 @@
//
// Copyright (c) 2012 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_NOWIDE_CONFIG_HPP_INCLUDED
#define BOOST_NOWIDE_CONFIG_HPP_INCLUDED
#include <boost/config.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
//
// 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
// once it's done with it:
//
#define BOOST_LIB_NAME boost_nowide
//
// If we're importing code from a dll, then tell auto_link.hpp about it:
//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_NOWIDE_DYN_LINK)
# define BOOST_DYN_LINK
#endif
//
// And include the header that does the work:
//
#include <boost/config/auto_link.hpp>
#endif // auto-linking disabled
#endif // boost/nowide/config.hpp
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
@@ -5,13 +5,13 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_CONVERT_H_INCLUDED
#define NOWIDE_CONVERT_H_INCLUDED
#ifndef BOOST_NOWIDE_CONVERT_H_INCLUDED
#define BOOST_NOWIDE_CONVERT_H_INCLUDED
#include <string>
#include <nowide/encoding_utf.hpp>
#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)
@@ -30,7 +30,7 @@ namespace nowide {
return 0;
buffer_size --;
while(source_begin!=source_end) {
using namespace nowide::utf;
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;
@@ -112,42 +112,42 @@ namespace nowide {
///
/// Convert between Wide - UTF-16/32 string and UTF-8 string.
///
/// nowide::conv::conversion_error is thrown in a case of a error
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::string narrow(wchar_t const *s)
{
return nowide::conv::utf_to_utf<char>(s);
return boost::locale::conv::utf_to_utf<char>(s);
}
///
/// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform
///
/// nowide::conv::conversion_error is thrown in a case of a error
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::wstring widen(char const *s)
{
return nowide::conv::utf_to_utf<wchar_t>(s);
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
///
/// Convert between Wide - UTF-16/32 string and UTF-8 string
///
/// nowide::conv::conversion_error is thrown in a case of a error
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::string narrow(std::wstring const &s)
{
return nowide::conv::utf_to_utf<char>(s);
return boost::locale::conv::utf_to_utf<char>(s);
}
///
/// Convert between UTF-8 and UTF-16 string, implemented only on Windows platform
///
/// nowide::conv::conversion_error is thrown in a case of a error
/// boost::locale::conv::conversion_error is thrown in a case of a error
///
inline std::wstring widen(std::string const &s)
{
return nowide::conv::utf_to_utf<wchar_t>(s);
return boost::locale::conv::utf_to_utf<wchar_t>(s);
}
} // nowide
} // namespace boost
#endif
///
@@ -5,25 +5,25 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_CSTDIO_H_INCLUDED
#define NOWIDE_CSTDIO_H_INCLUDED
#ifndef BOOST_NOWIDE_CSTDIO_H_INCLUDED
#define BOOST_NOWIDE_CSTDIO_H_INCLUDED
#include <cstdio>
#include <stdio.h>
#include <nowide/config.hpp>
#include <nowide/convert.hpp>
#include <nowide/stackstring.hpp>
#include <boost/config.hpp>
#include <boost/nowide/convert.hpp>
#include <boost/nowide/stackstring.hpp>
#include <errno.h>
#ifdef NOWIDE_MSVC
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4996)
#endif
namespace boost {
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using std::fopen;
using std::freopen;
using std::remove;
@@ -90,9 +90,9 @@ inline int remove(char const *name)
}
#endif
} // nowide
} // namespace boost
#ifdef NOWIDE_MSVC
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
@@ -5,11 +5,11 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_CSTDLIB_HPP_INCLUDED
#define NOWIDE_CSTDLIB_HPP_INCLUDED
#ifndef BOOST_NOWIDE_CSTDLIB_HPP_INCLUDED
#define BOOST_NOWIDE_CSTDLIB_HPP_INCLUDED
#include <nowide/cenv.hpp>
#include <nowide/system.hpp>
#include <boost/nowide/cenv.hpp>
#include <boost/nowide/system.hpp>
#endif
///
@@ -5,25 +5,25 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_FILEBUF_HPP
#define NOWIDE_FILEBUF_HPP
#ifndef BOOST_NOWIDE_FILEBUF_HPP
#define BOOST_NOWIDE_FILEBUF_HPP
#include <iosfwd>
#include <nowide/config.hpp>
#include <nowide/stackstring.hpp>
#include <boost/config.hpp>
#include <boost/nowide/stackstring.hpp>
#include <fstream>
#include <streambuf>
#include <stdio.h>
#ifdef NOWIDE_MSVC
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4996 4244)
#endif
namespace boost {
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_FSTREAM_TESTS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_FSTREAM_TESTS) && !defined(BOOST_NOWIDE_DOXYGEN)
using std::basic_filebuf;
using std::filebuf;
#else // Windows
@@ -93,8 +93,8 @@ namespace nowide {
wstackstring name;
if(!name.convert(s))
return 0;
#ifdef NOWIDE_FSTREAM_TESTS
FILE *f = ::fopen(s,nowide::convert(smode).c_str());
#ifdef BOOST_NOWIDE_FSTREAM_TESTS
FILE *f = ::fopen(s,boost::nowide::convert(smode).c_str());
#else
FILE *f = ::_wfopen(name.c_str(),smode);
#endif
@@ -146,7 +146,7 @@ namespace nowide {
return this;
}
#ifdef NOWIDE_DEBUG_FILEBUF
#ifdef BOOST_NOWIDE_DEBUG_FILEBUF
void print_buf(char *b,char *p,char *e)
{
@@ -201,7 +201,7 @@ namespace nowide {
int overflow(int c)
{
#ifdef NOWIDE_DEBUG_FILEBUF
#ifdef BOOST_NOWIDE_DEBUG_FILEBUF
print_guard g(this,__FUNCTION__);
#endif
if(!file_)
@@ -239,7 +239,7 @@ namespace nowide {
int underflow()
{
#ifdef NOWIDE_DEBUG_FILEBUF
#ifdef BOOST_NOWIDE_DEBUG_FILEBUF
print_guard g(this,__FUNCTION__);
#endif
if(!file_)
@@ -272,7 +272,7 @@ namespace nowide {
std::ios_base::seekdir seekdir,
std::ios_base::openmode /*m*/)
{
#ifdef NOWIDE_DEBUG_FILEBUF
#ifdef BOOST_NOWIDE_DEBUG_FILEBUF
print_guard g(this,__FUNCTION__);
#endif
if(!file_)
@@ -396,9 +396,9 @@ namespace nowide {
#endif // windows
} // nowide
} // namespace boost
#ifdef NOWIDE_MSVC
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
@@ -5,25 +5,25 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_FSTREAM_INCLUDED_HPP
#define NOWIDE_FSTREAM_INCLUDED_HPP
#ifndef BOOST_NOWIDE_FSTREAM_INCLUDED_HPP
#define BOOST_NOWIDE_FSTREAM_INCLUDED_HPP
#include <iosfwd>
#include <nowide/config.hpp>
#include <nowide/convert.hpp>
#include <nowide/scoped_ptr.hpp>
#include <boost/config.hpp>
#include <boost/nowide/convert.hpp>
#include <boost/scoped_ptr.hpp>
#include <fstream>
#include <memory>
#include <nowide/filebuf.hpp>
#include <boost/nowide/filebuf.hpp>
namespace boost {
///
/// \brief This namespace includes implementation of the standard library functios
/// such that they accept UTF-8 strings on Windows. On other platforms it is just an alias
/// of std namespace (i.e. not on Windows)
///
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_FSTREAM_TESTS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_FSTREAM_TESTS) && !defined(BOOST_NOWIDE_DOXYGEN)
using std::basic_ifstream;
using std::basic_ofstream;
@@ -93,7 +93,7 @@ namespace nowide {
}
private:
nowide::scoped_ptr<internal_buffer_type> buf_;
boost::scoped_ptr<internal_buffer_type> buf_;
};
///
@@ -155,7 +155,7 @@ namespace nowide {
}
private:
nowide::scoped_ptr<internal_buffer_type> buf_;
boost::scoped_ptr<internal_buffer_type> buf_;
};
///
@@ -217,7 +217,7 @@ namespace nowide {
}
private:
nowide::scoped_ptr<internal_buffer_type> buf_;
boost::scoped_ptr<internal_buffer_type> buf_;
};
@@ -240,7 +240,7 @@ namespace nowide {
#endif
} // nowide
} // namespace boost
@@ -5,24 +5,24 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_IOSTREAM_HPP_INCLUDED
#define NOWIDE_IOSTREAM_HPP_INCLUDED
#ifndef BOOST_NOWIDE_IOSTREAM_HPP_INCLUDED
#define BOOST_NOWIDE_IOSTREAM_HPP_INCLUDED
#include <nowide/config.hpp>
#include <nowide/scoped_ptr.hpp>
#include <boost/nowide/config.hpp>
#include <boost/scoped_ptr.hpp>
#include <iostream>
#include <ostream>
#include <istream>
#ifdef NOWIDE_MSVC
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4251)
#endif
namespace boost {
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using std::cout;
using std::cerr;
using std::cin;
@@ -34,17 +34,17 @@ namespace nowide {
class console_output_buffer;
class console_input_buffer;
class NOWIDE_DECL winconsole_ostream : public std::ostream {
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:
nowide::scoped_ptr<console_output_buffer> d;
boost::scoped_ptr<console_output_buffer> d;
};
class NOWIDE_DECL winconsole_istream : public std::istream {
class BOOST_NOWIDE_DECL winconsole_istream : public std::istream {
winconsole_istream(winconsole_istream const &);
void operator=(winconsole_istream const &);
public:
@@ -53,7 +53,7 @@ namespace nowide {
~winconsole_istream();
private:
struct data;
nowide::scoped_ptr<console_input_buffer> d;
boost::scoped_ptr<console_input_buffer> d;
};
} // details
@@ -64,32 +64,32 @@ namespace nowide {
///
/// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
///
extern NOWIDE_DECL details::winconsole_istream cin;
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 NOWIDE_DECL details::winconsole_ostream cout;
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 NOWIDE_DECL details::winconsole_ostream cerr;
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 NOWIDE_DECL details::winconsole_ostream clog;
extern BOOST_NOWIDE_DECL details::winconsole_ostream clog;
#endif
} // nowide
} // namespace boost
#ifdef NOWIDE_MSVC
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
@@ -5,13 +5,13 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_DETAILS_WIDESTR_H_INCLUDED
#define NOWIDE_DETAILS_WIDESTR_H_INCLUDED
#include <nowide/convert.hpp>
#ifndef BOOST_NOWIDE_DETAILS_WIDESTR_H_INCLUDED
#define BOOST_NOWIDE_DETAILS_WIDESTR_H_INCLUDED
#include <boost/nowide/convert.hpp>
#include <string.h>
#include <algorithm>
namespace boost {
namespace nowide {
///
@@ -147,7 +147,7 @@ typedef basic_stackstring<char,wchar_t,16> short_stackstring;
} // nowide
} // namespace boost
#endif
///
@@ -5,16 +5,16 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_CSTDLIB_HPP
#define NOWIDE_CSTDLIB_HPP
#ifndef BOOST_NOWIDE_CSTDLIB_HPP
#define BOOST_NOWIDE_CSTDLIB_HPP
#include <stdlib.h>
#include <errno.h>
#include <nowide/stackstring.hpp>
#include <boost/nowide/stackstring.hpp>
namespace boost {
namespace nowide {
#if !defined(NOWIDE_WINDOWS) && !defined(NOWIDE_DOXYGEN)
#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
using ::system;
@@ -39,7 +39,7 @@ inline int system(char const *cmd)
#endif
} // nowide
} // namespace boost
#endif
///
@@ -5,12 +5,12 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_WINDOWS_HPP_INCLUDED
#define NOWIDE_WINDOWS_HPP_INCLUDED
#ifndef BOOST_NOWIDE_WINDOWS_HPP_INCLUDED
#define BOOST_NOWIDE_WINDOWS_HPP_INCLUDED
#include <stddef.h>
#ifdef NOWIDE_USE_WINDOWS_H
#ifdef BOOST_NOWIDE_USE_WINDOWS_H
#include <windows.h>
#else
-37
View File
@@ -1,37 +0,0 @@
//
// Copyright (c) 2012 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_CONFIG_H_INCLUDED
#define NOWIDE_CONFIG_H_INCLUDED
#if (defined(__WIN32) || defined(_WIN32) || defined(WIN32)) && !defined(__CYGWIN__)
#define NOWIDE_WINDOWS
#endif
#ifdef _MSC_VER
#define NOWIDE_MSVC
#endif
#ifdef NOWIDE_WINDOWS
# if defined(DLL_EXPORT) || defined(NOWIDE_EXPORT)
# ifdef NOWIDE_SOURCE
# define NOWIDE_DECL __declspec(dllexport)
# else
# define NOWIDE_DECL __declspec(dllimport)
# endif //NOWIDE_SOURCE
# endif // DYN_LINK
#endif
#ifndef NOWIDE_DECL
# define NOWIDE_DECL
#endif
#endif
///
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
-58
View File
@@ -1,58 +0,0 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_ENCODING_ERRORS_HPP_INCLUDED
#define NOWIDE_ENCODING_ERRORS_HPP_INCLUDED
#include <nowide/config.hpp>
#ifdef NOWIDE_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <stdexcept>
namespace nowide {
namespace conv {
///
/// \addtogroup codepage
///
/// @{
///
/// \brief The excepton that is thrown in case of conversion error
///
class conversion_error : public std::runtime_error {
public:
conversion_error() : std::runtime_error("Conversion failed") {}
};
///
/// enum that defines conversion policy
///
typedef enum {
skip = 0, ///< Skip illegal/unconvertable characters
stop = 1, ///< Stop conversion and throw conversion_error
default_method = skip ///< Default method - skip
} method_type;
/// @}
} // conv
} // nowide
#ifdef NOWIDE_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
-84
View File
@@ -1,84 +0,0 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_ENCODING_UTF_HPP_INCLUDED
#define NOWIDE_ENCODING_UTF_HPP_INCLUDED
#include <nowide/utf.hpp>
#include <nowide/encoding_errors.hpp>
#include <string>
#include <iterator>
#ifdef NOWIDE_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
namespace nowide{
namespace conv {
///
/// Convert a Unicode text in range [begin,end) to other Unicode encoding
///
template<typename CharOut,typename CharIn>
std::basic_string<CharOut>
utf_to_utf(CharIn const *begin,CharIn const *end,method_type how = default_method)
{
std::basic_string<CharOut> result;
result.reserve(end-begin);
typedef std::back_insert_iterator<std::basic_string<CharOut> > inserter_type;
inserter_type inserter(result);
utf::code_point c;
while(begin!=end) {
c=utf::utf_traits<CharIn>::template decode<CharIn const *>(begin,end);
if(c==utf::illegal || c==utf::incomplete) {
if(how==stop)
throw conversion_error();
}
else {
utf::utf_traits<CharOut>::template encode<inserter_type>(c,inserter);
}
}
return result;
}
///
/// Convert a Unicode NUL terminated string \a str other Unicode encoding
///
template<typename CharOut,typename CharIn>
std::basic_string<CharOut>
utf_to_utf(CharIn const *str,method_type how = default_method)
{
CharIn const *end = str;
while(*end)
end++;
return utf_to_utf<CharOut,CharIn>(str,end,how);
}
///
/// Convert a Unicode string \a str other Unicode encoding
///
template<typename CharOut,typename CharIn>
std::basic_string<CharOut>
utf_to_utf(std::basic_string<CharIn> const &str,method_type how = default_method)
{
return utf_to_utf<CharOut,CharIn>(str.c_str(),str.c_str()+str.size(),how);
}
} // conv
} // nowide
#ifdef NOWIDE_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
-93
View File
@@ -1,93 +0,0 @@
#ifndef NOWIDE_SCOPED_PTR_HPP
#define NOWIDE_SCOPED_PTR_HPP
// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
// Copyright (c) 2001, 2002 Peter Dimov,
// Copyright (C) 2012 Artyom Beilis
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// http://www.boost.org/libs/smart_ptr/scoped_ptr.htm
//
#include <assert.h>
namespace nowide
{
// scoped_ptr mimics a built-in pointer except that it guarantees deletion
// of the object pointed to, either on destruction of the scoped_ptr or via
// an explicit reset(). scoped_ptr is a simple solution for simple needs;
// use shared_ptr or std::auto_ptr if your needs are more complex.
template<class T> class scoped_ptr // noncopyable
{
private:
T * px;
scoped_ptr(scoped_ptr const &);
scoped_ptr & operator=(scoped_ptr const &);
typedef scoped_ptr<T> this_type;
void operator==( scoped_ptr const& ) const;
void operator!=( scoped_ptr const& ) const;
public:
typedef T element_type;
explicit scoped_ptr( T * p = 0 ): px( p ) // never throws
{
}
~scoped_ptr() // never throws
{
delete px;
}
void reset(T * p = 0) // never throws
{
assert( p == 0 || p != px ); // catch self-reset errors
this_type(p).swap(*this);
}
T & operator*() const // never throws
{
assert( px != 0 );
return *px;
}
T * operator->() const // never throws
{
assert( px != 0 );
return px;
}
T * get() const // never throws
{
return px;
}
operator bool() const
{
return px!=0;
}
void swap(scoped_ptr & b) // never throws
{
T * tmp = b.px;
b.px = px;
px = tmp;
}
};
} // namespace nowide
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
-469
View File
@@ -1,469 +0,0 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NOWIDE_UTF_HPP_INCLUDED
#define NOWIDE_UTF_HPP_INCLUDED
#include <nowide/config.hpp>
#ifndef NOWIDE_MSVC
namespace nowide {
namespace utf {
typedef unsigned uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
}
}
#else
#include <stdint.h>
#endif
namespace nowide {
///
/// \brief Namespace that holds basic operations on UTF encoded sequences
///
/// All functions defined in this namespace do not require linking with Boost.Locale library
///
namespace utf {
/// \cond INTERNAL
#ifdef __GNUC__
# define NOWIDE_LIKELY(x) __builtin_expect((x),1)
# define NOWIDE_UNLIKELY(x) __builtin_expect((x),0)
#else
# define NOWIDE_LIKELY(x) (x)
# define NOWIDE_UNLIKELY(x) (x)
#endif
/// \endcond
///
/// \brief The integral type type that can hold a Unicode code point
///
typedef uint32_t code_point;
///
/// \brief Special constant that defines illegal code point
///
static const code_point illegal = 0xFFFFFFFFu;
///
/// \brief Special constant that defines incomplete code point
///
static const code_point incomplete = 0xFFFFFFFEu;
///
/// \brief the function checks if \a v is a valid code point
///
inline bool is_valid_codepoint(code_point v)
{
if(v>0x10FFFF)
return false;
if(0xD800 <=v && v<= 0xDFFF) // surragates
return false;
return true;
}
#ifdef NOWIDE_DOXYGEN
///
/// \brief UTF Traits class - functions to convert UTF sequences to and from Unicode code points
///
template<typename CharType,int size=sizeof(CharType)>
struct utf_traits {
///
/// The type of the character
///
typedef CharType char_type;
///
/// Read one code point from the range [p,e) and return it.
///
/// - If the sequence that was read is incomplete sequence returns \ref incomplete,
/// - If illegal sequence detected returns \ref illegal
///
/// Requirements
///
/// - Iterator is valid input iterator
///
/// Postconditions
///
/// - p points to the last consumed character
///
template<typename Iterator>
static code_point decode(Iterator &p,Iterator e);
///
/// Maximal width of valid sequence in the code units:
///
/// - UTF-8 - 4
/// - UTF-16 - 2
/// - UTF-32 - 1
///
static const int max_width;
///
/// The width of specific code point in the code units.
///
/// Requirement: value is a valid Unicode code point
/// Returns value in range [1..max_width]
///
static int width(code_point value);
///
/// 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
///
static bool is_trail(char_type c);
///
/// Returns true if c is lead code unit, always true of UTF-32
///
static bool is_lead(char_type c);
///
/// Convert valid Unicode code point \a value to the UTF sequence.
///
/// 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>
static Iterator encode(code_point value,Iterator out);
///
/// Decodes valid UTF sequence that is pointed by p into code point.
///
/// If the sequence is invalid or points to end the behavior is undefined
///
template<typename Iterator>
static code_point decode_valid(Iterator &p);
};
#else
template<typename CharType,int size=sizeof(CharType)>
struct utf_traits;
template<typename CharType>
struct utf_traits<CharType,1> {
typedef CharType char_type;
static int trail_length(char_type ci)
{
unsigned char c = ci;
if(c < 128)
return 0;
if(NOWIDE_UNLIKELY(c < 194))
return -1;
if(c < 224)
return 1;
if(c < 240)
return 2;
if(NOWIDE_LIKELY(c <=244))
return 3;
return -1;
}
static const int max_width = 4;
static int width(code_point value)
{
if(value <=0x7F) {
return 1;
}
else if(value <=0x7FF) {
return 2;
}
else if(NOWIDE_LIKELY(value <=0xFFFF)) {
return 3;
}
else {
return 4;
}
}
static bool is_trail(char_type ci)
{
unsigned char c=ci;
return (c & 0xC0)==0x80;
}
static bool is_lead(char_type ci)
{
return !is_trail(ci);
}
template<typename Iterator>
static code_point decode(Iterator &p,Iterator e)
{
if(NOWIDE_UNLIKELY(p==e))
return incomplete;
unsigned char lead = *p++;
// First byte is fully validated here
int trail_size = trail_length(lead);
if(NOWIDE_UNLIKELY(trail_size < 0))
return illegal;
//
// Ok as only ASCII may be of size = 0
// also optimize for ASCII text
//
if(trail_size == 0)
return lead;
code_point c = lead & ((1<<(6-trail_size))-1);
// Read the rest
unsigned char tmp;
switch(trail_size) {
case 3:
if(NOWIDE_UNLIKELY(p==e))
return incomplete;
tmp = *p++;
if (!is_trail(tmp))
return illegal;
c = (c << 6) | ( tmp & 0x3F);
case 2:
if(NOWIDE_UNLIKELY(p==e))
return incomplete;
tmp = *p++;
if (!is_trail(tmp))
return illegal;
c = (c << 6) | ( tmp & 0x3F);
case 1:
if(NOWIDE_UNLIKELY(p==e))
return incomplete;
tmp = *p++;
if (!is_trail(tmp))
return illegal;
c = (c << 6) | ( tmp & 0x3F);
}
// Check code point validity: no surrogates and
// valid range
if(NOWIDE_UNLIKELY(!is_valid_codepoint(c)))
return illegal;
// make sure it is the most compact representation
if(NOWIDE_UNLIKELY(width(c)!=trail_size + 1))
return illegal;
return c;
}
template<typename Iterator>
static code_point decode_valid(Iterator &p)
{
unsigned char lead = *p++;
if(lead < 192)
return lead;
int trail_size;
if(lead < 224)
trail_size = 1;
else if(NOWIDE_LIKELY(lead < 240)) // non-BMP rare
trail_size = 2;
else
trail_size = 3;
code_point c = lead & ((1<<(6-trail_size))-1);
switch(trail_size) {
case 3:
c = (c << 6) | ( static_cast<unsigned char>(*p++) & 0x3F);
case 2:
c = (c << 6) | ( static_cast<unsigned char>(*p++) & 0x3F);
case 1:
c = (c << 6) | ( static_cast<unsigned char>(*p++) & 0x3F);
}
return c;
}
template<typename Iterator>
static Iterator encode(code_point value,Iterator out)
{
if(value <= 0x7F) {
*out++ = static_cast<char_type>(value);
}
else if(value <= 0x7FF) {
*out++ = static_cast<char_type>((value >> 6) | 0xC0);
*out++ = static_cast<char_type>((value & 0x3F) | 0x80);
}
else if(NOWIDE_LIKELY(value <= 0xFFFF)) {
*out++ = static_cast<char_type>((value >> 12) | 0xE0);
*out++ = static_cast<char_type>(((value >> 6) & 0x3F) | 0x80);
*out++ = static_cast<char_type>((value & 0x3F) | 0x80);
}
else {
*out++ = static_cast<char_type>((value >> 18) | 0xF0);
*out++ = static_cast<char_type>(((value >> 12) & 0x3F) | 0x80);
*out++ = static_cast<char_type>(((value >> 6) & 0x3F) | 0x80);
*out++ = static_cast<char_type>((value & 0x3F) | 0x80);
}
return out;
}
}; // utf8
template<typename CharType>
struct utf_traits<CharType,2> {
typedef CharType char_type;
// See RFC 2781
static bool is_first_surrogate(uint16_t x)
{
return 0xD800 <=x && x<= 0xDBFF;
}
static bool is_second_surrogate(uint16_t x)
{
return 0xDC00 <=x && x<= 0xDFFF;
}
static code_point combine_surrogate(uint16_t w1,uint16_t w2)
{
return ((code_point(w1 & 0x3FF) << 10) | (w2 & 0x3FF)) + 0x10000;
}
static int trail_length(char_type c)
{
if(is_first_surrogate(c))
return 1;
if(is_second_surrogate(c))
return -1;
return 0;
}
///
/// Returns true if c is trail code unit, always false for UTF-32
///
static bool is_trail(char_type c)
{
return is_second_surrogate(c);
}
///
/// Returns true if c is lead code unit, always true of UTF-32
///
static bool is_lead(char_type c)
{
return !is_second_surrogate(c);
}
template<typename It>
static code_point decode(It &current,It last)
{
if(NOWIDE_UNLIKELY(current == last))
return incomplete;
uint16_t w1=*current++;
if(NOWIDE_LIKELY(w1 < 0xD800 || 0xDFFF < w1)) {
return w1;
}
if(w1 > 0xDBFF)
return illegal;
if(current==last)
return incomplete;
uint16_t w2=*current++;
if(w2 < 0xDC00 || 0xDFFF < w2)
return illegal;
return combine_surrogate(w1,w2);
}
template<typename It>
static code_point decode_valid(It &current)
{
uint16_t w1=*current++;
if(NOWIDE_LIKELY(w1 < 0xD800 || 0xDFFF < w1)) {
return w1;
}
uint16_t w2=*current++;
return combine_surrogate(w1,w2);
}
static const int max_width = 2;
static int width(code_point u)
{
return u>=0x10000 ? 2 : 1;
}
template<typename It>
static It encode(code_point u,It out)
{
if(NOWIDE_LIKELY(u<=0xFFFF)) {
*out++ = static_cast<char_type>(u);
}
else {
u -= 0x10000;
*out++ = static_cast<char_type>(0xD800 | (u>>10));
*out++ = static_cast<char_type>(0xDC00 | (u & 0x3FF));
}
return out;
}
}; // utf16;
template<typename CharType>
struct utf_traits<CharType,4> {
typedef CharType char_type;
static int trail_length(char_type c)
{
if(is_valid_codepoint(c))
return 0;
return -1;
}
static bool is_trail(char_type /*c*/)
{
return false;
}
static bool is_lead(char_type /*c*/)
{
return true;
}
template<typename It>
static code_point decode_valid(It &current)
{
return *current++;
}
template<typename It>
static code_point decode(It &current,It last)
{
if(NOWIDE_UNLIKELY(current == last))
return nowide::utf::incomplete;
code_point c=*current++;
if(NOWIDE_UNLIKELY(!is_valid_codepoint(c)))
return nowide::utf::illegal;
return c;
}
static const int max_width = 1;
static int width(code_point /*u*/)
{
return 1;
}
template<typename It>
static It encode(code_point u,It out)
{
*out++ = static_cast<char_type>(u);
return out;
}
}; // utf32
#endif
} // utf
} // nowide
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4