2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Fix nonascii fields

This commit is contained in:
denzor200
2023-08-20 00:49:14 +03:00
committed by Antony Polukhin
parent ad7ab1cfc3
commit 642d1f7d23
4 changed files with 62 additions and 56 deletions

View File

@@ -40,7 +40,7 @@ consteval auto name_of_field_impl() noexcept {
constexpr std::string_view sv = __PRETTY_FUNCTION__;
constexpr auto last = sv.find_last_not_of(" ])}");
#endif
constexpr auto first = sv.find_last_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789", last);
constexpr auto first = sv.find_last_of(".:->", last);
auto res = std::array<char, last - first + 2>{};
std::ranges::copy(sv.begin()+first+1,
sv.begin()+last+1,

View File

@@ -44,23 +44,20 @@ project
;
########## BEGIN of helpers to prepare the test with non-ascii field name
# TODO: fix it
# actions insert_utf8_action
# {
# sed 's/%ARG%/\xcf\x80/' $(>) > $(<)
# }
# make fields_names_nonascii.cpp : fields_names_nonascii.cpp.tpl : @insert_utf8_action ;
actions invoke_python_generator
{
python $(>) > $(<)
}
########## END of helpers to prepare the test with non-ascii field name
make fields_names_nonascii.cpp : generate_fields_names_nonascii.cpp.py : @invoke_python_generator ;
test-suite pfr_tests
:
[ run fields_names.cpp : : : : ]
[ run fields_names_constexpr.cpp : : : : ]
# [ run fields_names_nonascii.cpp : : : : ]
[ run fields_names_nonascii.cpp : : : <toolset>msvc:<cxxflags>"/utf-8" : ]
;

View File

@@ -1,46 +0,0 @@
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
//
// 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)
// Initial implementation by Bela Schaum, https://github.com/schaumb
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
//
#include <boost/pfr/core_name.hpp>
#include <boost/core/lightweight_test.hpp>
namespace testing {
struct Aggregate {
int _%ARG%;
};
void test_get_name() {
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate>())), "_%ARG%");
}
void test_names_as_array() {
const auto expected = std::array<std::string_view, 1>{
"_%ARG%"
};
const auto value = boost::pfr::names_as_array<Aggregate>();
BOOST_TEST_EQ(expected.size(), value.size());
for (std::size_t i=0;i<expected.size();++i) {
BOOST_TEST_EQ(value[i], expected[i]);
}
}
} // namespace testing
int main() {
testing::test_get_name();
testing::test_names_as_array();
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
# Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
#
# 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)
# Initial implementation by Bela Schaum, https://github.com/schaumb
# The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
#
############################################################################################################################
import sys
import string
TEMPLATE = """#include <boost/pfr/core_name.hpp>
#include <boost/core/lightweight_test.hpp>
namespace testing {
struct Aggregate {
int _%ARG%;
};
void test_get_name() {
BOOST_TEST_EQ( ((boost::pfr::get_name<0, Aggregate>())), "_%ARG%");
}
void test_names_as_array() {
const auto expected = std::array<std::string_view, 1>{
"_%ARG%"
};
const auto value = boost::pfr::names_as_array<Aggregate>();
BOOST_TEST_EQ(expected.size(), value.size());
for (std::size_t i=0;i<expected.size();++i) {
BOOST_TEST_EQ(value[i], expected[i]);
}
}
} // namespace testing
int main() {
testing::test_get_name();
testing::test_names_as_array();
return boost::report_errors();
}
"""
############################################################################################################################
sys.stdout.reconfigure(encoding='utf-8')
print(TEMPLATE.replace('%ARG%', (b'\xcf\x80').decode('utf-8')))