Skip to content

Commit

Permalink
Better compatibility with MSVC compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptExec committed Jul 6, 2024
1 parent 2aa5709 commit 11edb28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#endif
#endif

#if defined(__cplusplus) && __cplusplus >= 201402L
#if defined(utf8_cplusplus) && utf8_cplusplus >= 201402L
constexpr void test() {
constexpr utf8_int8_t in_str[20]{};
constexpr utf8_int32_t in_chr{};
Expand Down
18 changes: 13 additions & 5 deletions utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
#pragma warning(disable : 4820)
#endif

#if defined(__cplusplus)
#if defined(_MSC_VER)
#define utf8_cplusplus _MSVC_LANG
#else
#define utf8_cplusplus __cplusplus
#endif
#endif

#include <stddef.h>
#include <stdlib.h>

Expand All @@ -67,7 +75,7 @@ typedef int32_t utf8_int32_t;
#endif
#endif

#ifdef __cplusplus
#ifdef utf8_cplusplus
extern "C" {
#endif

Expand Down Expand Up @@ -96,13 +104,13 @@ extern "C" {
#error Non clang, non gcc, non MSVC, non tcc compiler found!
#endif

#ifdef __cplusplus
#ifdef utf8_cplusplus
#define utf8_null NULL
#else
#define utf8_null 0
#endif

#if (defined(__cplusplus) && __cplusplus >= 201402L)
#if (defined(utf8_cplusplus) && utf8_cplusplus >= 201402L)
#define utf8_constexpr14 constexpr
#define utf8_constexpr14_impl constexpr
#else
Expand All @@ -111,7 +119,7 @@ extern "C" {
#define utf8_constexpr14_impl
#endif

#if defined(__cplusplus) && __cplusplus >= 202002L
#if defined(utf8_cplusplus) && utf8_cplusplus >= 202002L
using utf8_int8_t = char8_t; /* Introduced in C++20 */
#else
typedef char utf8_int8_t;
Expand Down Expand Up @@ -1693,7 +1701,7 @@ utf8rcodepoint(const utf8_int8_t *utf8_restrict str,
#undef utf8_constexpr14
#undef utf8_null

#ifdef __cplusplus
#ifdef utf8_cplusplus
} /* extern "C" */
#endif

Expand Down

0 comments on commit 11edb28

Please sign in to comment.