From 932227bbac7fe740bff1e38bf92b58edef19e32f Mon Sep 17 00:00:00 2001 From: default Date: Wed, 8 Jan 2025 16:59:14 +0100 Subject: Bumped copyright year. --- xs_version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xs_version.h') diff --git a/xs_version.h b/xs_version.h index 770366a..fc3b755 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 297f71e198be7819213e9122e1e78c3b963111bc 2024-11-24T18:48:42+01:00 */ +/* 9e8f5cf300ffbf453031f2ec923cef0822a41b41 2025-01-08T16:57:26+01:00 */ -- cgit From 9fd234d05edd9b6690fd9f14546f93b29e8379cf Mon Sep 17 00:00:00 2001 From: default Date: Sun, 12 Jan 2025 06:59:16 +0100 Subject: Backport from xs. --- xs.h | 16 ++++++++++++---- xs_version.h | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'xs_version.h') diff --git a/xs.h b/xs.h index a6e40d5..2a90467 100644 --- a/xs.h +++ b/xs.h @@ -1061,14 +1061,15 @@ xs_keyval *xs_keyval_make(xs_keyval *keyval, const xs_str *key, const xs_val *va typedef struct { int value_offset; /* offset to value (from dict start) */ - int next; /* next node in sequential search */ + int next; /* next node in sequential scanning */ int child[4]; /* child nodes in hashed search */ char key[]; /* C string key */ } ditem_hdr; typedef struct { int size; /* size of full dict (_XS_TYPE_SIZE) */ - int first; /* first node for sequential search */ + int first; /* first node for sequential scanning */ + int last; /* last node for sequential scanning */ int root; /* root node for hashed search */ /* a bunch of ditem_hdr and value follows */ } dict_hdr; @@ -1153,8 +1154,15 @@ xs_dict *xs_dict_set(xs_dict *dict, const xs_str *key, const xs_val *value) memcpy(dict + di->value_offset, value, vsz); /* chain to the sequential list */ - di->next = dh->first; - dh->first = end; + if (dh->first == 0) + dh->first = end; + else { + /* chain this new element to the last one */ + ditem_hdr *dil = (ditem_hdr *)(dict + dh->last); + dil->next = end; + } + + dh->last = end; } else { /* ditem already exists */ diff --git a/xs_version.h b/xs_version.h index fc3b755..ded4335 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 9e8f5cf300ffbf453031f2ec923cef0822a41b41 2025-01-08T16:57:26+01:00 */ +/* c317231894f28c39ba45a46f493f124d12a12f3a 2025-01-12T06:56:21+01:00 */ -- cgit From 5aaa6192ef08de7ab6c63e85708a1c825e9ff5f1 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 12 Jan 2025 14:59:28 +0100 Subject: Better dangling hashtag checking. --- html.c | 14 +++++++------- xs.h | 3 +++ xs_version.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'xs_version.h') diff --git a/html.c b/html.c index 6a5aa10..322bafa 100644 --- a/html.c +++ b/html.c @@ -2317,8 +2317,9 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, /* show all hashtags that has not been shown previously in the content */ const xs_list *tags = xs_dict_get(msg, "tag"); - if (xs_type(tags) == XSTYPE_LIST && xs_list_len(tags)) { - const char *o_content = xs_dict_get_def(msg, "content", ""); + const char *o_content = xs_dict_get_def(msg, "content", ""); + + if (xs_is_string(o_content) && xs_is_list(tags) && xs_list_len(tags)) { xs *content = xs_utf8_to_lower(o_content); const xs_dict *tag; @@ -2328,16 +2329,15 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, xs_list_foreach(tags, tag) { const char *type = xs_dict_get(tag, "type"); - if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Hashtag") == 0) { + if (xs_is_string(type) && strcmp(type, "Hashtag") == 0) { const char *o_href = xs_dict_get(tag, "href"); + const char *name = xs_dict_get(tag, "name"); - if (xs_type(o_href) == XSTYPE_STRING) { + if (xs_is_string(o_href) && xs_is_string(name)) { xs *href = xs_utf8_to_lower(o_href); - if (xs_str_in(content, href) == -1) { + if (xs_str_in(content, href) == -1 && xs_str_in(content, name) == -1) { /* not in the content: add here */ - const char *name = xs_dict_get(tag, "name"); - xs_html_add(add_hashtags, xs_html_tag("li", xs_html_tag("a", diff --git a/xs.h b/xs.h index 2a90467..45952c9 100644 --- a/xs.h +++ b/xs.h @@ -157,6 +157,9 @@ unsigned int xs_hash_func(const char *data, int size); #define xs_is_true(v) (xs_type((v)) == XSTYPE_TRUE) #define xs_is_false(v) (xs_type((v)) == XSTYPE_FALSE) #define xs_not(v) xs_stock(xs_is_true((v)) ? XSTYPE_FALSE : XSTYPE_TRUE) +#define xs_is_string(v) (xs_type((v)) == XSTYPE_STRING) +#define xs_is_list(v) (xs_type((v)) == XSTYPE_LIST) +#define xs_is_dict(v) (xs_type((v)) == XSTYPE_DICT) #define xs_list_foreach(l, v) for (int ct_##__LINE__ = 0; xs_list_next(l, &v, &ct_##__LINE__); ) #define xs_dict_foreach(l, k, v) for (int ct_##__LINE__ = 0; xs_dict_next(l, &k, &v, &ct_##__LINE__); ) diff --git a/xs_version.h b/xs_version.h index ded4335..ce3d06b 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* c317231894f28c39ba45a46f493f124d12a12f3a 2025-01-12T06:56:21+01:00 */ +/* cebb5663f26bc91b80c787525f5953b97839e0f7 2025-01-12T14:57:12+01:00 */ -- cgit From ddc8781b3a93d77836b61f3efa884b3c23a1fd35 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 12 Jan 2025 16:21:20 +0100 Subject: Minor improvements to start / end event time showing. --- html.c | 8 ++++---- xs.h | 5 ++--- xs_version.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'xs_version.h') diff --git a/html.c b/html.c index 322bafa..c55937d 100644 --- a/html.c +++ b/html.c @@ -2275,18 +2275,18 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, if (strcmp(type, "Event") == 0) { /** Event start and end times **/ const char *s_time = xs_dict_get(msg, "startTime"); - if (xs_type(s_time) == XSTYPE_STRING) { + if (xs_is_string(s_time) && strlen(s_time) > 20) { const char *e_time = xs_dict_get(msg, "endTime"); const char *tz = xs_dict_get(msg, "timezone"); xs *s = xs_replace_i(xs_dup(s_time), "T", " "); xs *e = NULL; - if (xs_type(e_time) == XSTYPE_STRING) + if (xs_is_string(e_time) && strlen(e_time) > 20) e = xs_replace_i(xs_dup(e_time), "T", " "); /* if the event has a timezone, crop the offsets */ - if (xs_type(tz) == XSTYPE_STRING) { + if (xs_is_string(tz)) { s = xs_crop_i(s, 0, 19); if (e) @@ -2297,7 +2297,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, /* if start and end share the same day, crop it from the end */ if (e && memcmp(s, e, 11) == 0) - e = xs_crop_i(e, 11, strlen(e)); + e = xs_crop_i(e, 11, 0); if (e) s = xs_str_cat(s, " / ", e); diff --git a/xs.h b/xs.h index 45952c9..05d84f5 100644 --- a/xs.h +++ b/xs.h @@ -626,15 +626,14 @@ int xs_between(const char *prefix, const char *str, const char *suffix) xs_str *xs_crop_i(xs_str *str, int start, int end) /* crops the string to be only from start to end */ { - XS_ASSERT_TYPE(str, XSTYPE_STRING); - int sz = strlen(str); if (end <= 0) end = sz + end; /* crop from the top */ - str[end] = '\0'; + if (end > 0 && end < sz) + str[end] = '\0'; /* crop from the bottom */ str = xs_collapse(str, 0, start); diff --git a/xs_version.h b/xs_version.h index ce3d06b..12f713a 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* cebb5663f26bc91b80c787525f5953b97839e0f7 2025-01-12T14:57:12+01:00 */ +/* b865e89769aedfdbc61251e94451e9d37579f52e 2025-01-12T16:17:47+01:00 */ -- cgit