mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-07 18:22:50 -06:00
started an official API to the C runtime
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#ifndef GU_SYSDEPS_H_
|
||||
#define GU_SYSDEPS_H_
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
# define GU_GNUC
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <gu/ucs.h>
|
||||
#include <gu/assert.h>
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
GU_DEFINE_TYPE(GuUCSExn, abstract, _);
|
||||
|
||||
@@ -131,5 +131,16 @@ gu_ucs_to_str(const GuUCS* ubuf, size_t len, char* cbuf, GuExn* err)
|
||||
extern inline bool
|
||||
gu_ucs_valid(GuUCS ucs);
|
||||
|
||||
extern inline GuUCS
|
||||
gu_char_ucs(char c);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <gu/exn.h>
|
||||
#include <gu/assert.h>
|
||||
|
||||
|
||||
#if defined(__STDC_ISO_10646__) && WCHAR_MAX >= 0x10FFFF
|
||||
#include <wchar.h>
|
||||
#define GU_UCS_WCHAR
|
||||
@@ -25,19 +24,8 @@ gu_ucs_valid(GuUCS ucs)
|
||||
return ucs >= 0 && ucs <= GU_UCS_MAX;
|
||||
}
|
||||
|
||||
inline 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;
|
||||
}
|
||||
GuUCS
|
||||
gu_char_ucs(char c);
|
||||
|
||||
char
|
||||
gu_ucs_char(GuUCS uc, GuExn* err);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <gu/assert.h>
|
||||
#include <gu/utf8.h>
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
GuUCS
|
||||
gu_utf8_decode(const uint8_t** src_inout)
|
||||
@@ -73,7 +73,6 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
gu_advance_utf8(GuUCS ucs, uint8_t* buf)
|
||||
{
|
||||
@@ -105,6 +104,19 @@ gu_in_utf8_char_(GuIn* in, GuExn* err)
|
||||
return gu_ucs_char(gu_in_utf8(in, err), 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);
|
||||
}
|
||||
|
||||
void
|
||||
gu_out_utf8_long_(GuUCS ucs, GuOut* out, GuExn* err)
|
||||
{
|
||||
@@ -210,11 +222,17 @@ void gu_str_out_utf8_(const char* str, GuOut* out, GuExn* err)
|
||||
|
||||
#endif
|
||||
|
||||
extern inline void
|
||||
gu_str_out_utf8(const char* str, GuOut* out, GuExn* err);
|
||||
|
||||
extern inline GuUCS
|
||||
gu_in_utf8(GuIn* in, GuExn* err);
|
||||
|
||||
extern inline char
|
||||
gu_in_utf8_char(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
|
||||
}
|
||||
|
||||
@@ -18,19 +18,8 @@ gu_in_utf8(GuIn* in, GuExn* err)
|
||||
}
|
||||
|
||||
|
||||
inline 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
|
||||
extern char gu_in_utf8_char_(GuIn* in, GuExn* err);
|
||||
return gu_in_utf8_char_(in, err);
|
||||
}
|
||||
char
|
||||
gu_in_utf8_char(GuIn* in, GuExn* err);
|
||||
|
||||
void
|
||||
gu_out_utf8_long_(GuUCS ucs, GuOut* out, GuExn* err);
|
||||
@@ -52,16 +41,7 @@ gu_utf32_out_utf8(const GuUCS* src, size_t len, GuOut* out, GuExn* err);
|
||||
GuUCS
|
||||
gu_utf8_decode(const uint8_t** utf8);
|
||||
|
||||
inline 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
|
||||
}
|
||||
void
|
||||
gu_str_out_utf8(const char* str, GuOut* out, GuExn* err);
|
||||
|
||||
#endif // GU_UTF8_H_
|
||||
|
||||
Reference in New Issue
Block a user