Skip to content

Commit

Permalink
✨ Move Windows and POSIX tests elsewhere!
Browse files Browse the repository at this point in the history
— 🛠 Use definitive compile-time (and some runtime) tests for UTF8, there are more places for UTF-16/32, though.
  • Loading branch information
ThePhD committed Nov 20, 2021
1 parent 574eff4 commit a562a6a
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 295 deletions.
5 changes: 2 additions & 3 deletions include/ztd/text/detail/iconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@

#include <ztd/text/version.hpp>

#include <ztd/text/detail/windows.hpp>
#include <ztd/text/detail/posix.hpp>
#include <ztd/idk/detail/windows.hpp>
#include <ztd/idk/detail/posix.hpp>

#if ZTD_IS_ON(ZTD_LIBICONV_I_)

#if ZTD_IS_ON(ZTD_ICONV_H_I_)
#include <iconv.h>
#elif ZTD_IS_ON(ZTD_LIBICONV_LOAD_I_)
#if ZTD_IS_ON(ZTD_PLATFORM_POSIX_I_)
#include <dlfcn.h>
#elif ZTD_IS_ON(ZTD_PLATFORM_WINDOWS_I_)
// taken care of above
#else
Expand Down
91 changes: 0 additions & 91 deletions include/ztd/text/detail/posix.hpp

This file was deleted.

88 changes: 0 additions & 88 deletions include/ztd/text/detail/windows.hpp

This file was deleted.

36 changes: 7 additions & 29 deletions include/ztd/text/impl/execution_cuchar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
#include <ztd/text/type_traits.hpp>
#include <ztd/text/assert.hpp>
#include <ztd/text/detail/progress_handler.hpp>
#include <ztd/text/detail/windows.hpp>
#include <ztd/text/detail/posix.hpp>
#include <ztd/text/detail/encoding_name.hpp>

#include <ztd/ranges/range.hpp>
#include <ztd/idk/span.hpp>
#include <ztd/idk/encoding_detection.h>
#include <ztd/idk/detail/windows.hpp>

#if ZTD_IS_ON(ZTD_CUCHAR_I_) || ZTD_IS_ON(ZTD_UCHAR_I_)

Expand Down Expand Up @@ -201,22 +201,7 @@ namespace ztd { namespace text {
/// `std::setlocale` name checking otherwise).
//////
static bool contains_unicode_encoding() noexcept {
#if ZTD_IS_ON(ZTD_PLATFORM_WINDOWS_I_)
int __codepage_id = __txt_detail::__windows::__determine_active_code_page();
return __txt_detail::__windows::__is_unicode_code_page(__codepage_id);
#else
#if ZTD_IS_ON(ZTD_NL_LANGINFO_I_) || ZTD_IS_ON(ZTD_LANGINFO_I_)
const char* __ctype_name = nl_langinfo(CODESET);
#else
const char* __ctype_name = setlocale(LC_CTYPE, nullptr);
#endif
::std::string_view __adjusted_ctype_name(__ctype_name);
::std::size_t __index = __adjusted_ctype_name.find_first_of(".");
if (__index != ::std::string_view::npos) {
__adjusted_ctype_name = __adjusted_ctype_name.substr(__index);
}
return ::ztd::is_unicode_encoding_name(__adjusted_ctype_name);
#endif
return ztdc_is_execution_encoding_unicode();
}

//////
Expand Down Expand Up @@ -253,8 +238,7 @@ namespace ztd { namespace text {
= __txt_detail::__reconstruct_encode_result_t<_InputRange, _OutputRange, encode_state>;
constexpr bool __call_error_handler = !is_ignorable_error_handler_v<_UErrorHandler>;

#if ZTD_IS_ON(ZTD_PLATFORM_WINDOWS_I_)
if (__txt_detail::__windows::__determine_active_code_page() == CP_UTF8) {
if (ztdc_is_execution_encoding_utf8()) {
// just go straight to UTF8
using __execution_utf8 = __txt_impl::__utf8_with<__execution_cuchar, code_unit, code_point,
decode_state, encode_state>;
Expand All @@ -263,7 +247,6 @@ namespace ztd { namespace text {
::std::forward<_OutputRange>(__output), ::std::forward<_ErrorHandler>(__error_handler),
__s);
}
#endif // Windows Hell

#if ZTD_IS_ON(ZTD_PLATFORM_WINDOWS_I_)
auto __outit = ranges::ranges_adl::adl_begin(__output);
Expand Down Expand Up @@ -311,7 +294,7 @@ namespace ztd { namespace text {
::ztd::span<const wchar_t> __wide_read_buffer(
__wide_intermediary, __intermediate_result.output.data());
int __res = ::WideCharToMultiByte(
static_cast<UINT>(__txt_detail::__windows::__determine_active_code_page()),
static_cast<UINT>(__idk_detail::__windows::__determine_active_code_page()),
WC_ERR_INVALID_CHARS, __wide_read_buffer.data(), static_cast<int>(__wide_read_buffer.size()),
__intermediary_output, __state_count_max, ::std::addressof(replacement_code_units[0]),
::std::addressof(__used_default_char));
Expand Down Expand Up @@ -459,9 +442,7 @@ namespace ztd { namespace text {
= __txt_detail::__reconstruct_decode_result_t<_InputRange, _OutputRange, decode_state>;
constexpr bool __call_error_handler = !is_ignorable_error_handler_v<_UErrorHandler>;

#if ZTD_IS_ON(ZTD_PLATFORM_WINDOWS_I_)
if (__txt_detail::__windows::__determine_active_code_page() == CP_UTF8) {
// just use utf8_t directly
if (ztdc_is_execution_encoding_utf8()) {
// just go straight to UTF8
using __execution_utf8 = __txt_impl::__utf8_with<__execution_cuchar, code_unit, code_point,
decode_state, encode_state>;
Expand All @@ -470,7 +451,6 @@ namespace ztd { namespace text {
::std::forward<_OutputRange>(__output), ::std::forward<_ErrorHandler>(__error_handler),
__s);
}
#endif

auto __init = ranges::ranges_adl::adl_begin(__input);
auto __inlast = ranges::ranges_adl::adl_end(__input);
Expand Down Expand Up @@ -512,7 +492,7 @@ namespace ztd { namespace text {
constexpr const int __wide_intermediary_size = 4;
wchar_t __wide_intermediary[__wide_intermediary_size] {};
int __res = ::MultiByteToWideChar(
static_cast<UINT>(__txt_detail::__windows::__determine_active_code_page()),
static_cast<UINT>(__idk_detail::__windows::__determine_active_code_page()),
MB_ERR_INVALID_CHARS, __intermediary_input, static_cast<int>(__state_count),
__wide_intermediary, __wide_intermediary_size);
if (__res == 0) {
Expand Down Expand Up @@ -713,8 +693,6 @@ namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text

#undef ZTD_UCHAR_ACCESSOR_I_

#include <ztd/epilogue.hpp>

#endif
Expand Down
25 changes: 5 additions & 20 deletions include/ztd/text/impl/wide_execution_cwchar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@

#include <ztd/ranges/range.hpp>
#include <ztd/idk/span.hpp>
#include <ztd/idk/encoding_detection.h>

#include <ztd/prologue.hpp>

#include <cwchar>
#include <iterator>
#include <utility>
#if ZTD_IS_ON(ZTD_LOCALE_DEPENDENT_WIDE_EXECUTION_I_)
#include <clocale>
#endif

namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_
Expand Down Expand Up @@ -191,25 +189,12 @@ namespace ztd { namespace text {
/// `std::setlocale` name checking otherwise).
//////
static bool contains_unicode_encoding() noexcept {
execution_t __execution {};
if (!text::contains_unicode_encoding(__execution)) {
// even if the wide encoding is unicode, we have to round-trip through the execution encoding, so if
// this doesn't work then nothing works with all unicode code points!
if (!ztdc_is_execution_encoding_unicode()) {
return false;
}
#if ZTD_IS_ON(ZTD_LOCALE_DEPENDENT_WIDE_EXECUTION_I_)
#if ZTD_IS_ON(ZTD_NL_LANGINFO_I_) || ZTD_IS_ON(ZTD_LANGINFO_I_)
const char* __ctype_name = nl_langinfo(CODESET);
#else
const char* __ctype_name = setlocale(LC_CTYPE, nullptr);
#endif
::std::string_view __adjusted_ctype_name(__ctype_name);
::std::size_t __index = __adjusted_ctype_name.find_first_of(".");
if (__index != ::std::string_view::npos) {
__adjusted_ctype_name = __adjusted_ctype_name.substr(__index);
}
return ::ztd::is_unicode_encoding_name(__adjusted_ctype_name);
#else
return true;
#endif
return ztdc_is_wide_execution_encoding_unicode();
}

//////
Expand Down
2 changes: 0 additions & 2 deletions include/ztd/text/impl/wide_execution_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
#include <ztd/ranges/range.hpp>
#include <ztd/idk/span.hpp>

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

#if ZTD_IS_ON(ZTD_PLATFORM_WINDOWS_I_)

#include <iterator>
Expand Down
31 changes: 0 additions & 31 deletions tests/inclusion/source/ztd/text/detail/posix.cpp

This file was deleted.

0 comments on commit a562a6a

Please sign in to comment.