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>
|
#include <dcfg.h>
|
||||||
|
|
||||||
|
#ifndef DCFG_UTF8_SUPPORT
|
||||||
|
# define DCFG_UTF8_SUPPORT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
|
|
||||||
#include "vendor/utf8proc.h"
|
#if DCFG_UTF8_SUPPORT
|
||||||
|
# include "vendor/utf8proc.h"
|
||||||
|
#endif
|
||||||
#include "vendor/vec.h"
|
#include "vendor/vec.h"
|
||||||
|
|
||||||
#ifdef DCFG_POSIX_SUPPORT
|
#if DCFG_POSIX_SUPPORT
|
||||||
# ifdef __sun
|
# ifdef __sun
|
||||||
// FIXME: Fix this stupid shit!
|
// FIXME: Fix this stupid shit!
|
||||||
# error "realpath() is dumb and stupid on sun. sorry not sorry."
|
# error "realpath() is dumb and stupid on sun. sorry not sorry."
|
||||||
@@ -43,7 +49,7 @@
|
|||||||
# define _POSIX_C_SOURCE 0L
|
# define _POSIX_C_SOURCE 0L
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DCFG_PTHREAD_SUPPORT
|
#if DCFG_PTHREAD_SUPPORT
|
||||||
# ifdef _POSIX_C_SOURCE
|
# ifdef _POSIX_C_SOURCE
|
||||||
# undef _POSIX_C_SOURCE
|
# undef _POSIX_C_SOURCE
|
||||||
# endif
|
# endif
|
||||||
@@ -380,7 +386,7 @@ struct dcfg_Instance {
|
|||||||
|
|
||||||
static void *alloc(size_t size) { return calloc(1, size); }
|
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); }
|
static char *realpath_(char const *s) { return realpath(s, NULL); }
|
||||||
void *fopen_(char const *f, char const *a) { return fopen(f, a); }
|
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); }
|
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) {
|
if (!instance->free) {
|
||||||
instance->free = free;
|
instance->free = free;
|
||||||
}
|
}
|
||||||
#ifdef DCFG_POSIX_SUPPORT
|
#if DCFG_POSIX_SUPPORT
|
||||||
if (!instance->realpath) {
|
if (!instance->realpath) {
|
||||||
instance->realpath = realpath_;
|
instance->realpath = realpath_;
|
||||||
}
|
}
|
||||||
@@ -544,6 +550,7 @@ typedef struct {
|
|||||||
|
|
||||||
static inline int32_t decode_cp(StringView src, int pos, int *len)
|
static inline int32_t decode_cp(StringView src, int pos, int *len)
|
||||||
{
|
{
|
||||||
|
#if DCFG_UTF8_SUPPORT
|
||||||
if (pos >= (int)src.size) {
|
if (pos >= (int)src.size) {
|
||||||
*len = 0;
|
*len = 0;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -560,24 +567,46 @@ static inline int32_t decode_cp(StringView src, int pos, int *len)
|
|||||||
|
|
||||||
*len = bytes;
|
*len = bytes;
|
||||||
return cp;
|
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)
|
static inline bool is_space_cp(int32_t cp)
|
||||||
{
|
{
|
||||||
|
#if DCFG_UTF8_SUPPORT
|
||||||
return (cp <= 0x7F && (cp == ' ' || cp == '\t' || cp == '\r' || cp == '\n'))
|
return (cp <= 0x7F && (cp == ' ' || cp == '\t' || cp == '\r' || cp == '\n'))
|
||||||
|| utf8proc_category(cp) == UTF8PROC_CATEGORY_ZS;
|
|| 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)
|
static inline bool is_alpha_cp(int32_t cp)
|
||||||
{
|
{
|
||||||
|
#if DCFG_UTF8_SUPPORT
|
||||||
utf8proc_category_t cat = utf8proc_category(cp);
|
utf8proc_category_t cat = utf8proc_category(cp);
|
||||||
return (cp <= 0x7F && isalpha(cp))
|
return (cp <= 0x7F && isalpha(cp))
|
||||||
|| (cat >= UTF8PROC_CATEGORY_LU && cat <= UTF8PROC_CATEGORY_LO)
|
|| (cat >= UTF8PROC_CATEGORY_LU && cat <= UTF8PROC_CATEGORY_LO)
|
||||||
|| (cat == UTF8PROC_CATEGORY_SO);
|
|| (cat == UTF8PROC_CATEGORY_SO);
|
||||||
|
#else
|
||||||
|
return (cp <= 0x7F && isalpha(cp));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
static inline bool is_digit_cp(int32_t cp)
|
static inline bool is_digit_cp(int32_t cp)
|
||||||
{
|
{
|
||||||
|
#if DCFG_UTF8_SUPPORT
|
||||||
return (cp <= 0x7F && isdigit(cp))
|
return (cp <= 0x7F && isdigit(cp))
|
||||||
|| utf8proc_category(cp) == UTF8PROC_CATEGORY_ND;
|
|| utf8proc_category(cp) == UTF8PROC_CATEGORY_ND;
|
||||||
|
#else
|
||||||
|
return (cp <= 0x7F && isdigit(cp));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
static inline bool is_alnum_cp(int32_t cp)
|
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
|
// Libraries
|
||||||
#include "vendor/utf8proc.c"
|
#if DCFG_UTF8_SUPPORT
|
||||||
|
# include "vendor/utf8proc.c"
|
||||||
|
#endif
|
||||||
#include "vendor/vec.c"
|
#include "vendor/vec.c"
|
||||||
|
Reference in New Issue
Block a user