Make UTF-8 optional
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 10s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 13s
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 10s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 13s
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
43
src/dcfg.c
43
src/dcfg.c
@@ -22,15 +22,21 @@
|
||||
|
||||
#include <dcfg.h>
|
||||
|
||||
#ifndef DCFG_UTF8_SUPPORT
|
||||
# define DCFG_UTF8_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "meta.h"
|
||||
|
||||
#include "vendor/utf8proc.h"
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
# include "vendor/utf8proc.h"
|
||||
#endif
|
||||
#include "vendor/vec.h"
|
||||
|
||||
#ifdef DCFG_POSIX_SUPPORT
|
||||
#if DCFG_POSIX_SUPPORT
|
||||
# ifdef __sun
|
||||
// FIXME: Fix this stupid shit!
|
||||
# error "realpath() is dumb and stupid on sun. sorry not sorry."
|
||||
@@ -43,7 +49,7 @@
|
||||
# define _POSIX_C_SOURCE 0L
|
||||
#endif
|
||||
|
||||
#ifdef DCFG_PTHREAD_SUPPORT
|
||||
#if DCFG_PTHREAD_SUPPORT
|
||||
# ifdef _POSIX_C_SOURCE
|
||||
# undef _POSIX_C_SOURCE
|
||||
# endif
|
||||
@@ -380,7 +386,7 @@ struct dcfg_Instance {
|
||||
|
||||
static void *alloc(size_t size) { return calloc(1, size); }
|
||||
|
||||
#ifdef DCFG_POSIX_SUPPORT
|
||||
#if DCFG_POSIX_SUPPORT
|
||||
static char *realpath_(char const *s) { return realpath(s, NULL); }
|
||||
void *fopen_(char const *f, char const *a) { return fopen(f, a); }
|
||||
int fseek_(void *f, size_t p, int o) { return fseek(f, p, o); }
|
||||
@@ -416,7 +422,7 @@ dcfg_Instance *dcfg_make_instance(dcfg_InstanceCreateInfo const *create_info)
|
||||
if (!instance->free) {
|
||||
instance->free = free;
|
||||
}
|
||||
#ifdef DCFG_POSIX_SUPPORT
|
||||
#if DCFG_POSIX_SUPPORT
|
||||
if (!instance->realpath) {
|
||||
instance->realpath = realpath_;
|
||||
}
|
||||
@@ -544,6 +550,7 @@ typedef struct {
|
||||
|
||||
static inline int32_t decode_cp(StringView src, int pos, int *len)
|
||||
{
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
if (pos >= (int)src.size) {
|
||||
*len = 0;
|
||||
return -1;
|
||||
@@ -560,24 +567,46 @@ static inline int32_t decode_cp(StringView src, int pos, int *len)
|
||||
|
||||
*len = bytes;
|
||||
return cp;
|
||||
#else
|
||||
if (pos >= (int)src.size) {
|
||||
*len = 0;
|
||||
return -1;
|
||||
}
|
||||
*len = 1;
|
||||
return (int32_t)src.data[pos];
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline bool is_space_cp(int32_t cp)
|
||||
{
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
return (cp <= 0x7F && (cp == ' ' || cp == '\t' || cp == '\r' || cp == '\n'))
|
||||
|| utf8proc_category(cp) == UTF8PROC_CATEGORY_ZS;
|
||||
#else
|
||||
if (cp <= 0x7F)
|
||||
return (cp == ' ' || cp == '\t' || cp == '\r' || cp == '\n');
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
static inline bool is_alpha_cp(int32_t cp)
|
||||
{
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
utf8proc_category_t cat = utf8proc_category(cp);
|
||||
return (cp <= 0x7F && isalpha(cp))
|
||||
|| (cat >= UTF8PROC_CATEGORY_LU && cat <= UTF8PROC_CATEGORY_LO)
|
||||
|| (cat == UTF8PROC_CATEGORY_SO);
|
||||
#else
|
||||
return (cp <= 0x7F && isalpha(cp));
|
||||
#endif
|
||||
}
|
||||
static inline bool is_digit_cp(int32_t cp)
|
||||
{
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
return (cp <= 0x7F && isdigit(cp))
|
||||
|| utf8proc_category(cp) == UTF8PROC_CATEGORY_ND;
|
||||
#else
|
||||
return (cp <= 0x7F && isdigit(cp));
|
||||
#endif
|
||||
}
|
||||
static inline bool is_alnum_cp(int32_t cp)
|
||||
{
|
||||
@@ -2085,5 +2114,7 @@ bool dcfg_Value_evaluate_toplevel(dcfg_Value *top, dcfg_Value **out_value,
|
||||
}
|
||||
|
||||
// Libraries
|
||||
#include "vendor/utf8proc.c"
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
# include "vendor/utf8proc.c"
|
||||
#endif
|
||||
#include "vendor/vec.c"
|
||||
|
Reference in New Issue
Block a user