Skip to content

Commit

Permalink
✨ mbstate_t proxy type for ztd/idk because Android and MacOS are a pain!
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Oct 28, 2023
1 parent 5413729 commit 00c82f4
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 46 deletions.
4 changes: 2 additions & 2 deletions include/ztd/idk/charN_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef ZTD_CHAR8_T_I_ ztd_char8_t;
typedef char16_t ztd_char16_t;
typedef char32_t ztd_char32_t;
#else
#if ZTD_IS_ON(ZTD_UCHAR)
#if ZTD_IS_ON(ZTD_UCHAR_H)
#include <uchar.h>

typedef char16_t ztd_char16_t;
Expand All @@ -72,7 +72,7 @@ typedef ZTD_CHAR8_T_I_ ztd_char8_t;
typedef uint_least32_t ztd_char32_t;
#endif

#if ZTD_IS_ON(ZTD_WCHAR)
#if ZTD_IS_ON(ZTD_WCHAR_H)
#include <wchar.h>

typedef wchar_t ztd_wchar_t;
Expand Down
3 changes: 2 additions & 1 deletion include/ztd/idk/char_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <ztd/idk/version.hpp>

#include <ztd/idk/charN_t.hpp>
#include <ztd/idk/mbstate_t.hpp>
#include <ztd/idk/type_traits.hpp>
#include <ztd/ranges/algorithm.hpp>

Expand All @@ -55,7 +56,7 @@ namespace ztd {
using int_type = ::std::int_least32_t;
using pos_type = ::std::streampos;
using off_type = ::std::streamoff;
using state_type = ::std::mbstate_t;
using state_type = ztd_mbstate_t;

static constexpr char_type* copy(
char_type* __destination, const char_type* __source, ::std::size_t __count) noexcept {
Expand Down
6 changes: 3 additions & 3 deletions include/ztd/idk/detail/posix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

// clang-format off
#include <clocale>
#if ZTD_IS_ON(ZTD_LANGINFO)
#if ZTD_IS_ON(ZTD_LANGINFO_H)
extern "C" {
#include <langinfo.h>
}
#elif ZTD_IS_ON(ZTD_NL_LANGINFO)
#elif ZTD_IS_ON(ZTD_NL_LANGINFO_H)
// IBM-specific??
extern "C" {
#include <nl_langinfo.h>
Expand All @@ -66,7 +66,7 @@ namespace ztd {
namespace __idk_detail { namespace __posix {

inline text_encoding_id __determine_active_code_page() noexcept {
#if ZTD_IS_ON(ZTD_LANGINFO) || ZTD_IS_ON(ZTD_NL_LANGINFO)
#if ZTD_IS_ON(ZTD_NL_LANGINFO)
const char* __name = nl_langinfo(LC_CTYPE);
return __idk_detail::__to_encoding_id(__name);
#else
Expand Down
52 changes: 52 additions & 0 deletions include/ztd/idk/mbstate_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ============================================================================
//
// ztd.idk
// Copyright © 2022-2023 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: [email protected]
//
// Commercial License Usage
// Licensees holding valid commercial ztd.cuneicode licenses may use this file
// in accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact [email protected].
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ========================================================================= //

#ifndef ZTD_IDK_MBSTATE_H
#define ZTD_IDK_MBSTATE_H

#pragma once

#include <ztd/version.h>

#if ZTD_IS_ON(ZTD_CWCHAR)
#include <cwchar>
#elif ZTD_IS_ON(ZTD_WCHAR_H)
#include <wchar.h>
#endif
#if ZTD_IS_ON(ZTD_CUCHAR)
#include <cuchar>
#elif ZTD_IS_ON(ZTD_UCHAR_H)
ZTD_EXTERN_C_OPEN_I_
#include <uchar.h>
ZTD_EXTERN_C_CLOSE_I_
#endif

typedef ZTD_MBSTATE_SCOPE_I_ mbstate_t ztd_mbstate_t;

#endif
39 changes: 39 additions & 0 deletions include/ztd/idk/mbstate_t.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ============================================================================
//
// ztd.idk
// Copyright © 2022-2023 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: [email protected]
//
// Commercial License Usage
// Licensees holding valid commercial ztd.cuneicode licenses may use this file
// in accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact [email protected].
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ========================================================================= //

#ifndef ZTD_IDK_MBSTATE_HPP
#define ZTD_IDK_MBSTATE_HPP

#pragma once

#include <ztd/version.h>

#include <ztd/idk/mbstate_t.h>

#endif
2 changes: 2 additions & 0 deletions include/ztd/idk/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ namespace std {

// Use home-grown span from Martin Moene
#define span_FEATURE_MAKE_SPAN 1
#define span_FEATURE_COMPARISON 1
#define span_FEATURE_WITH_INITIALIZER_LIST_P2447 1
#include <ztd/idk/detail/span.implementation.hpp>

#include <ztd/prologue.hpp>
Expand Down
3 changes: 2 additions & 1 deletion include/ztd/tests/basic_unicode_strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,8 @@ namespace ztd { namespace tests {
(CharType)0x75, (CharType)0x72, (CharType)0xc3, (CharType)0xa9, (CharType)0x6c, (CharType)0x69,
(CharType)0x65, (CharType)0x2e, (CharType)0x00 };
inline constexpr std::size_t x_u8_unicode_sequence_truth_native_endian_storage_size
= sizeof(x_u8_unicode_sequence_truth_native_endian_storage<char>);
= /* GCC 13.2 x86_64 GNU Linux bug??? sizeof(x_u8_unicode_sequence_truth_native_endian_storage<char>)*/
2109;


inline constexpr const std::basic_string_view<char32_t> u32_unicode_sequence_truth_native_endian
Expand Down
2 changes: 1 addition & 1 deletion include/ztd/version/detail/version.c++.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#elif ZTD_IS_ON(ZTD_COMPILER_CLANG)
// clang is busted right now!
// taking bets: Clang 17 is when it'll get fixed!
#if (__clang_major__ >= 17)
#if (__clang_major__ >= 17) && defined(__cpp_concepts) && (__cpp_concepts >= 201907LL)
#define ZTD_STD_CONCEPTS_I_ ZTD_DEFAULT_ON
#else
#define ZTD_STD_CONCEPTS_I_ ZTD_DEFAULT_OFF
Expand Down
124 changes: 91 additions & 33 deletions include/ztd/version/detail/version.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@
#define ZTD_PLATFORM_SUNOS_I_ ZTD_DEFAULT_OFF
#endif // SunOS

#if defined(ZTD_PLATFORM_ANDROID)
#if (ZTD_PLATFORM_ANDROID_I_ != 0)
#define ZTD_PLATFORM_ANDROID_I_ ZTD_ON
#else
#define ZTD_PLATFORM_ANDROID_I_ ZTD_OFF
#endif
#elif defined(__ANDROID_API__) && (__ANDROID_API__ > 0)
#define ZTD_PLATFORM_ANDROID_I_ ZTD_DEFAULT_ON
#else
#define ZTD_PLATFORM_ANDROID_I_ ZTD_DEFAULT_OFF
#endif // Android (NDK)

#if defined(ZTD_PLATFORM_ANDROID_VERSION)
#define ZTD_PLATFORM_ANDROID_I_ ZTD_PLATFORM_ANDROID_VERSION
#elif ZTD_IS_ON(ZTD_PLATFORM_ANDROID)
#define ZTD_PLATFORM_ANDROID_VERSION_I_ __ANDROID_API__
#else
#define ZTD_PLATFORM_ANDROID_VERSION_I_ 0
#endif

#if defined(ZTD_PLATFORM_UNIX)
#if (ZTD_PLATFORM_UNIX != 0)
#define ZTD_PLATFORM_UNIX_I_ ZTD_ON
Expand Down Expand Up @@ -380,17 +400,25 @@
#endif


#if defined(ZTD_NL_LANGINFO)
#if (ZTD_NL_LANGINFO != 0)
#define ZTD_NL_LANGINFO_I_ ZTD_ON
#if defined(ZTD_NL_LANGINFO_H)
#if (ZTD_NL_LANGINFO_H != 0)
#define ZTD_NL_LANGINFO_H_I_ ZTD_ON
#else
#define ZTD_NL_LANGINFO_I_ ZTD_OFF
#define ZTD_NL_LANGINFO_H_I_ ZTD_OFF
#endif
#else
#if ZTD_HAS_INCLUDE_I_(<nl_langinfo.h>)
#define ZTD_NL_LANGINFO_I_ ZTD_ON
#if ZTD_IS_ON(ZTD_PLATFORM_ANDROID)
#if ZTD_USE(ZTD_PLATFORM_ANDROID_VERSION) >= 26
#define ZTD_NL_LANGINFO_H_I_ ZTD_DEFAULT_ON
#else
#define ZTD_NL_LANGINFO_H_I_ ZTD_DEFAULT_OFF
#endif
#else
#define ZTD_NL_LANGINFO_H_I_ ZTD_DEFAULT_ON
#endif
#else
#define ZTD_NL_LANGINFO_I_ ZTD_DEFAULT_OFF
#define ZTD_NL_LANGINFO_H_I_ ZTD_DEFAULT_OFF
#endif
#endif // nl_langinfo POSIX

Expand All @@ -400,7 +428,7 @@
#else
#define ZTD_LOCALE_DEPENDENT_WIDE_EXECUTION_I_ ZTD_OFF
#endif
#elif ZTD_IS_ON(ZTD_NL_LANGINFO) && (ZTD_IS_ON(ZTD_PLATFORM_ZEDOS) || ZTD_IS_ON(ZTD_PLATFORM_AIX))
#elif ZTD_IS_ON(ZTD_NL_LANGINFO_H) && (ZTD_IS_ON(ZTD_PLATFORM_ZEDOS) || ZTD_IS_ON(ZTD_PLATFORM_AIX))
#define ZTD_LOCALE_DEPENDENT_WIDE_EXECUTION_I_ ZTD_ON
#else
#define ZTD_LOCALE_DEPENDENT_WIDE_EXECUTION_I_ ZTD_DEFAULT_OFF
Expand Down Expand Up @@ -477,18 +505,18 @@
#define ZTD_CHAR8_T_I_ unsigned char
#endif // char8_t defined by the user

#if defined(ZTD_UCHAR)
#if (ZTD_UCHAR != 0)
#define ZTD_UCHAR_I_ ZTD_ON
#if defined(ZTD_UCHAR_H)
#if (ZTD_UCHAR_H != 0)
#define ZTD_UCHAR_H_I_ ZTD_ON
#else
#define ZTD_UCHAR_I_ ZTD_OFF
#define ZTD_UCHAR_H_I_ ZTD_OFF
#endif
#elif ZTD_IS_OFF(ZTD_PLATFORM_MAC_OS)
#define ZTD_UCHAR_I_ ZTD_DEFAULT_ON
#define ZTD_UCHAR_H_I_ ZTD_DEFAULT_ON
#elif ZTD_HAS_INCLUDE_I_(<uchar.h>)
#define ZTD_UCHAR_I_ ZTD_DEFAULT_ON
#define ZTD_UCHAR_H_I_ ZTD_DEFAULT_ON
#else
#define ZTD_UCHAR_I_ ZTD_DEFAULT_OFF
#define ZTD_UCHAR_H_I_ ZTD_DEFAULT_OFF
#endif

#if defined(ZTD_CUCHAR)
Expand All @@ -505,18 +533,18 @@
#define ZTD_CUCHAR_I_ ZTD_DEFAULT_OFF
#endif

#if defined(ZTD_WCHAR)
#if (ZTD_WCHAR != 0)
#define ZTD_WCHAR_I_ ZTD_ON
#if defined(ZTD_WCHAR_H)
#if (ZTD_WCHAR_H != 0)
#define ZTD_WCHAR_H_I_ ZTD_ON
#else
#define ZTD_WCHAR_I_ ZTD_OFF
#define ZTD_WCHAR_H_I_ ZTD_OFF
#endif
#elif ZTD_HAS_INCLUDE_I_(<wchar.h>)
#define ZTD_WCHAR_I_ ZTD_DEFAULT_ON
#define ZTD_WCHAR_H_I_ ZTD_DEFAULT_ON
#elif ZTD_IS_OFF(ZTD_LIBCXX)
#define ZTD_WCHAR_I_ ZTD_DEFAULT_ON
#define ZTD_WCHAR_H_I_ ZTD_DEFAULT_ON
#else
#define ZTD_WCHAR_I_ ZTD_DEFAULT_OFF
#define ZTD_WCHAR_H_I_ ZTD_DEFAULT_OFF
#endif

#if defined(ZTD_CWCHAR)
Expand Down Expand Up @@ -559,38 +587,68 @@

#if ZTD_IS_ON(ZTD_CXX)
#if ZTD_IS_ON(ZTD_CUCHAR)
#define ZTD_UCHAR_ACCESSOR_I_ ::std::
#define ZTD_UCHAR_SCOPE_I_ ::std::
#else
#define ZTD_UCHAR_ACCESSOR_I_ ::
#define ZTD_UCHAR_SCOPE_I_ ::
#endif
#else
#define ZTD_UCHAR_ACCESSOR_I_
#define ZTD_UCHAR_SCOPE_I_
#endif

#if ZTD_IS_ON(ZTD_CXX)
#if ZTD_IS_ON(ZTD_CWCHAR)
#define ZTD_WCHAR_ACCESSOR_I_ ::std::
#define ZTD_WCHAR_SCOPE_I_ ::std::
#else
#define ZTD_WCHAR_ACCESSOR_I_ ::
#define ZTD_WCHAR_SCOPE_I_ ::
#endif
#else
#define ZTD_WCHAR_ACCESSOR_I_
#define ZTD_WCHAR_SCOPE_I_
#endif

#if defined(ZTD_LANGINFO)
#if (ZTD_LANGINFO != 0)
#define ZTD_LANGINFO_I_ ZTD_ON
#if ZTD_IS_ON(ZTD_CXX)
#if ZTD_IS_ON(ZTD_CWCHAR) || ZTD_IS_ON(ZTD_CUCHAR)
#define ZTD_MBSTATE_SCOPE_I_ ::std::
#else
#define ZTD_LANGINFO_I_ ZTD_OFF
#define ZTD_MBSTATE_SCOPE_I_ ::
#endif
#else
#define ZTD_MBSTATE_SCOPE_I_
#endif

#if defined(ZTD_LANGINFO_H)
#if (ZTD_LANGINFO_H != 0)
#define ZTD_LANGINFO_H_I_ ZTD_ON
#else
#define ZTD_LANGINFO_H_I_ ZTD_OFF
#endif
#else
#if ZTD_HAS_INCLUDE_I_(<langinfo.h>)
#define ZTD_LANGINFO_I_ ZTD_ON
#if ZTD_IS_ON(ZTD_PLATFORM_ANDROID)
#if ZTD_USE(ZTD_PLATFORM_ANDROID_VERSION) >= 26
#define ZTD_LANGINFO_H_I_ ZTD_DEFAULT_ON
#else
#define ZTD_LANGINFO_H_I_ ZTD_DEFAULT_OFF
#endif
#else
#define ZTD_LANGINFO_H_I_ ZTD_DEFAULT_ON
#endif
#else
#define ZTD_LANGINFO_I_ ZTD_DEFAULT_OFF
#define ZTD_LANGINFO_H_I_ ZTD_DEFAULT_OFF
#endif
#endif // langinfo POSIX

#if defined(ZTD_NL_LANGINFO)
#if (ZTD_NL_LANGINFO != 0)
#define ZTD_NL_LANGINFO_I_ ZTD_ON
#else
#define ZTD_NL_LANGINFO_I_ ZTD_OFF
#endif
#elif ZTD_IS_ON(ZTD_NL_LANGINFO_H) || ZTD_IS_ON(ZTD_LANGINFO_H)
#define ZTD_NL_LANGINFO_I_ ZTD_DEFAULT_ON
#else
#define ZTD_NL_LANGINFO_I_ ZTD_DEFAULT_OFF
#endif

#if (ZTD_HAS_ATTRIBUTE_I_(nodiscard) != 0L)
#if ZTD_IS_ON(ZTD_CXX)
#if ZTD_HAS_ATTRIBUTE_I_(nodiscard) >= 201907L
Expand Down
Loading

0 comments on commit 00c82f4

Please sign in to comment.