Minor code organization change

This commit is contained in:
gingerBill
2019-03-31 18:29:57 +01:00
parent dd9113786c
commit 2614830c69
3 changed files with 17 additions and 11 deletions
+10 -4
View File
@@ -203,16 +203,22 @@ u64 u64_from_string(String string) {
return result; return result;
} }
gb_global char const global_num_to_char_table[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"@$";
String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { String u64_to_string(u64 v, char *out_buf, isize out_buf_len) {
char buf[32] = {0}; char buf[32] = {0};
isize i = gb_size_of(buf); isize i = gb_size_of(buf);
u64 b = 10; u64 b = 10;
while (v >= b) { while (v >= b) {
buf[--i] = gb__num_to_char_table[v%b]; buf[--i] = global_num_to_char_table[v%b];
v /= b; v /= b;
} }
buf[--i] = gb__num_to_char_table[v%b]; buf[--i] = global_num_to_char_table[v%b];
isize len = gb_min(gb_size_of(buf)-i, out_buf_len); isize len = gb_min(gb_size_of(buf)-i, out_buf_len);
gb_memmove(out_buf, &buf[i], len); gb_memmove(out_buf, &buf[i], len);
@@ -230,10 +236,10 @@ String i64_to_string(i64 a, char *out_buf, isize out_buf_len) {
u64 v = cast(u64)a; u64 v = cast(u64)a;
u64 b = 10; u64 b = 10;
while (v >= b) { while (v >= b) {
buf[--i] = gb__num_to_char_table[v%b]; buf[--i] = global_num_to_char_table[v%b];
v /= b; v /= b;
} }
buf[--i] = gb__num_to_char_table[v%b]; buf[--i] = global_num_to_char_table[v%b];
if (negative) { if (negative) {
buf[--i] = '-'; buf[--i] = '-';
+1 -1
View File
@@ -2,7 +2,7 @@
#pragma warning(disable: 4245) #pragma warning(disable: 4245)
extern "C" { extern "C" {
// #include "utf8proc/utf8proc.h" #include "utf8proc/utf8proc.h"
#include "utf8proc/utf8proc.c" #include "utf8proc/utf8proc.c"
} }
#pragma warning(pop) #pragma warning(pop)
+6 -6
View File
@@ -383,7 +383,7 @@ UTF8PROC_DLLEXPORT int utf8proc_charwidth(utf8proc_int32_t c) {
} }
UTF8PROC_DLLEXPORT utf8proc_category_t utf8proc_category(utf8proc_int32_t c) { UTF8PROC_DLLEXPORT utf8proc_category_t utf8proc_category(utf8proc_int32_t c) {
return cast(utf8proc_category_t)utf8proc_get_property(c)->category; return (utf8proc_category_t)utf8proc_get_property(c)->category;
} }
UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t c) { UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t c) {
@@ -401,7 +401,7 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char(utf8proc_int32_t uc,
utf8proc_int32_t hangul_sindex; utf8proc_int32_t hangul_sindex;
if (uc < 0 || uc >= 0x110000) return UTF8PROC_ERROR_NOTASSIGNED; if (uc < 0 || uc >= 0x110000) return UTF8PROC_ERROR_NOTASSIGNED;
property = unsafe_get_property(uc); property = unsafe_get_property(uc);
category = cast(utf8proc_category_t)property->category; category = (utf8proc_category_t)property->category;
hangul_sindex = uc - UTF8PROC_HANGUL_SBASE; hangul_sindex = uc - UTF8PROC_HANGUL_SBASE;
if (options & (UTF8PROC_COMPOSE|UTF8PROC_DECOMPOSE)) { if (options & (UTF8PROC_COMPOSE|UTF8PROC_DECOMPOSE)) {
if (hangul_sindex >= 0 && hangul_sindex < UTF8PROC_HANGUL_SCOUNT) { if (hangul_sindex >= 0 && hangul_sindex < UTF8PROC_HANGUL_SCOUNT) {
@@ -728,24 +728,24 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map_custom(
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFD(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFD(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_DECOMPOSE)); utf8proc_map(str, 0, &retval, (utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_DECOMPOSE));
return retval; return retval;
} }
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFC(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFC(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_COMPOSE)); utf8proc_map(str, 0, &retval, (utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_COMPOSE));
return retval; return retval;
} }
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKD(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKD(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_DECOMPOSE|UTF8PROC_COMPAT)); utf8proc_map(str, 0, &retval, (utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_DECOMPOSE|UTF8PROC_COMPAT));
return retval; return retval;
} }
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_COMPOSE|UTF8PROC_COMPAT)); utf8proc_map(str, 0, &retval, (utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_COMPOSE|UTF8PROC_COMPAT));
return retval; return retval;
} }