Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support stdlib without support for wchar_t #291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions include/ctll/fixed_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string_view>
#include <cstdint>

#include "utilities.hpp"

namespace ctll {

struct length_value_t {
Expand Down Expand Up @@ -130,12 +132,14 @@ template <size_t N> struct fixed_string {
}
}
real_size = out;
#ifndef CTLL_NO_WCHAR_T
} else if constexpr (std::is_same_v<T, wchar_t> || std::is_same_v<T, char32_t>) {
for (size_t i{0}; i < N; ++i) {
content[i] = static_cast<char32_t>(input[i]);
if ((i == (N-1)) && (input[i] == 0)) break;
real_size++;
}
content[i] = static_cast<char32_t>(input[i]);
if ((i == (N - 1)) && (input[i] == 0)) break;
real_size++;
}
#endif
}
}
constexpr fixed_string(const fixed_string & other) noexcept {
Expand Down
7 changes: 7 additions & 0 deletions include/ctll/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
#define CTLL_FORCE_INLINE __attribute__((always_inline))
#endif

#ifdef _LIBCPP_VERSION
#ifdef _LIBCPP_HAS_NO_WIDE_CHARACTERS
#define CTLL_NO_WCHAR_T
#else
#endif
#endif

namespace ctll {

template <bool> struct conditional_helper;
Expand Down
3 changes: 3 additions & 0 deletions include/ctre/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "../ctll/utilities.hpp"

#define CTRE_CNTTP_COMPILER_CHECK CTLL_CNTTP_COMPILER_CHECK
#ifdef CTLL_NO_WCHAR_T
#define CTRE_NO_WCHAR_T
#endif

#if __GNUC__ > 9
#if __has_cpp_attribute(likely)
Expand Down
38 changes: 21 additions & 17 deletions include/ctre/wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,29 @@ struct zero_terminated_string_end_iterator {
constexpr CTRE_FORCE_INLINE friend bool operator==(const char * ptr, zero_terminated_string_end_iterator) noexcept {
return *ptr == '\0';
}
constexpr CTRE_FORCE_INLINE friend bool operator==(const wchar_t * ptr, zero_terminated_string_end_iterator) noexcept {
constexpr CTRE_FORCE_INLINE friend bool operator!=(const char * ptr, zero_terminated_string_end_iterator) noexcept {
return *ptr != '\0';
}
constexpr CTRE_FORCE_INLINE friend bool operator==(zero_terminated_string_end_iterator, const char * ptr) noexcept {
return *ptr == '\0';
}
constexpr CTRE_FORCE_INLINE friend bool operator!=(zero_terminated_string_end_iterator, const char * ptr) noexcept {
return *ptr != '\0';
}
#ifndef CTLL_NO_WCHAR_T
constexpr CTRE_FORCE_INLINE friend bool operator==(const wchar_t * ptr, zero_terminated_string_end_iterator) noexcept {
return *ptr == 0;
}
constexpr CTRE_FORCE_INLINE friend bool operator!=(const char * ptr, zero_terminated_string_end_iterator) noexcept {
return *ptr != '\0';
}
constexpr CTRE_FORCE_INLINE friend bool operator!=(const wchar_t * ptr, zero_terminated_string_end_iterator) noexcept {
return *ptr != 0;
}
constexpr CTRE_FORCE_INLINE friend bool operator==(zero_terminated_string_end_iterator, const char * ptr) noexcept {
return *ptr == '\0';
}
constexpr CTRE_FORCE_INLINE friend bool operator==(zero_terminated_string_end_iterator, const wchar_t * ptr) noexcept {
return *ptr == 0;
}
constexpr CTRE_FORCE_INLINE friend bool operator!=(zero_terminated_string_end_iterator, const char * ptr) noexcept {
return *ptr != '\0';
}
constexpr CTRE_FORCE_INLINE friend bool operator!=(zero_terminated_string_end_iterator, const wchar_t * ptr) noexcept {
return *ptr != 0;
}
}
constexpr CTRE_FORCE_INLINE friend bool operator==(zero_terminated_string_end_iterator, const wchar_t * ptr) noexcept {
return *ptr == 0;
}
constexpr CTRE_FORCE_INLINE friend bool operator!=(zero_terminated_string_end_iterator, const wchar_t * ptr) noexcept {
return *ptr != 0;
}
#endif
};

template <typename T> class RangeLikeType {
Expand Down Expand Up @@ -181,9 +183,11 @@ template <typename RE, typename Method, typename Modifier> struct regular_expres
static constexpr CTRE_FORCE_INLINE auto exec(std::string_view sv) noexcept {
return exec(sv.begin(), sv.end());
}
#ifndef CTRE_NO_WCHAR_T
static constexpr CTRE_FORCE_INLINE auto exec(std::wstring_view sv) noexcept {
return exec(sv.begin(), sv.end());
}
#endif
#ifdef CTRE_ENABLE_UTF8_RANGE
static constexpr CTRE_FORCE_INLINE auto exec(std::u8string_view sv) noexcept {
return exec_with_result_iterator<const char8_t *>(utf8_range(sv).begin(), utf8_range(sv).end());
Expand Down