From 9b61adb97dd78e1cf04ad410e72166f684f97925 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Thu, 8 Jun 2017 12:03:40 +0100 Subject: Build as C++ --- src/unicode.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/unicode.cpp (limited to 'src/unicode.cpp') diff --git a/src/unicode.cpp b/src/unicode.cpp new file mode 100644 index 000000000..538e6adce --- /dev/null +++ b/src/unicode.cpp @@ -0,0 +1,43 @@ +#pragma warning(push) +#pragma warning(disable: 4245) + +extern "C" { +// #include "utf8proc/utf8proc.h" +#include "utf8proc/utf8proc.c" +} +#pragma warning(pop) + + +bool rune_is_letter(Rune r) { + if ((r < 0x80 && gb_char_is_alpha(cast(char)r)) || + r == '_') { + return true; + } + switch (utf8proc_category(r)) { + case UTF8PROC_CATEGORY_LU: + case UTF8PROC_CATEGORY_LL: + case UTF8PROC_CATEGORY_LT: + case UTF8PROC_CATEGORY_LM: + case UTF8PROC_CATEGORY_LO: + return true; + } + return false; +} + +bool rune_is_digit(Rune r) { + if (r < 0x80 && gb_is_between(r, '0', '9')) { + return true; + } + return utf8proc_category(r) == UTF8PROC_CATEGORY_ND; +} + +bool rune_is_whitespace(Rune r) { + switch (r) { + case ' ': + case '\t': + case '\n': + case '\r': + return true; + } + return false; +} -- cgit v1.2.3