2
0
mirror of https://github.com/boostorg/spirit.git synced 2026-01-19 04:42:11 +00:00

Modernize char/string, use X3's own char_encoding

This commit is contained in:
Nana Sakisaka
2025-09-08 10:02:43 +09:00
parent 5fb8252115
commit c28805b591
42 changed files with 2343 additions and 1869 deletions

View File

@@ -1,5 +1,6 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2025 Nana Sakisaka
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)
@@ -8,7 +9,6 @@
#include <boost/phoenix.hpp>
#include <boost/unordered_map.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/cstdint.hpp>
#include <boost/foreach.hpp>
#include <boost/array.hpp>
#include <boost/scoped_array.hpp>
@@ -22,10 +22,12 @@
#include <string>
#include <map>
#include <cstdint>
// We place the data here. Each line comprises various fields
typedef std::vector<std::string> ucd_line;
typedef std::vector<ucd_line> ucd_vector;
typedef std::vector<ucd_line>::iterator ucd_iterator;
using ucd_line = std::vector<std::string>;
using ucd_vector = std::vector<ucd_line>;
using ucd_iterator = std::vector<ucd_line>::iterator;
// spirit and phoenix using declarations
using boost::spirit::qi::parse;
@@ -40,9 +42,9 @@ using boost::phoenix::push_back;
using boost::phoenix::ref;
// basic unsigned types
using boost::uint8_t;
using boost::uint16_t;
using boost::uint32_t;
using std::uint8_t;
using std::uint16_t;
using std::uint32_t;
enum code_action
{
@@ -535,15 +537,16 @@ void print_head(Out& out)
out
<< "/*=============================================================================\n"
<< " Copyright (c) 2001-2011 Joel de Guzman\n"
<< " Copyright (c) 2025 Nana Sakisaka\n"
<< "\n"
<< " Distributed under the Boost Software License, Version 1.0. (See accompanying\n"
<< " file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n"
<< "\n"
<< " AUTOGENERATED. DO NOT EDIT!!!\n"
<< "==============================================================================*/\n"
<< "#include <boost/cstdint.hpp>\n"
<< "#include <cstdint>\n"
<< "\n"
<< "namespace boost { namespace spirit { namespace ucd { namespace detail\n"
<< "namespace boost::spirit::x3::unicode::detail\n"
<< "{"
;
}
@@ -553,7 +556,7 @@ void print_tail(Out& out)
{
out
<< "\n"
<< "}}}} // namespace boost::spirit::unicode::detail\n"
<< "} // boost::spirit::x3::unicode::detail\n"
;
}
@@ -561,10 +564,10 @@ char const* get_int_type_name(int size)
{
switch (size)
{
case 1: return "::boost::uint8_t";
case 2: return "::boost::uint16_t";
case 4: return "::boost::uint32_t";
case 5: return "::boost::uint64_t";
case 1: return "std::uint8_t";
case 2: return "std::uint16_t";
case 4: return "std::uint32_t";
case 5: return "std::uint64_t";
default: BOOST_ASSERT(false); return 0; // invalid size
};
}
@@ -588,7 +591,7 @@ void print_file(Out& out, Builder& builder, int field_width, char const* name)
out
<< "\n"
<< " static const ::boost::uint8_t " << name << "_stage1[] = {\n"
<< " inline constexpr std::uint8_t " << name << "_stage1[] = {\n"
<< "\n"
;
@@ -600,7 +603,7 @@ void print_file(Out& out, Builder& builder, int field_width, char const* name)
<< " };"
<< "\n"
<< "\n"
<< " static const " << int_name << ' ' << name << "_stage2[] = {"
<< " inline constexpr " << int_name << ' ' << name << "_stage2[] = {"
;
int block_n = 0;
@@ -621,9 +624,9 @@ void print_file(Out& out, Builder& builder, int field_width, char const* name)
out
<< "\n"
<< " inline " << int_name << ' ' << name << "_lookup(::boost::uint32_t ch)\n"
<< " [[nodiscard]] constexpr " << int_name << ' ' << name << "_lookup(std::uint32_t ch) noexcept\n"
<< " {\n"
<< " ::boost::uint32_t block_offset = " << name << "_stage1[ch / " << block_size << "] * " << block_size << ";\n"
<< " std::uint32_t block_offset = " << name << "_stage1[ch / " << block_size << "] * " << block_size << ";\n"
<< " return " << name << "_stage2[block_offset + ch % " << block_size << "];\n"
<< " }\n"
;
@@ -666,6 +669,4 @@ int main()
builder.collect("UnicodeData.txt", 12, assign_code_value);
print_file(out, builder, 6, "uppercase");
}
return 0;
}