1
0
forked from GitHub/gf-core

remove the dependency on the CHAR_ASCII flag

This commit is contained in:
kr.angelov
2013-09-04 10:27:08 +00:00
parent 805f95eac6
commit 93cbfd31d1
5 changed files with 0 additions and 152 deletions

View File

@@ -37,7 +37,6 @@ fi]
AC_C_ALIGNOF
AC_C_FAM_IN_MEM
AC_C_ASCII
case "$target_cpu" in
i?86) cpu=i386; AC_DEFINE(LIGHTNING_I386, 1,

View File

@@ -5,7 +5,6 @@
#include <gu/string.h>
#include <gu/utf8.h>
#include <gu/assert.h>
#include "config.h"
const GuString gu_empty_string = { 1 };
@@ -195,18 +194,7 @@ gu_format_string(GuPool* pool, const char* fmt, ...)
GuString
gu_str_string(const char* str, GuPool* pool)
{
#ifdef CHAR_ASCII
return gu_utf8_string((const uint8_t*) str, strlen(str), pool);
#else
GuPool* tmp_pool = gu_local_pool();
GuStringBuf* sb = gu_string_buf(tmp_pool);
GuWriter* wtr = gu_string_buf_writer(sb);
gu_puts(str, wtr, NULL);
gu_writer_flush(wtr, NULL);
GuString s = gu_string_buf_freeze(sb, pool);
gu_pool_free(tmp_pool);
return s;
#endif
}
bool

View File

@@ -1,12 +1,8 @@
#include <gu/ucs.h>
#include <gu/assert.h>
#include "config.h"
GU_DEFINE_TYPE(GuUCSExn, abstract, _);
#ifdef CHAR_ASCII
bool
gu_char_is_valid(char c)
{
@@ -36,66 +32,6 @@ gu_ucs_char(GuUCS uc, GuExn* err)
return 0;
}
#else // defined(CHAR_ASCII)
static const char gu_ucs_ascii[128] =
"\0\0\0\0\0\0\0\a\b\t\n\v\f\r\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
" !\"#\0%&'()*+,-./0123456789:;<=>?"
"\0ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"\0abcdefghijklmnopqrstuvwxyz{|}~\0";
const uint8_t gu_ucs_ascii_reverse_[CHAR_MAX] = {
['\0'] = 0x00, ['\a'] = 0x07, ['\b'] = 0x08, ['\t'] = 0x09,
['\n'] = 0x0a, ['\v'] = 0x0b, ['\f'] = 0x0c, ['\r'] = 0x0d,
[' '] = 0x20, ['!'] = 0x21, ['"'] = 0x22, ['#'] = 0x23, ['%'] = 0x25,
['&'] = 0x26, ['\''] = 0x27, ['('] = 0x28, [')'] = 0x29, ['*'] = 0x2a,
['+'] = 0x2b, [','] = 0x2c, ['-'] = 0x2d, ['.'] = 0x2e, ['/'] = 0x2f,
['0'] = 0x30, ['1'] = 0x31, ['2'] = 0x32, ['3'] = 0x33, ['4'] = 0x34,
['5'] = 0x35, ['6'] = 0x36, ['7'] = 0x37, ['8'] = 0x38, ['9'] = 0x39,
[':'] = 0x3a, [';'] = 0x3b, ['<'] = 0x3c, ['='] = 0x3d, ['>'] = 0x3e,
['?'] = 0x3f, ['A'] = 0x41, ['B'] = 0x42, ['C'] = 0x43, ['D'] = 0x44,
['E'] = 0x45, ['F'] = 0x46, ['G'] = 0x47, ['H'] = 0x48, ['I'] = 0x49,
['J'] = 0x4a, ['K'] = 0x4b, ['L'] = 0x4c, ['M'] = 0x4d, ['N'] = 0x4e,
['O'] = 0x4f, ['P'] = 0x50, ['Q'] = 0x51, ['R'] = 0x52, ['S'] = 0x53,
['T'] = 0x54, ['U'] = 0x55, ['V'] = 0x56, ['W'] = 0x57, ['X'] = 0x58,
['Y'] = 0x59, ['Z'] = 0x5a, ['['] = 0x5b, ['\\'] = 0x5c, [']'] = 0x5d,
['^'] = 0x5e, ['_'] = 0x5f, ['a'] = 0x61, ['b'] = 0x62, ['c'] = 0x63,
['d'] = 0x64, ['e'] = 0x65, ['f'] = 0x66, ['g'] = 0x67, ['h'] = 0x68,
['i'] = 0x69, ['j'] = 0x6a, ['k'] = 0x6b, ['l'] = 0x6c, ['m'] = 0x6d,
['n'] = 0x6e, ['o'] = 0x6f, ['p'] = 0x70, ['q'] = 0x71, ['r'] = 0x72,
['s'] = 0x73, ['t'] = 0x74, ['u'] = 0x75, ['v'] = 0x76, ['w'] = 0x77,
['x'] = 0x78, ['y'] = 0x79, ['z'] = 0x7a, ['{'] = 0x7b, ['|'] = 0x7c,
['}'] = 0x7d, ['~'] = 0x7e
};
bool
gu_char_is_valid(char c)
{
if (c > 0) {
return (gu_ucs_ascii_reverse_[(int) c] > 0);
}
return (c == '\0');
}
char
gu_ucs_char(GuUCS uc, GuExn* err)
{
if (uc == 0) {
return '\0';
} else if (0 < uc && uc <= 127) {
char c = gu_ucs_ascii[uc];
if (c != '\0') {
return (unsigned char) c;
}
}
gu_raise(err, GuUCSExn);
return 0;
}
#endif
size_t
gu_str_to_ucs(const char* cbuf, size_t len, GuUCS* ubuf, GuExn* err)
{
@@ -135,12 +71,7 @@ GuUCS
gu_char_ucs(char c)
{
gu_require(gu_char_is_valid(c));
#ifdef CHAR_ASCII
GuUCS u = (GuUCS) c;
#else
extern const uint8_t gu_ucs_ascii_reverse_[CHAR_MAX];
GuUCS u = gu_ucs_ascii_reverse_[(unsigned char) c];
#endif
gu_ensure(u < 0x80);
return u;
}

View File

@@ -1,6 +1,5 @@
#include <gu/assert.h>
#include <gu/utf8.h>
#include "config.h"
GuUCS
gu_utf8_decode(const uint8_t** src_inout)
@@ -107,13 +106,11 @@ gu_in_utf8_char_(GuIn* in, GuExn* err)
char
gu_in_utf8_char(GuIn* in, GuExn* err)
{
#ifdef CHAR_ASCII
int i = gu_in_peek_u8(in);
if (i >= 0 && i < 0x80) {
gu_in_consume(in, 1);
return (char) i;
}
#endif
return gu_in_utf8_char_(in, err);
}
@@ -192,47 +189,11 @@ gu_utf32_out_utf8(const GuUCS* src, size_t len, GuOut* out, GuExn* err)
}
#ifndef CHAR_ASCII
void gu_str_out_utf8_(const char* str, GuOut* out, GuExn* err)
{
size_t len = strlen(str);
size_t sz = 0;
uint8_t* buf = gu_out_begin_span(out, len, &sz, err);
if (!gu_ok(err)) {
return;
}
if (buf != NULL && sz < len) {
gu_out_end_span(out, 0);
buf = NULL;
}
GuPool* tmp_pool = buf ? NULL : gu_local_pool();
buf = buf ? buf : gu_new_n(uint8_t, len, tmp_pool);
for (size_t i = 0; i < len; i++) {
GuUCS ucs = gu_char_ucs(str[i]);
buf[i] = (uint8_t) ucs;
}
if (tmp_pool) {
gu_out_bytes(out, buf, len, err);
gu_pool_free(tmp_pool);
} else {
gu_out_end_span(out, len);
}
}
#endif
extern inline GuUCS
gu_in_utf8(GuIn* in, GuExn* err);
void
gu_str_out_utf8(const char* str, GuOut* out, GuExn* err)
{
#ifdef CHAR_ASCII
gu_out_bytes(out, (const uint8_t*) str, strlen(str), err);
#else
extern void
gu_str_out_utf8_(const char* str, GuOut* out, GuExn* err);
gu_str_out_utf8_(str, out, err);
#endif
}

View File

@@ -40,34 +40,3 @@ AC_DEFUN([AC_C_FAM_IN_MEM],
the last member of another struct.])
fi
])
## AC_C_ASCII
AC_DEFUN([AC_C_ASCII],
[
AC_CACHE_CHECK([whether the execution character set uses ASCII],
ac_cv_c_ascii,
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([], [[
int i;
static const char ascii[128] =
"\0\0\0\0\0\0\0\a\b\t\n\v\f\r\0\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
" !\"#\0%&'()*+,-./0123456789:;<=>?"
"\0ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_"
"\0abcdefghijklmnopqrstuvwxyz{|}~\0";
for (i = 0; i < 128; i++) {
if (ascii[i] && ascii[i] != (char) i) {
return 1;
}
}
]])],
[ac_cv_c_ascii=yes],
[ac_cv_c_ascii=no])])
if test $ac_cv_c_ascii = yes; then
AC_DEFINE([CHAR_ASCII], 1,
[Define to 1 if the encoding of the basic character set is ASCII.])
fi
])