update boost
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <boost/spirit/home/x3/support/context.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/lambda_visitor.hpp>
|
||||
#include <boost/spirit/home/x3/support/traits/is_variant.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
@@ -40,9 +41,16 @@ namespace boost { namespace spirit { namespace x3
|
||||
|
||||
template <typename T, typename Iterator, typename Context>
|
||||
inline void on_success(Iterator const& first, Iterator const& last
|
||||
, forward_ast<T>& ast, Context const& context)
|
||||
{
|
||||
this->on_success(first, last, ast.get(), context);
|
||||
}
|
||||
|
||||
template <typename T, typename Iterator, typename Context>
|
||||
inline typename disable_if<traits::is_variant<T>>::type on_success(Iterator const& first, Iterator const& last
|
||||
, T& ast, Context const& context)
|
||||
{
|
||||
auto& error_handler = get<error_handler_tag>(context).get();
|
||||
auto& error_handler = x3::get<error_handler_tag>(context).get();
|
||||
error_handler.tag(ast, first, last);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,12 +7,8 @@
|
||||
#if !defined(BOOST_SPIRIT_X3_ERROR_REPORTING_MAY_19_2014_00405PM)
|
||||
#define BOOST_SPIRIT_X3_ERROR_REPORTING_MAY_19_2014_00405PM
|
||||
|
||||
#ifndef BOOST_SPIRIT_X3_NO_FILESYSTEM
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/locale/encoding_utf.hpp>
|
||||
#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/utf8.hpp>
|
||||
#include <ostream>
|
||||
|
||||
// Clang-style error handling utilities
|
||||
@@ -68,8 +64,6 @@ namespace boost { namespace spirit { namespace x3
|
||||
void print_file_line(std::size_t line) const;
|
||||
void print_line(Iterator line_start, Iterator last) const;
|
||||
void print_indicator(Iterator& line_start, Iterator last, char ind) const;
|
||||
void skip_whitespace(Iterator& err_pos, Iterator last) const;
|
||||
void skip_non_whitespace(Iterator& err_pos, Iterator last) const;
|
||||
Iterator get_line_start(Iterator first, Iterator pos) const;
|
||||
std::size_t position(Iterator i) const;
|
||||
|
||||
@@ -84,12 +78,7 @@ namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
if (file != "")
|
||||
{
|
||||
#ifdef BOOST_SPIRIT_X3_NO_FILESYSTEM
|
||||
err_out << "In file " << file << ", ";
|
||||
#else
|
||||
namespace fs = boost::filesystem;
|
||||
err_out << "In file " << fs::path(file).generic_string() << ", ";
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -113,7 +102,7 @@ namespace boost { namespace spirit { namespace x3
|
||||
}
|
||||
typedef typename std::iterator_traits<Iterator>::value_type char_type;
|
||||
std::basic_string<char_type> line{start, end};
|
||||
err_out << locale::conv::utf_to_utf<char>(line) << std::endl;
|
||||
err_out << x3::to_utf8(line) << std::endl;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
@@ -132,41 +121,15 @@ namespace boost { namespace spirit { namespace x3
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::skip_whitespace(Iterator& err_pos, Iterator last) const
|
||||
{
|
||||
// make sure err_pos does not point to white space
|
||||
while (err_pos != last)
|
||||
{
|
||||
char c = *err_pos;
|
||||
if (std::isspace(c))
|
||||
++err_pos;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void error_handler<Iterator>::skip_non_whitespace(Iterator& err_pos, Iterator last) const
|
||||
{
|
||||
// make sure err_pos does not point to white space
|
||||
while (err_pos != last)
|
||||
{
|
||||
char c = *err_pos;
|
||||
if (std::isspace(c))
|
||||
break;
|
||||
else
|
||||
++err_pos;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
inline Iterator error_handler<Iterator>::get_line_start(Iterator first, Iterator pos) const
|
||||
{
|
||||
Iterator latest = first;
|
||||
for (Iterator i = first; i != pos; ++i)
|
||||
for (Iterator i = first; i != pos;)
|
||||
if (*i == '\r' || *i == '\n')
|
||||
latest = i;
|
||||
latest = ++i;
|
||||
else
|
||||
++i;
|
||||
return latest;
|
||||
}
|
||||
|
||||
@@ -201,15 +164,10 @@ namespace boost { namespace spirit { namespace x3
|
||||
Iterator first = pos_cache.first();
|
||||
Iterator last = pos_cache.last();
|
||||
|
||||
// make sure err_pos does not point to white space
|
||||
skip_whitespace(err_pos, last);
|
||||
|
||||
print_file_line(position(err_pos));
|
||||
err_out << error_message << std::endl;
|
||||
|
||||
Iterator start = get_line_start(first, err_pos);
|
||||
if (start != first)
|
||||
++start;
|
||||
print_line(start, last);
|
||||
print_indicator(start, err_pos, '_');
|
||||
err_out << "^_" << std::endl;
|
||||
@@ -222,15 +180,10 @@ namespace boost { namespace spirit { namespace x3
|
||||
Iterator first = pos_cache.first();
|
||||
Iterator last = pos_cache.last();
|
||||
|
||||
// make sure err_pos does not point to white space
|
||||
skip_whitespace(err_first, last);
|
||||
|
||||
print_file_line(position(err_first));
|
||||
err_out << error_message << std::endl;
|
||||
|
||||
Iterator start = get_line_start(first, err_first);
|
||||
if (start != first)
|
||||
++start;
|
||||
print_line(start, last);
|
||||
print_indicator(start, err_first, ' ');
|
||||
print_indicator(start, err_last, '~');
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#define BOOST_SPIRIT_X3_IS_CALLABLE_HPP_INCLUDED
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/spirit/home/x3/support/utility/sfinae.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3 { namespace detail
|
||||
{
|
||||
@@ -16,8 +15,8 @@ namespace boost { namespace spirit { namespace x3 { namespace detail
|
||||
struct is_callable_impl : mpl::false_ {};
|
||||
|
||||
template <typename F, typename... A>
|
||||
struct is_callable_impl<F(A...), typename disable_if_substitution_failure<
|
||||
decltype(std::declval<F>()(std::declval<A>()...))>::type>
|
||||
struct is_callable_impl<F(A...),
|
||||
decltype(void(std::declval<F>()(std::declval<A>()...)))>
|
||||
: mpl::true_
|
||||
{};
|
||||
}}}}
|
||||
|
||||
@@ -1,269 +0,0 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_X3_TEST_UTILITIES)
|
||||
#define BOOST_SPIRIT_X3_TEST_UTILITIES
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3 { namespace testing
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// compare
|
||||
//
|
||||
// Compares the contents of in with the template tem. The template
|
||||
// may include embedded regular expressions marked up within re_prefix
|
||||
// and re_suffix tags. For example, given the default RE markup, this
|
||||
// template <%[0-9]+%> will match any integer in in. The function
|
||||
// will return the first non-matching position. The flag full_match
|
||||
// indicates a full match. It is possible for returned pos to be
|
||||
// at the end of in (in.end()) while still returning full_match ==
|
||||
// false. In that case, we have a partial match.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Iterator>
|
||||
struct compare_result
|
||||
{
|
||||
compare_result(
|
||||
Iterator pos
|
||||
, bool full_match
|
||||
) : pos(pos), full_match(full_match) {}
|
||||
|
||||
Iterator pos;
|
||||
bool full_match;
|
||||
};
|
||||
|
||||
template <typename Range>
|
||||
compare_result<typename Range::const_iterator>
|
||||
compare(
|
||||
Range const& in
|
||||
, Range const& tem
|
||||
, char const* re_prefix = "<%"
|
||||
, char const* re_suffix = "%>"
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// compare
|
||||
//
|
||||
// 1) Call f, given the contents of input_path loaded in a string.
|
||||
// The result of calling f is the output string.
|
||||
// 2) Compare the result of calling f with expected template
|
||||
// file (expect_path) using the low-level compare utility
|
||||
// abive
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
template <typename F>
|
||||
bool compare(
|
||||
fs::path input_path, fs::path expect_path
|
||||
, F f
|
||||
, char const* re_prefix = "<%"
|
||||
, char const* re_suffix = "%>"
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// for_each_file
|
||||
//
|
||||
// For each *.input and *.expect file in a given directory,
|
||||
// call the function f, passing in the *.input and *.expect paths.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
template <typename F>
|
||||
int for_each_file(fs::path p, F f);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// load_file
|
||||
//
|
||||
// Load file into a string.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
std::string load(fs::path p);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Iterator>
|
||||
inline bool is_regex(
|
||||
Iterator& first
|
||||
, Iterator last
|
||||
, std::string& re
|
||||
, char const* re_prefix
|
||||
, char const* re_suffix
|
||||
)
|
||||
{
|
||||
boost::regex e(re_prefix + std::string("(.*?)") + re_suffix);
|
||||
boost::match_results<Iterator> what;
|
||||
if (boost::regex_search(
|
||||
first, last, what, e
|
||||
, boost::match_default | boost::match_continuous))
|
||||
{
|
||||
re = what[1].str();
|
||||
first = what[0].second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Range>
|
||||
inline compare_result<typename Range::const_iterator>
|
||||
compare(
|
||||
Range const& in
|
||||
, Range const& tem
|
||||
, char const* re_prefix
|
||||
, char const* re_suffix
|
||||
)
|
||||
{
|
||||
typedef typename Range::const_iterator iter_t;
|
||||
typedef compare_result<iter_t> compare_result_t;
|
||||
|
||||
iter_t in_first = in.begin();
|
||||
iter_t in_last = in.end();
|
||||
iter_t tem_first = tem.begin();
|
||||
iter_t tem_last = tem.end();
|
||||
std::string re;
|
||||
|
||||
while (in_first != in_last && tem_first != tem_last)
|
||||
{
|
||||
if (is_regex(tem_first, tem_last, re, re_prefix, re_suffix))
|
||||
{
|
||||
boost::match_results<iter_t> what;
|
||||
boost::regex e(re);
|
||||
if (!boost::regex_search(
|
||||
in_first, in_last, what, e
|
||||
, boost::match_default | boost::match_continuous))
|
||||
{
|
||||
// RE mismatch: exit now.
|
||||
return compare_result_t(in_first, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// RE match: gobble the matching string.
|
||||
in_first = what[0].second;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Char by char comparison. Exit if we have a mismatch.
|
||||
if (*in_first++ != *tem_first++)
|
||||
return compare_result_t(in_first, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore trailing spaces in template
|
||||
bool has_trailing_nonspaces = false;
|
||||
while (tem_first != tem_last)
|
||||
{
|
||||
if (!std::isspace(*tem_first++))
|
||||
{
|
||||
has_trailing_nonspaces = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (in_first != in_last)
|
||||
{
|
||||
if (!std::isspace(*in_first++))
|
||||
{
|
||||
has_trailing_nonspaces = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// return a full match only if the template is fully matched and if there
|
||||
// are no more characters to match in the source
|
||||
return compare_result_t(in_first, !has_trailing_nonspaces);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
inline int for_each_file(fs::path p, F f)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fs::exists(p) && fs::is_directory(p))
|
||||
{
|
||||
for (auto i = fs::directory_iterator(p); i != fs::directory_iterator(); ++i)
|
||||
{
|
||||
auto ext = fs::extension(i->path());
|
||||
if (ext == ".input")
|
||||
{
|
||||
auto input_path = i->path();
|
||||
auto expect_path = input_path;
|
||||
expect_path.replace_extension(".expect");
|
||||
f(input_path, expect_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Directory: " << fs::absolute(p) << " does not exist." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
catch (const fs::filesystem_error& ex)
|
||||
{
|
||||
std::cerr << ex.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline std::string load(fs::path p)
|
||||
{
|
||||
boost::filesystem::ifstream file(p);
|
||||
if (!file)
|
||||
return "";
|
||||
std::string contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
return contents;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
inline bool compare(
|
||||
fs::path input_path, fs::path expect_path
|
||||
, F f
|
||||
, char const* re_prefix
|
||||
, char const* re_suffix
|
||||
)
|
||||
{
|
||||
std::string output = f(load(input_path), input_path);
|
||||
std::string expected = load(expect_path);
|
||||
|
||||
auto result = compare(output, expected, re_prefix, re_suffix);
|
||||
if (!result.full_match)
|
||||
{
|
||||
std::cout << "=============================================" << std::endl;
|
||||
std::cout << "==== Mismatch Found:" << std::endl;
|
||||
int line = 1;
|
||||
int col = 1;
|
||||
for (auto i = output.begin(); i != result.pos; ++i)
|
||||
{
|
||||
if (*i == '\n')
|
||||
{
|
||||
line++;
|
||||
col = 0;
|
||||
}
|
||||
++col;
|
||||
}
|
||||
|
||||
std::cerr
|
||||
<< "==== File: " << expect_path
|
||||
<< ", Line: " << line
|
||||
<< ", Column: " << col
|
||||
<< std::endl;
|
||||
std::cerr << "=============================================" << std::endl;
|
||||
|
||||
// Print output
|
||||
std::cerr << output;
|
||||
std::cerr << "=============================================" << std::endl;
|
||||
std::cerr << "==== End" << std::endl;
|
||||
std::cerr << "=============================================" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -1,25 +0,0 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
Copyright (c) 2014 Jamboree
|
||||
|
||||
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_SPIRIT_X3_UNREFCV_HPP_INCLUDED
|
||||
#define BOOST_SPIRIT_X3_UNREFCV_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
template <typename T>
|
||||
struct unrefcv : remove_cv<typename remove_reference<T>::type> {};
|
||||
|
||||
template <typename T>
|
||||
using unrefcv_t = typename unrefcv<T>::type;
|
||||
}}}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2014 Joel de Guzman
|
||||
Copyright (c) 2023 Nikita Kniazev
|
||||
|
||||
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)
|
||||
@@ -7,42 +8,62 @@
|
||||
#if !defined(BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM)
|
||||
#define BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/regex/pending/unicode_iterator.hpp>
|
||||
#include <boost/type_traits/make_unsigned.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
typedef ::boost::uint32_t ucs4_char;
|
||||
typedef char32_t ucs4_char;
|
||||
typedef char utf8_char;
|
||||
typedef std::basic_string<ucs4_char> ucs4_string;
|
||||
typedef std::basic_string<utf8_char> utf8_string;
|
||||
|
||||
namespace detail {
|
||||
inline void utf8_put_encode(utf8_string& out, ucs4_char x)
|
||||
{
|
||||
// https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf D90
|
||||
if (BOOST_UNLIKELY(x > 0x10FFFFul || (0xD7FFul < x && x < 0xE000ul)))
|
||||
x = 0xFFFDul;
|
||||
|
||||
// Table 3-6. UTF-8 Bit Distribution
|
||||
if (x < 0x80ul) {
|
||||
out.push_back(static_cast<unsigned char>(x));
|
||||
}
|
||||
else if (x < 0x800ul) {
|
||||
out.push_back(static_cast<unsigned char>(0xC0ul + (x >> 6)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + (x & 0x3Ful)));
|
||||
}
|
||||
else if (x < 0x10000ul) {
|
||||
out.push_back(static_cast<unsigned char>(0xE0ul + (x >> 12)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + ((x >> 6) & 0x3Ful)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + (x & 0x3Ful)));
|
||||
}
|
||||
else {
|
||||
out.push_back(static_cast<unsigned char>(0xF0ul + (x >> 18)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + ((x >> 12) & 0x3Ful)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + ((x >> 6) & 0x3Ful)));
|
||||
out.push_back(static_cast<unsigned char>(0x80ul + (x & 0x3Ful)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
inline utf8_string to_utf8(Char value)
|
||||
{
|
||||
// always store as UTF8
|
||||
utf8_string result;
|
||||
typedef std::back_insert_iterator<utf8_string> insert_iter;
|
||||
insert_iter out_iter(result);
|
||||
utf8_output_iterator<insert_iter> utf8_iter(out_iter);
|
||||
typedef typename make_unsigned<Char>::type UChar;
|
||||
*utf8_iter = (UChar)value;
|
||||
typedef typename std::make_unsigned<Char>::type UChar;
|
||||
detail::utf8_put_encode(result, static_cast<UChar>(value));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
inline utf8_string to_utf8(Char const* str)
|
||||
{
|
||||
// always store as UTF8
|
||||
utf8_string result;
|
||||
typedef std::back_insert_iterator<utf8_string> insert_iter;
|
||||
insert_iter out_iter(result);
|
||||
utf8_output_iterator<insert_iter> utf8_iter(out_iter);
|
||||
typedef typename make_unsigned<Char>::type UChar;
|
||||
typedef typename std::make_unsigned<Char>::type UChar;
|
||||
while (*str)
|
||||
*utf8_iter++ = (UChar)*str++;
|
||||
detail::utf8_put_encode(result, static_cast<UChar>(*str++));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -50,46 +71,49 @@ namespace boost { namespace spirit { namespace x3
|
||||
inline utf8_string
|
||||
to_utf8(std::basic_string<Char, Traits, Allocator> const& str)
|
||||
{
|
||||
// always store as UTF8
|
||||
utf8_string result;
|
||||
typedef std::back_insert_iterator<utf8_string> insert_iter;
|
||||
insert_iter out_iter(result);
|
||||
utf8_output_iterator<insert_iter> utf8_iter(out_iter);
|
||||
typedef typename make_unsigned<Char>::type UChar;
|
||||
typedef typename std::make_unsigned<Char>::type UChar;
|
||||
for (Char ch : str)
|
||||
{
|
||||
*utf8_iter++ = (UChar)ch;
|
||||
}
|
||||
detail::utf8_put_encode(result, static_cast<UChar>(ch));
|
||||
return result;
|
||||
}
|
||||
|
||||
// Assume wchar_t content is UTF-16 on Windows and UCS-4 on Unix
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
// Assume wchar_t content is UTF-16 on MSVC, or mingw/wineg++ with -fshort-wchar
|
||||
#if defined(_MSC_VER) || defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2
|
||||
inline utf8_string to_utf8(wchar_t value)
|
||||
{
|
||||
utf8_string result;
|
||||
typedef std::back_insert_iterator<utf8_string> insert_iter;
|
||||
insert_iter out_iter(result);
|
||||
utf8_output_iterator<insert_iter> utf8_iter(out_iter);
|
||||
|
||||
u16_to_u32_iterator<wchar_t const*, ucs4_char> ucs4_iter(&value);
|
||||
*utf8_iter++ = *ucs4_iter;
|
||||
|
||||
detail::utf8_put_encode(result, static_cast<std::make_unsigned<wchar_t>::type>(value));
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
inline ucs4_char decode_utf16(wchar_t const*& s)
|
||||
{
|
||||
typedef std::make_unsigned<wchar_t>::type uwchar_t;
|
||||
|
||||
uwchar_t x(*s);
|
||||
if (x < 0xD800ul || x > 0xDFFFul)
|
||||
return x;
|
||||
|
||||
// expected high-surrogate
|
||||
if (BOOST_UNLIKELY((x >> 10) != 0b110110ul))
|
||||
return 0xFFFDul;
|
||||
|
||||
uwchar_t y(*++s);
|
||||
// expected low-surrogate
|
||||
if (BOOST_UNLIKELY((y >> 10) != 0b110111ul))
|
||||
return 0xFFFDul;
|
||||
|
||||
return ((x & 0x3FFul) << 10) + (y & 0x3FFul) + 0x10000ul;
|
||||
}
|
||||
}
|
||||
|
||||
inline utf8_string to_utf8(wchar_t const* str)
|
||||
{
|
||||
utf8_string result;
|
||||
typedef std::back_insert_iterator<utf8_string> insert_iter;
|
||||
insert_iter out_iter(result);
|
||||
utf8_output_iterator<insert_iter> utf8_iter(out_iter);
|
||||
|
||||
u16_to_u32_iterator<wchar_t const*, ucs4_char> ucs4_iter(str);
|
||||
for (ucs4_char c; (c = *ucs4_iter) != ucs4_char(); ++ucs4_iter) {
|
||||
*utf8_iter++ = c;
|
||||
}
|
||||
|
||||
for (ucs4_char c; (c = detail::decode_utf16(str)) != ucs4_char(); ++str)
|
||||
detail::utf8_put_encode(result, c);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user