From 2949b2de0c02c2eefe846a84088297af0070349c Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 3 Jan 2018 00:37:31 +0100 Subject: [PATCH] add fallbacks for when string_utf.hh doesn't exist yet --- src/string.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/string.cc b/src/string.cc index 6919a80..d914f19 100644 --- a/src/string.cc +++ b/src/string.cc @@ -288,7 +288,57 @@ bool isupper(char32_t c); char32_t tolower(char32_t c); char32_t toupper(char32_t c); +#if __has_include("string_utf.hh") #include "string_utf.hh" +#else + +/* break the cycle (build system and generator use libostd, but string_utf.hh + * is generated during build) by providing a bunch of ASCII only fallbacks + */ + +bool isalpha(char32_t c) { + return (utf::isupper(c) || utf::islower(c)); +} + +bool iscntrl(char32_t c) { + return ((c <= 0x1F) || (c == 0x7F)); +} + +bool isdigit(char32_t c) { + return ((c >= '0') && (c <= '9')); +} + +bool islower(char32_t c) { + return ((c >= 'a') && (c <= 'z')); +} + +bool isspace(char32_t c) { + return ((c == ' ') || ((c >= 0x09) && (c <= 0x0D))); +} + +bool istitle(char32_t) { + return false; +} + +bool isupper(char32_t c) { + return ((c >= 'A') && (c <= 'Z')); +} + +char32_t tolower(char32_t c) { + if (utf::isupper(c)) { + return c | 32; + } + return c; +} + +char32_t toupper(char32_t c) { + if (utf::islower(c)) { + return c ^ 32; + } + return c; +} + +#endif /* __has_include("string_utf.hh") */ } /* namespace utf */ } /* namespace ostd */