mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
get rid of gu/str.(c|h)
This commit is contained in:
@@ -22,7 +22,6 @@ guinclude_HEADERS = \
|
||||
gu/out.h \
|
||||
gu/prime.h \
|
||||
gu/seq.h \
|
||||
gu/str.h \
|
||||
gu/string.h \
|
||||
gu/sysdeps.h \
|
||||
gu/ucs.h \
|
||||
@@ -54,7 +53,6 @@ libgu_la_SOURCES = \
|
||||
gu/mem.c \
|
||||
gu/out.c \
|
||||
gu/prime.c \
|
||||
gu/str.c \
|
||||
gu/string.c \
|
||||
gu/utf8.c \
|
||||
gu/ucs.c \
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <gu/seq.h>
|
||||
#include <gu/out.h>
|
||||
#include <gu/utf8.h>
|
||||
#include <gu/str.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static bool
|
||||
gu_out_is_buffering(GuOut* out)
|
||||
@@ -261,7 +261,15 @@ void
|
||||
gu_vprintf(const char* fmt, va_list args, GuOut* out, GuExn* err)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
char* str = gu_vasprintf(fmt, args, tmp_pool);
|
||||
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
int len = vsnprintf(NULL, 0, fmt, args2);
|
||||
gu_assert_msg(len >= 0, "Invalid format string: \"%s\"", fmt);
|
||||
va_end(args2);
|
||||
char* str = gu_new_n(char, len + 1, tmp_pool);
|
||||
vsnprintf(str, len + 1, fmt, args);
|
||||
|
||||
gu_out_bytes(out, (const uint8_t*) str, strlen(str), err);
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <gu/out.h>
|
||||
#include <gu/seq.h>
|
||||
#include <gu/fun.h>
|
||||
#include <gu/str.h>
|
||||
#include <gu/assert.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __MINGW32__
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
#include <gu/assert.h>
|
||||
#include <gu/str.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char gu_empty_str[] = "";
|
||||
const char* const gu_null_str = NULL;
|
||||
|
||||
char*
|
||||
gu_new_str(size_t size, GuPool* pool)
|
||||
{
|
||||
char* str = gu_new_n(char, size + 1, pool);
|
||||
memset(str, '\0', size + 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
char*
|
||||
gu_strdup(const char* cstr, GuPool* pool)
|
||||
{
|
||||
int len = strlen(cstr);
|
||||
char* str = gu_new_str(len, pool);
|
||||
memcpy(str, cstr, len);
|
||||
return str;
|
||||
}
|
||||
|
||||
bool
|
||||
gu_str_eq(GuStr s1, GuStr s2)
|
||||
{
|
||||
return (strcmp(s1, s2)) == 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
gu_str_is_equal(GuEquality* self, const void* p1, const void* p2)
|
||||
{
|
||||
(void) self;
|
||||
const GuStr* sp1 = p1;
|
||||
const GuStr* sp2 = p2;
|
||||
return gu_str_eq(*sp1, *sp2);
|
||||
}
|
||||
|
||||
static GuHash
|
||||
gu_str_hasher_hash(GuHasher* self, const void* p)
|
||||
{
|
||||
(void) self;
|
||||
GuHash h = 0;
|
||||
const GuStr* sp = p;
|
||||
for (const char* s = *sp; *s != '\0'; s++) {
|
||||
h = 101 * h + (unsigned char) *s;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
GuHasher gu_str_hasher[1] = {
|
||||
{
|
||||
.eq = { .is_equal = gu_str_is_equal },
|
||||
.hash = gu_str_hasher_hash
|
||||
}
|
||||
};
|
||||
|
||||
char*
|
||||
gu_vasprintf(const char* fmt, va_list args, GuPool* pool)
|
||||
{
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
int len = vsnprintf(NULL, 0, fmt, args2);
|
||||
gu_assert_msg(len >= 0, "Invalid format string: \"%s\"", fmt);
|
||||
va_end(args2);
|
||||
char* str = gu_new_str(len, pool);
|
||||
vsnprintf(str, len + 1, fmt, args);
|
||||
return str;
|
||||
}
|
||||
|
||||
char*
|
||||
gu_asprintf(GuPool* pool, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
char* str = gu_vasprintf(fmt, args, pool);
|
||||
va_end(args);
|
||||
return str;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef GU_STR_H_
|
||||
#define GU_STR_H_
|
||||
|
||||
#include <gu/mem.h>
|
||||
#include <gu/hash.h>
|
||||
|
||||
extern const char gu_empty_str[];
|
||||
extern const char* const gu_null_str;
|
||||
|
||||
typedef const char* GuStr;
|
||||
|
||||
char* gu_new_str(size_t size, GuPool* pool);
|
||||
|
||||
char* gu_strdup(const char* str, GuPool* pool);
|
||||
|
||||
bool
|
||||
gu_str_eq(GuStr s1, GuStr s2);
|
||||
|
||||
extern GuHasher gu_str_hasher[1];
|
||||
|
||||
char* gu_vasprintf(const char* fmt, va_list args, GuPool* pool);
|
||||
|
||||
char* gu_asprintf(GuPool* pool, const char* fmt, ...);
|
||||
|
||||
#endif // GU_STR_H_
|
||||
@@ -5,7 +5,7 @@ include $(CLEAR_VARS)
|
||||
jni_c_files := jpgf.c
|
||||
pgf_c_files := data.c expr.c graphviz.c linearizer.c literals.c parser.c parseval.c pgf.c printer.c reader.c \
|
||||
reasoner.c evaluator.c jit.c typechecker.c
|
||||
gu_c_files := assert.c choice.c exn.c fun.c in.c map.c out.c str.c utf8.c \
|
||||
gu_c_files := assert.c choice.c exn.c fun.c in.c map.c out.c utf8.c \
|
||||
bits.c defs.c enum.c file.c hash.c mem.c prime.c seq.c string.c ucs.c variant.c
|
||||
|
||||
LOCAL_MODULE := jpgf
|
||||
|
||||
Reference in New Issue
Block a user