replaced TomlString with StringBuilder
This commit is contained in:
parent
c83ee4078e
commit
a33505ffe4
2
dependencies/tlibc.config
vendored
2
dependencies/tlibc.config
vendored
@ -9,7 +9,7 @@ if [[ "$TASK" = *_dbg ]]; then
|
|||||||
else
|
else
|
||||||
dep_build_target="build_static_lib"
|
dep_build_target="build_static_lib"
|
||||||
fi
|
fi
|
||||||
DEP_PRE_BUILD_COMMAND="setup_user_config"
|
DEP_PRE_BUILD_COMMAND=""
|
||||||
DEP_BUILD_COMMAND="cbuild $dep_build_target"
|
DEP_BUILD_COMMAND="cbuild $dep_build_target"
|
||||||
DEP_POST_BUILD_COMMAND=""
|
DEP_POST_BUILD_COMMAND=""
|
||||||
DEP_CLEAN_COMMAND="cbuild clean"
|
DEP_CLEAN_COMMAND="cbuild clean"
|
||||||
|
|||||||
@ -11,6 +11,7 @@ extern "C" {
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "tlibc/std.h"
|
#include "tlibc/std.h"
|
||||||
#include "tlibc/string/str.h"
|
#include "tlibc/string/str.h"
|
||||||
|
#include "tlibc/string/StringBuilder.h"
|
||||||
|
|
||||||
typedef struct tm TomlDateTime;
|
typedef struct tm TomlDateTime;
|
||||||
|
|
||||||
@ -28,12 +29,6 @@ typedef struct {
|
|||||||
NULLABLE(char*) message;
|
NULLABLE(char*) message;
|
||||||
} TomlErr;
|
} TomlErr;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char* s;
|
|
||||||
u64 len;
|
|
||||||
u64 _capacity;
|
|
||||||
} TomlString;
|
|
||||||
|
|
||||||
typedef struct _TomlValue TomlValue;
|
typedef struct _TomlValue TomlValue;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -70,16 +65,16 @@ struct _TomlValue {
|
|||||||
union {
|
union {
|
||||||
TomlTable* table;
|
TomlTable* table;
|
||||||
TomlArray* array;
|
TomlArray* array;
|
||||||
TomlString* string;
|
str s;
|
||||||
i64 integer;
|
i64 i;
|
||||||
f64 float_;
|
f64 f;
|
||||||
TomlDateTime datetime;
|
TomlDateTime dt;
|
||||||
bool boolean;
|
bool b;
|
||||||
} value;
|
} value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _TomlKeyValue {
|
struct _TomlKeyValue {
|
||||||
TomlString* key;
|
str key;
|
||||||
TomlValue* value;
|
TomlValue* value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -98,28 +93,19 @@ void toml_free(void* p);
|
|||||||
const TomlErr* toml_err(void);
|
const TomlErr* toml_err(void);
|
||||||
void toml_err_clear(void);
|
void toml_err_clear(void);
|
||||||
|
|
||||||
TomlString* toml_string_new(void);
|
|
||||||
TomlString* toml_string_from_str(str s);
|
|
||||||
void toml_string_append_char(TomlString* self, char ch);
|
|
||||||
void toml_string_append_str(TomlString* self, str s);
|
|
||||||
TomlString* toml_string_clone(const TomlString* self);
|
|
||||||
void toml_string_free(TomlString* self);
|
|
||||||
i32 toml_string_equals(const TomlString* self, const TomlString* other);
|
|
||||||
|
|
||||||
TomlTable* toml_table_new(void);
|
TomlTable* toml_table_new(void);
|
||||||
void toml_table_free(TomlTable* self);
|
void toml_table_free(TomlTable* self);
|
||||||
|
|
||||||
void toml_table_set_by_string(TomlTable* self, TomlString* key, TomlValue* value);
|
|
||||||
TomlValue* toml_table_get_by_string(const TomlTable* self, const TomlString* key);
|
|
||||||
void toml_table_set(TomlTable* self, str key, TomlValue* value);
|
void toml_table_set(TomlTable* self, str key, TomlValue* value);
|
||||||
TomlValue* toml_table_get(const TomlTable* self, str key);
|
TomlValue* toml_table_get(const TomlTable* self, str key);
|
||||||
TomlTable* toml_table_get_table(const TomlTable* self, str key);
|
TomlTable* toml_table_get_table(const TomlTable* self, str key);
|
||||||
TomlArray* toml_table_get_array(const TomlTable* self, str key);
|
TomlArray* toml_table_get_array(const TomlTable* self, str key);
|
||||||
TomlString* toml_table_get_string(const TomlTable* self, str key);
|
str toml_table_get_str(const TomlTable* self, str key);
|
||||||
i64 toml_table_get_integer(const TomlTable* self, str key);
|
i64 toml_table_get_integer(const TomlTable* self, str key);
|
||||||
f64 toml_table_get_float(const TomlTable* self, str key);
|
f64 toml_table_get_float(const TomlTable* self, str key);
|
||||||
const TomlDateTime* toml_table_get_datetime(const TomlTable* self, str key);
|
const TomlDateTime* toml_table_get_datetime(const TomlTable* self, str key);
|
||||||
i32 toml_table_get_boolean(const TomlTable* self, str key);
|
bool toml_table_get_bool(const TomlTable* self, str key);
|
||||||
|
|
||||||
TomlTableIter toml_table_iter_new(TomlTable* table);
|
TomlTableIter toml_table_iter_new(TomlTable* table);
|
||||||
TomlKeyValue* toml_table_iter_get(TomlTableIter* self);
|
TomlKeyValue* toml_table_iter_get(TomlTableIter* self);
|
||||||
@ -137,7 +123,7 @@ TomlValue* toml_value_new_array(void);
|
|||||||
TomlValue* toml_value_new_integer(i64 integer);
|
TomlValue* toml_value_new_integer(i64 integer);
|
||||||
TomlValue* toml_value_new_float(f64 flt);
|
TomlValue* toml_value_new_float(f64 flt);
|
||||||
TomlValue* toml_value_new_datetime(void);
|
TomlValue* toml_value_new_datetime(void);
|
||||||
TomlValue* toml_value_new_boolean(i32 boolean);
|
TomlValue* toml_value_new_bool(bool b);
|
||||||
TomlValue* toml_value_from_str(str s);
|
TomlValue* toml_value_from_str(str s);
|
||||||
void toml_value_free(TomlValue* self);
|
void toml_value_free(TomlValue* self);
|
||||||
|
|
||||||
@ -146,7 +132,7 @@ TomlTable* toml_load_file(FILE* file);
|
|||||||
TomlTable* toml_load_filename(cstr filename);
|
TomlTable* toml_load_filename(cstr filename);
|
||||||
|
|
||||||
/* TODO: implement dump functions
|
/* TODO: implement dump functions
|
||||||
TomlString* toml_dump_str(const TomlTable* self, TomlErr *err);
|
str toml_dump_str(const TomlTable* self, TomlErr *err);
|
||||||
void toml_dump_file(const TomlTable* self, FILE* file, TomlErr *err);
|
void toml_dump_file(const TomlTable* self, FILE* file, TomlErr *err);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
443
src/toml.c
443
src/toml.c
File diff suppressed because it is too large
Load Diff
10
tests/main.c
10
tests/main.c
@ -34,26 +34,26 @@ void print_value(const TomlValue* value)
|
|||||||
print_array(value->value.array);
|
print_array(value->value.array);
|
||||||
break;
|
break;
|
||||||
case TOML_STRING:
|
case TOML_STRING:
|
||||||
printf("\"%s\"", value->value.string->s);
|
printf("\"%s\"", value->value.s.data);
|
||||||
break;
|
break;
|
||||||
case TOML_INTEGER:
|
case TOML_INTEGER:
|
||||||
printf("%" PRId64, value->value.integer);
|
printf("%" PRId64, value->value.i);
|
||||||
break;
|
break;
|
||||||
case TOML_FLOAT:
|
case TOML_FLOAT:
|
||||||
printf("%f", value->value.float_);
|
printf("%f", value->value.f);
|
||||||
break;
|
break;
|
||||||
case TOML_DATETIME:
|
case TOML_DATETIME:
|
||||||
printf("(datetime)");
|
printf("(datetime)");
|
||||||
break;
|
break;
|
||||||
case TOML_BOOLEAN:
|
case TOML_BOOLEAN:
|
||||||
printf("%s", value->value.boolean ? "true" : "false");
|
printf("%s", value->value.b ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_keyval(const TomlKeyValue *keyval)
|
void print_keyval(const TomlKeyValue *keyval)
|
||||||
{
|
{
|
||||||
printf("\"%s\": ", keyval->key->s);
|
printf("\"%s\": ", keyval->key.data);
|
||||||
print_value(keyval->value);
|
print_value(keyval->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user