Skip to content

Commit

Permalink
馃洜 Minor build system tweaks and some fixes!
Browse files Browse the repository at this point in the history
- 馃挰 I am not going to have fun with some of these new build errors from -Wall...!
  • Loading branch information
ThePhD committed Jul 1, 2021
1 parent eb0f895 commit 1f7b896
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 57 deletions.
28 changes: 23 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ if (ZTD_TEXT_IS_TOP_LEVEL_PROJECT)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/${CFG_INT_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/${CFG_INT_DIR}/bin")
endif()

if (NOT CMAKE_CXX_STANDARD GREATER_EQUAL 20)
set(CMAKE_CXX_STANDARD 20)
endif()

if (NOT CMAKE_C_STANDARD GREATER_EQUAL 11)
set(CMAKE_C_STANDARD 11)
endif()

# normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)
# Warning flags
check_compiler_flag(warn-pedantic MSVC /permissive- GCC -pedantic)
check_compiler_flag(warn-all MSVC /W4 GCC -Wall)
check_compiler_flag(warn-errors MSVC /WX GCC -Werror)
check_compiler_flag(utf8-literal-encoding MSVC /execution-charset:utf-8 GCC -fexec-charset=utf-8)
check_compiler_flag(utf8-source-encoding MSVC /source-charset:utf-8 GCC -finput-charset=utf-8)
check_compiler_flag(extra-constexpr-depth MSVC /constexpr:depth2147483647 GCC -fconstexpr-depth=2147483647 CLANG -fconstexpr-depth=2147483647)
check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 CLANG -fconstexpr-steps=2147483647)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0)
endif()

# # Options
Expand All @@ -80,10 +100,6 @@ option(ZTD_TEXT_BENCHMARKS "Enable build of benchmarks" OFF)
option(ZTD_TEXT_GENERATE_SINGLE "Enable generation of a single header and its target" OFF)
option(ZTD_TEXT_USE_CUNEICODE "Enable generation of a single header and its target" OFF)

if (NOT CMAKE_CXX_STANDARD GREATER_EQUAL 20)
set(CMAKE_CXX_STANDARD 20)
endif()

# # Dependencies
# includes
include(CheckIPOSupported)
Expand Down Expand Up @@ -118,7 +134,7 @@ add_library(ztd::text ALIAS ztd.text)
target_include_directories(ztd.text
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_sources(ztd.text INTERFACE ${ztd.text.includes})
target_link_libraries(ztd.text
INTERFACE
Expand Down Expand Up @@ -166,6 +182,8 @@ if (ZTD_TEXT_EXAMPLES)
add_subdirectory(examples)
endif()

# For quick debugging and development only: don't peek! 馃檲
mark_as_advanced(ZTD_TEXT_SCRATCH)
if (ZTD_TEXT_SCRATCH)
add_executable(scratch main.cpp)
target_link_libraries(scratch PRIVATE ztd::text)
Expand Down
17 changes: 10 additions & 7 deletions examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ foreach (example_source_name ${ztd.text.examples.basic.sources})
set(example_source_file source/${example_source_name})
set(example_target ztd.text.examples.basic.${example_source_name})
add_executable(${example_target} ${example_source_file})
if (MSVC)
target_compile_options(${example_target}
PRIVATE /std:c++latest /utf-8 /permissive-)
else()
target_compile_options(${example_target}
PRIVATE -std=c++2a -Wall -Werror -Wpedantic)
endif()
target_compile_options(${example_target}
PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-errors}
)

target_link_libraries(${example_target}
PRIVATE
ztd::text
Expand Down
16 changes: 9 additions & 7 deletions examples/boost.text/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ target_compile_definitions(ztd.text.examples.boost_text
PRIVATE
ZTD_TEXT_COMPILE_TIME_ENCODING_NAME="UTF-8"
)
if (MSVC)
target_compile_options(ztd.text.examples.boost_text
PRIVATE /std:c++latest /utf-8 /permissive-)
else()
target_compile_options(ztd.text.examples.boost_text
PRIVATE -std=c++2a -Wall -Werror -Wpedantic -fexec-charset=UTF-8)
endif()
target_compile_options(ztd.text.examples.boost_text
PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-errors})

target_include_directories(ztd.text.examples.boost_text
PRIVATE
${Boost_INCLUDE_DIRS}
Expand Down
16 changes: 9 additions & 7 deletions examples/documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ foreach (example_source_name ${ztd.text.examples.documentation.sources})
set(example_source_file source/${example_source_name})
set(example_target ztd.text.examples.documentation.${example_source_name})
add_executable(${example_target} ${example_source_file})
if (MSVC)
target_compile_options(${example_target}
PRIVATE /std:c++latest /utf-8 /permissive-)
else()
target_compile_options(${example_target}
PRIVATE -std=c++2a -Wall -Werror -Wpedantic)
endif()
target_compile_options(${example_target}
PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-errors})

target_link_libraries(${example_target}
PRIVATE
ztd::text
Expand Down
4 changes: 4 additions & 0 deletions examples/documentation/source/error_handler.anatomy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct my_error_handler {
// Third Parameter
code_point_span<Encoding> progress) const noexcept {
// ... implementation here!
(void)encoding;
(void)progress;
return result;
}

Expand All @@ -66,6 +68,8 @@ struct my_error_handler {
// Third Parameter
code_unit_span<Encoding> progress) const noexcept {
// ... implementation here!
(void)encoding;
(void)progress;
return result;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using ascii_encode_result = ztd::text::encode_result<
ascii_encode_result my_printing_handler(const ztd::text::ascii& encoding,
ascii_encode_result result,
ztd::text::span<const char32_t> unused_read_characters) noexcept {
(void)encoding;
// just printing some information
std::cout << "An error occurred.\n"
<< "\tError code value: "
Expand Down
1 change: 1 addition & 0 deletions examples/documentation/source/runtime_locale_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class runtime_locale {
};

int main(int argc, char* argv[]) {
(void)argc;
// Text coming in from the command line / program arguments
// is (usually) encoded by the runtime locale
runtime_locale encoding {};
Expand Down
20 changes: 11 additions & 9 deletions examples/shift_jis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ add_custom_target(ztd.text.examples.shift_jis.data
file(GLOB_RECURSE ztd.text.examples.shift_jis.sources LIST_DIRECTORIES false
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS
source/*.cpp)

add_executable(ztd.text.examples.shift_jis ${ztd.text.examples.shift_jis.sources})
if (MSVC)
target_compile_options(ztd.text.examples.shift_jis
PRIVATE /std:c++latest /utf-8 /permissive-)
else()
target_compile_options(ztd.text.examples.shift_jis
PRIVATE -std=c++2a -Wall -Werror -Wpedantic)
endif()
target_compile_options(ztd.text.examples.shift_jis
PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-errors}
)
target_include_directories(ztd.text.examples.shift_jis
PRIVATE
../include
include)
include
)
target_link_libraries(ztd.text.examples.shift_jis
PRIVATE
ztd::text
Expand Down
12 changes: 6 additions & 6 deletions examples/shift_jis/source/shift_jis_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace {

std::array<std::pair<std::uint_least16_t, std::uint_least16_t>, 7724> index_codepoint_map { { { 0, 0x3000 },
std::array<std::pair<std::uint_least32_t, std::uint_least32_t>, 7724> index_codepoint_map { { { 0, 0x3000 },
{ 1, 0x3001 }, { 2, 0x3002 }, { 3, 0xFF0C }, { 4, 0xFF0E }, { 5, 0x30FB }, { 6, 0xFF1A }, { 7, 0xFF1B },
{ 8, 0xFF1F }, { 9, 0xFF01 }, { 10, 0x309B }, { 11, 0x309C }, { 12, 0x00B4 }, { 13, 0xFF40 }, { 14, 0x00A8 },
{ 15, 0xFF3E }, { 16, 0xFFE3 }, { 17, 0xFF3F }, { 18, 0x30FD }, { 19, 0x30FE }, { 20, 0x309D },
Expand Down Expand Up @@ -1339,36 +1339,36 @@ namespace {
{ 11100, 0x9D6B }, { 11101, 0xFA2D }, { 11102, 0x9E19 }, { 11103, 0x9ED1 } } };

static bool less_than_index_target(
std::pair<std::uint_least16_t, std::uint_least16_t> value, std::uint_least16_t target) {
std::pair<std::uint_least32_t, std::uint_least32_t> value, std::uint_least32_t target) {
return value.first < target;
}

} // namespace

namespace detail {
std::optional<char32_t> shift_jis_index_to_code_point(std::size_t lookup_index_pointer) noexcept {
std::uint_least16_t lookup_index = static_cast<std::uint_least16_t>(lookup_index_pointer);
std::uint_least32_t lookup_index = static_cast<std::uint_least32_t>(lookup_index_pointer);
auto it = std::lower_bound(
index_codepoint_map.cbegin(), index_codepoint_map.cend(), lookup_index, &less_than_index_target);
if (it == index_codepoint_map.cend()) {
return std::nullopt;
}
const std::pair<std::uint_least16_t, std::uint_least16_t> index_and_codepoint = *it;
const std::pair<std::uint_least32_t, std::uint_least32_t> index_and_codepoint = *it;
if (index_and_codepoint.first != lookup_index) {
return std::nullopt;
}
return static_cast<char32_t>(index_and_codepoint.second);
}

std::optional<std::size_t> shift_jis_code_point_to_index(char32_t code) noexcept {
auto predicate = [&code](const std::pair<std::uint_least16_t, std::uint_least16_t>& value) {
auto predicate = [&code](const std::pair<std::uint_least32_t, std::uint_least32_t>& value) {
return code == value.second && !(value.first < 8272 && value.first > 8835);
};
auto it = std::find_if(index_codepoint_map.cbegin(), index_codepoint_map.cend(), predicate);
if (it == index_codepoint_map.cend()) {
return std::nullopt;
}
const std::pair<std::uint_least16_t, std::uint_least16_t> index_and_codepoint = *it;
const std::pair<std::uint_least32_t, std::uint_least32_t> index_and_codepoint = *it;
return static_cast<std::size_t>(index_and_codepoint.first);
}
} // namespace detail
1 change: 1 addition & 0 deletions include/ztd/text/detail/adl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <ztd/text/detail/type_traits.hpp>

#include <iterator>
#include <limits>

#include <ztd/text/detail/prologue.hpp>

Expand Down
90 changes: 85 additions & 5 deletions include/ztd/text/error_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,42 @@ namespace ztd { namespace text {
"specified encoding type.");
}
}

template <typename _Encoding>
constexpr ::std::size_t __fill_replacement_code_unit_static(const _Encoding& __encoding,
code_unit_t<_Encoding> (&__replacement_code_units)[max_code_units_v<_Encoding>]) {
using _InputCodeUnit = code_unit_t<_Encoding>;
if constexpr (is_code_units_replaceable_v<_Encoding>) {
::std::size_t __replacement_index = 0;
for (const auto& __element : __encoding.replacement_code_units()) {
__replacement_code_units[__replacement_index] = static_cast<_InputCodeUnit>(__element);
++__replacement_index;
}
return __replacement_index;
}
else if constexpr (is_code_units_maybe_replaceable_v<_Encoding>) {
::std::size_t __replacement_index = 0;
decltype(auto) __maybe_code_units = __encoding.maybe_replacement_code_units();
if (__maybe_code_units) {
decltype(auto) __code_units
= *::std::forward<decltype(__maybe_code_units)>(__maybe_code_units);
for (const auto& __element : __code_units) {
__replacement_code_units[__replacement_index] = static_cast<_InputCodeUnit>(__element);
++__replacement_index;
}
}
return __replacement_index;
}
else if constexpr (is_unicode_code_point_v<_InputCodeUnit>) {
__replacement_code_units[0] = static_cast<_InputCodeUnit>(__replacement);
return 1;
}
else {
static_assert(__always_false_v<_Encoding>,
"There is no logical replacement code points to insert into the stream on failure for the "
"specified encoding type.");
}
}
} // namespace __txt_detail

//////
Expand Down Expand Up @@ -260,11 +296,11 @@ namespace ztd { namespace text {
// into the stream... report error and bail
return __result;
}
}

__result.error_code = encoding_error::ok;
__result.error_code = encoding_error::ok;

return __result;
return __result;
}
}

//////
Expand All @@ -274,7 +310,7 @@ namespace ztd { namespace text {
/// @param[in] __encoding The Encoding that experienced the error.
/// @param[in] __result The current state of the encode operation.
///
/// @remarks TODO: describe the replacement process thoroughly.
/// @remarks TODO: describe the replacement process thoroughly and fix this!
//////
template <typename _Encoding, typename _InputRange, typename _OutputRange, typename _State,
typename _Progress>
Expand All @@ -285,7 +321,51 @@ namespace ztd { namespace text {
return __result;
}

return __txt_detail::__write_static_code_points_direct(__encoding, ::std::move(__result));
auto __outit = __txt_detail::__adl::__adl_begin(__result.output);
auto __outlast = __txt_detail::__adl::__adl_end(__result.output);
if (__outit == __outlast) {
// BAIL
return __result;
}

if constexpr (is_code_points_replaceable_v<_Encoding>) {
return __txt_detail::__write_direct(
__encoding, __encoding.replacement_code_points(), ::std::move(__result));
}
else {
using _InputCodeUnit = code_unit_t<_Encoding>;
_InputCodeUnit __replacement[max_code_points_v<_Encoding>];
::std::size_t __replacement_size = 0;
if constexpr (is_code_units_replaceable_v<_Encoding>) {
auto __replacement_code_units = __encoding.replacement_code_units();
for (const auto& __element : __replacement_code_units) {
__replacement[__replacement_size] = __element;
++__replacement_size;
}
}
else {
__replacement_size
= __txt_detail::__fill_replacement_code_unit_static(__encoding, __replacement);
}

const ::ztd::text::span<const _InputCodeUnit> __replacement_range(
__replacement, __replacement_size);

__txt_detail::__pass_through_handler __handler {};
decode_state_t<_Encoding> __state = make_decode_state(__encoding);
auto __decresult = __txt_detail::__basic_decode_one<__txt_detail::__consume::__no>(
__replacement_range, __encoding, ::std::move(__result.output), __handler, __state);
__result.output = ::std::move(__decresult.output);
if (__decresult.error_code != encoding_error::ok) {
// we can't even encode a single code point
// into the stream... report error and bail
return __result;
}
}

__result.error_code = encoding_error::ok;

return __result;
}
};

Expand Down

0 comments on commit 1f7b896

Please sign in to comment.