Merge branch 'main' into feature/new-object-system
This commit is contained in:
49
ds/include/blue/ds/datetime.h
Normal file
49
ds/include/blue/ds/datetime.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef BLUELIB_DATETIME_H_
|
||||
#define BLUELIB_DATETIME_H_
|
||||
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/type.h>
|
||||
#include <ctype.h>
|
||||
|
||||
struct b_string;
|
||||
|
||||
#define B_DATETIME(p) ((b_datetime *)(p))
|
||||
|
||||
typedef struct b_datetime b_datetime;
|
||||
|
||||
typedef enum b_datetime_format {
|
||||
B_DATETIME_FORMAT_RFC3339 = 1,
|
||||
} b_datetime_format;
|
||||
|
||||
BLUE_API b_datetime *b_datetime_create(void);
|
||||
BLUE_API b_datetime *b_datetime_parse(b_datetime_format format, const char *s);
|
||||
BLUE_API void b_datetime_to_string(
|
||||
const b_datetime *dt, b_datetime_format format, struct b_string *dest);
|
||||
|
||||
static inline b_datetime *b_datetime_retain(b_datetime *dt)
|
||||
{
|
||||
return B_DATETIME(b_retain(B_DSREF(dt)));
|
||||
}
|
||||
static inline void b_datetime_release(b_datetime *dt)
|
||||
{
|
||||
b_release(B_DSREF(dt));
|
||||
}
|
||||
|
||||
BLUE_API bool b_datetime_is_localtime(const b_datetime *dt);
|
||||
BLUE_API bool b_datetime_has_date(const b_datetime *dt);
|
||||
BLUE_API bool b_datetime_has_time(const b_datetime *dt);
|
||||
|
||||
BLUE_API long b_datetime_year(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_month(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_day(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_hour(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_minute(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_second(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_subsecond(const b_datetime *dt);
|
||||
|
||||
BLUE_API bool b_datetime_zone_offset_is_negative(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_zone_offset_hour(const b_datetime *dt);
|
||||
BLUE_API long b_datetime_zone_offset_minute(const b_datetime *dt);
|
||||
|
||||
#endif
|
||||
@@ -8,16 +8,12 @@
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/type.h>
|
||||
|
||||
#define B_DICT(p) ((b_dict *)(p))
|
||||
struct b_string;
|
||||
|
||||
#define B_DICT_ITEM(k, v) \
|
||||
{ \
|
||||
.key = (k), .value = (v) \
|
||||
}
|
||||
#define B_DICT_ITEM_END \
|
||||
{ \
|
||||
.key = NULL, .value = NULL \
|
||||
}
|
||||
#define B_DICT(p) ((b_dict *)(p))
|
||||
|
||||
#define B_DICT_ITEM(k, v) {.key = (k), .value = (v)}
|
||||
#define B_DICT_ITEM_END {.key = NULL, .value = NULL}
|
||||
|
||||
#define b_dict_foreach(it, dict) \
|
||||
for (int z__b_unique_name() = b_dict_iterator_begin(dict, it); \
|
||||
@@ -28,7 +24,7 @@ typedef struct b_dict b_dict;
|
||||
typedef struct b_dict_iterator {
|
||||
b_iterator _base;
|
||||
size_t i;
|
||||
const char *key;
|
||||
const struct b_string *key;
|
||||
b_dsref *value;
|
||||
|
||||
b_dict *_d;
|
||||
@@ -54,10 +50,15 @@ static inline void b_dict_release(b_dict *dict)
|
||||
}
|
||||
|
||||
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_dsref *value);
|
||||
BLUE_API b_status b_dict_put_sk(
|
||||
b_dict *dict, const struct b_string *key, b_dsref *value);
|
||||
BLUE_API b_dsref *b_dict_at(const b_dict *dict, const char *key);
|
||||
BLUE_API b_dsref *b_dict_at_sk(const b_dict *dict, const struct b_string *key);
|
||||
BLUE_API b_dsref *b_dict_get(b_dict *dict, const char *key);
|
||||
BLUE_API b_dsref *b_dict_get_sk(b_dict *dict, const struct b_string *key);
|
||||
|
||||
BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key);
|
||||
BLUE_API bool b_dict_has_skey(const b_dict *dict, const struct b_string *key);
|
||||
BLUE_API size_t b_dict_get_size(const b_dict *dict);
|
||||
BLUE_API bool b_dict_is_empty(const b_dict *dict);
|
||||
|
||||
|
||||
@@ -7,27 +7,17 @@
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/type.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define B_HASHMAP(p) ((b_hashmap *)(p))
|
||||
#define B_HASHMAP(p) ((b_hashmap *)(p))
|
||||
|
||||
#define B_HASHMAP_KEY(k, ks) \
|
||||
{ \
|
||||
.key_data = (k), .key_size = (ks) \
|
||||
}
|
||||
#define B_HASHMAP_VALUE(v, vs) \
|
||||
{ \
|
||||
.value_data = (v), .value_size = (vs) \
|
||||
}
|
||||
#define B_HASHMAP_KEY(k, ks) {.key_data = (k), .key_size = (ks)}
|
||||
#define B_HASHMAP_VALUE(v, vs) {.value_data = (v), .value_size = (vs)}
|
||||
|
||||
#define B_HASHMAP_ITEM(k, ks, v, vs) \
|
||||
{ \
|
||||
.key = B_HASHMAP_KEY(k, ks), .value = B_HASHMAP_VALUE(v, vs) \
|
||||
}
|
||||
{.key = B_HASHMAP_KEY(k, ks), .value = B_HASHMAP_VALUE(v, vs)}
|
||||
|
||||
#define B_HASHMAP_ITEM_END \
|
||||
{ \
|
||||
.key = {0}, .value = { 0 } \
|
||||
}
|
||||
#define B_HASHMAP_ITEM_END {.key = {0}, .value = {0}}
|
||||
|
||||
#define b_hashmap_foreach(it, hashmap) \
|
||||
for (int z__b_unique_name() = b_hashmap_iterator_begin(hashmap, it); \
|
||||
@@ -38,7 +28,12 @@ typedef struct b_hashmap b_hashmap;
|
||||
typedef void (*b_hashmap_key_destructor)(void *);
|
||||
typedef void (*b_hashmap_value_destructor)(void *);
|
||||
|
||||
typedef enum b_hashmap_key_flags {
|
||||
B_HASHMAP_KEY_F_INTVALUE = 0x01u,
|
||||
} b_hashmap_key_flags;
|
||||
|
||||
typedef struct b_hashmap_key {
|
||||
b_hashmap_key_flags key_flags;
|
||||
const void *key_data;
|
||||
size_t key_size;
|
||||
} b_hashmap_key;
|
||||
|
||||
@@ -237,6 +237,17 @@ static inline size_t b_number_get_size_t(const b_number *number)
|
||||
|
||||
BLUE_API bool b_number_is_integer(const b_number *number);
|
||||
BLUE_API bool b_number_is_float(const b_number *number);
|
||||
BLUE_API bool b_number_is_inf(const b_number *number);
|
||||
BLUE_API bool b_number_is_inf_positive(const b_number *number);
|
||||
BLUE_API bool b_number_is_inf_negative(const b_number *number);
|
||||
BLUE_API bool b_number_is_nan(const b_number *number);
|
||||
BLUE_API bool b_number_is_nan_positive(const b_number *number);
|
||||
BLUE_API bool b_number_is_nan_negative(const b_number *number);
|
||||
|
||||
BLUE_API void b_number_set_inf_positive(b_number *number, bool v);
|
||||
BLUE_API void b_number_set_inf_negative(b_number *number, bool v);
|
||||
BLUE_API void b_number_set_nan_positive(b_number *number, bool v);
|
||||
BLUE_API void b_number_set_nan_negative(b_number *number, bool v);
|
||||
|
||||
BLUE_API size_t b_number_data_size(const b_number *number);
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
#define B_DSREF(p) ((b_dsref *)(p))
|
||||
|
||||
#define B_TYPEOF(object) ((struct b_dsref *)(object)->ob_type)
|
||||
#define B_TYPEID(object) (b_typeid(B_DSREF(object)))
|
||||
#define B_TYPEOF(object) ((struct b_dsref *)(object)->ob_type)
|
||||
#define B_TYPEID(object) (b_typeid(B_DSREF(object)))
|
||||
|
||||
#define B_RV(p) (b_make_rvalue(B_DSREF(p)))
|
||||
#define B_RVT(t, p) ((t *)(b_make_rvalue(B_DSREF(p))))
|
||||
#define B_RV(p) (b_make_rvalue(B_DSREF(p)))
|
||||
#define B_RVT(t, p) ((t *)(b_make_rvalue(B_DSREF(p))))
|
||||
|
||||
#define B_DSREF_IS(object, type) (B_TYPEID(object) == B_DSREF_TYPE_##type)
|
||||
|
||||
@@ -32,7 +32,7 @@ BLUE_API b_dsref *b_make_rvalue(b_dsref *obj);
|
||||
BLUE_API b_dsref *b_retain(b_dsref *obj);
|
||||
BLUE_API void b_release(b_dsref *obj);
|
||||
|
||||
BLUE_API void b_to_string(b_dsref *obj, struct b_stream *out);
|
||||
BLUE_API void b_to_string(const b_dsref *obj, struct b_stream *out);
|
||||
BLUE_API b_dsref_type_id b_typeid(const b_dsref *obj);
|
||||
|
||||
BLUE_API b_comparison_result_t b_compare(const b_dsref *a, const b_dsref *b);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef BLUELIB_STRING_H_
|
||||
#define BLUELIB_STRING_H_
|
||||
|
||||
#include <blue/core/encoding.h>
|
||||
#include <blue/core/iterator.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/ds/object.h>
|
||||
#include <blue/ds/type.h>
|
||||
@@ -13,16 +15,44 @@ struct b_stream;
|
||||
#define B_CSTR(s) (b_string_create_from_cstr(s))
|
||||
#define B_RV_CSTR(s) (B_RV(b_string_create_from_cstr(s)))
|
||||
|
||||
#define b_string_foreach(it, str) \
|
||||
for (int z__b_unique_name() = b_string_iterator_begin(str, it); \
|
||||
b_string_iterator_is_valid(it); b_string_iterator_next(it))
|
||||
|
||||
typedef struct b_string b_string;
|
||||
|
||||
typedef struct b_string_iterator {
|
||||
b_iterator _base;
|
||||
int _m, _f;
|
||||
b_string *_s, *_tmp;
|
||||
const char **_d;
|
||||
size_t _nd, _ds;
|
||||
|
||||
b_status status;
|
||||
size_t iteration_index;
|
||||
size_t byte_index;
|
||||
size_t codepoint_index;
|
||||
b_wchar char_value;
|
||||
const char *string_value;
|
||||
size_t string_length;
|
||||
size_t string_codepoints;
|
||||
} b_string_iterator;
|
||||
|
||||
typedef enum b_strlen_flags {
|
||||
B_STRLEN_NORMAL = 0,
|
||||
B_STRLEN_IGNORE_ESC = 0x01u,
|
||||
B_STRLEN_IGNORE_MOD = 0x02u,
|
||||
B_STRLEN_CODEPOINTS = 0x04u,
|
||||
} b_strlen_flags;
|
||||
|
||||
typedef enum b_string_tokenise_flags {
|
||||
B_STRING_TOK_F_NORMAL = 0x00u,
|
||||
B_STRING_TOK_F_INCLUDE_EMPTY_TOKENS = 0x01u,
|
||||
} b_string_tokenise_flags;
|
||||
|
||||
BLUE_API b_string *b_string_create(void);
|
||||
BLUE_API b_string *b_string_create_from_cstr(const char *s);
|
||||
BLUE_API b_string *b_string_create_from_wstr(const b_wchar *s);
|
||||
BLUE_API b_string *b_string_create_from_c(char c, size_t count);
|
||||
BLUE_API b_string *b_string_duplicate(const b_string *str);
|
||||
|
||||
@@ -41,6 +71,7 @@ BLUE_API b_status b_string_replace(
|
||||
BLUE_API b_status b_string_replace_all(b_string *str, const char *new_data);
|
||||
BLUE_API b_status b_string_remove(b_string *str, size_t start, size_t length);
|
||||
BLUE_API b_status b_string_transform(b_string *str, int (*transformer)(int));
|
||||
BLUE_API b_status b_string_trim(b_string *str);
|
||||
static inline b_status b_string_toupper(b_string *str)
|
||||
{
|
||||
return b_string_transform(str, toupper);
|
||||
@@ -51,22 +82,42 @@ static inline b_status b_string_tolower(b_string *str)
|
||||
}
|
||||
BLUE_API b_status b_string_open_stream(b_string *str, struct b_stream **out);
|
||||
|
||||
BLUE_API void b_string_append_s(b_string *dest, const b_string *src);
|
||||
BLUE_API void b_string_append_cstr(b_string *dest, const char *src);
|
||||
BLUE_API void b_string_append_cstrf(b_string *dest, const char *format, ...);
|
||||
BLUE_API void b_string_prepend_cstr(b_string *dest, const char *src);
|
||||
BLUE_API void b_string_prepend_cstrf(b_string *dest, const char *format, ...);
|
||||
BLUE_API void b_string_insert_s(b_string *dest, const b_string *src, size_t at);
|
||||
BLUE_API void b_string_insert_cstr(b_string *dest, const char *src, size_t at);
|
||||
BLUE_API void b_string_insert_cstrn(
|
||||
BLUE_API b_status b_string_append_c(b_string *dest, char c);
|
||||
BLUE_API b_status b_string_append_wc(b_string *dest, b_wchar c);
|
||||
BLUE_API b_status b_string_append_s(b_string *dest, const b_string *src);
|
||||
BLUE_API b_status b_string_append_cstr(b_string *dest, const char *src);
|
||||
BLUE_API b_status b_string_append_wstr(b_string *dest, const b_wchar *src);
|
||||
BLUE_API b_status b_string_append_cstrf(b_string *dest, const char *format, ...);
|
||||
|
||||
BLUE_API b_status b_string_prepend_c(b_string *dest, char c);
|
||||
BLUE_API b_status b_string_prepend_wc(b_string *dest, b_wchar c);
|
||||
BLUE_API b_status b_string_prepend_cstr(b_string *dest, const char *src);
|
||||
BLUE_API b_status b_string_prepend_wstr(b_string *dest, const b_wchar *src);
|
||||
BLUE_API b_status b_string_prepend_cstrf(b_string *dest, const char *format, ...);
|
||||
|
||||
BLUE_API b_status b_string_insert_c(b_string *dest, char c, size_t at);
|
||||
BLUE_API b_status b_string_insert_wc(b_string *dest, b_wchar c, size_t at);
|
||||
BLUE_API b_status b_string_insert_s(b_string *dest, const b_string *src, size_t at);
|
||||
BLUE_API b_status b_string_insert_cstr(b_string *dest, const char *src, size_t at);
|
||||
BLUE_API b_status b_string_insert_wstr(
|
||||
b_string *dest, const b_wchar *src, size_t at);
|
||||
BLUE_API b_status b_string_insert_cstrn(
|
||||
b_string *dest, const char *src, size_t len, size_t at);
|
||||
BLUE_API void b_string_insert_cstrf(
|
||||
BLUE_API b_status b_string_insert_wstrn(
|
||||
b_string *dest, const char *src, size_t len, size_t at);
|
||||
BLUE_API b_status b_string_insert_cstrf(
|
||||
b_string *dest, size_t at, const char *format, ...);
|
||||
BLUE_API void b_string_clear(b_string *str);
|
||||
|
||||
BLUE_API b_status b_string_tokenise(
|
||||
b_string *str, const char *delims[], size_t nr_delims,
|
||||
b_string_tokenise_flags flags, b_string_iterator *it);
|
||||
|
||||
BLUE_API size_t b_string_get_size(const b_string *str, b_strlen_flags flags);
|
||||
BLUE_API size_t b_string_get_capacity(const b_string *str);
|
||||
|
||||
BLUE_API bool b_string_compare(const b_string *a, const b_string *b);
|
||||
|
||||
BLUE_API char b_string_front(const b_string *str);
|
||||
BLUE_API char b_string_back(const b_string *str);
|
||||
|
||||
@@ -75,9 +126,16 @@ BLUE_API void b_string_pop_back(b_string *str);
|
||||
BLUE_API const char *b_string_ptr(const b_string *str);
|
||||
BLUE_API b_string *b_string_substr(const b_string *str, size_t start, size_t len);
|
||||
|
||||
BLUE_API int b_string_iterator_begin(const b_string *string, b_string_iterator *it);
|
||||
BLUE_API bool b_string_iterator_next(b_string_iterator *it);
|
||||
// BLUE_API b_status b_string_iterator_erase(b_string_iterator *it);
|
||||
BLUE_API bool b_string_iterator_is_valid(const b_string_iterator *it);
|
||||
|
||||
BLUE_API char *b_strdup(const char *s);
|
||||
BLUE_API size_t b_strlen(const char *s, b_strlen_flags flags);
|
||||
BLUE_API b_wchar *b_wstrdup(const b_wchar *s);
|
||||
BLUE_API size_t b_wstrlen(const b_wchar *s);
|
||||
|
||||
BLUE_API uint64_t b_cstr_hash(const char *s);
|
||||
BLUE_API uint64_t b_string_hash(const b_string *s);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,7 @@ typedef enum b_fundamental_type_id {
|
||||
B_DSREF_TYPE_PATH,
|
||||
B_DSREF_TYPE_FILE,
|
||||
B_DSREF_TYPE_DIRECTORY,
|
||||
B_DSREF_TYPE_DATETIME,
|
||||
} b_fundamental_type_id;
|
||||
|
||||
typedef enum b_dsref_type_flags {
|
||||
@@ -44,7 +45,7 @@ typedef struct b_dsref_type {
|
||||
b_queue_entry t_entry;
|
||||
void (*t_init)(struct b_dsref *);
|
||||
void (*t_release)(struct b_dsref *);
|
||||
void (*t_to_string)(struct b_dsref *, struct b_stream *);
|
||||
void (*t_to_string)(const struct b_dsref *, struct b_stream *);
|
||||
} b_dsref_type;
|
||||
|
||||
BLUE_API b_status b_dsref_type_register(b_dsref_type *type);
|
||||
|
||||
Reference in New Issue
Block a user