diff options
| author | 2024-05-21 14:12:15 +0200 | |
|---|---|---|
| committer | 2024-05-21 14:12:15 +0200 | |
| commit | 4777fc86cb962917a8f34afb3bfa40f26290815d (patch) | |
| tree | 268c078531a018f07c1b6d029f14f87134805f7b /xs_html.h | |
| parent | Version 2.53 RELEASED. (diff) | |
| download | penes-snac2-4777fc86cb962917a8f34afb3bfa40f26290815d.tar.gz penes-snac2-4777fc86cb962917a8f34afb3bfa40f26290815d.tar.xz penes-snac2-4777fc86cb962917a8f34afb3bfa40f26290815d.zip | |
Added const everywhere.
Diffstat (limited to 'xs_html.h')
| -rw-r--r-- | xs_html.h | 34 |
1 files changed, 17 insertions, 17 deletions
| @@ -6,26 +6,26 @@ | |||
| 6 | 6 | ||
| 7 | typedef struct xs_html xs_html; | 7 | typedef struct xs_html xs_html; |
| 8 | 8 | ||
| 9 | xs_str *xs_html_encode(char *str); | 9 | xs_str *xs_html_encode(const char *str); |
| 10 | 10 | ||
| 11 | xs_html *xs_html_attr(char *key, char *value); | 11 | xs_html *xs_html_attr(const char *key, const char *value); |
| 12 | xs_html *xs_html_text(char *content); | 12 | xs_html *xs_html_text(const char *content); |
| 13 | xs_html *xs_html_raw(char *content); | 13 | xs_html *xs_html_raw(const char *content); |
| 14 | 14 | ||
| 15 | xs_html *_xs_html_add(xs_html *tag, xs_html *var[]); | 15 | xs_html *_xs_html_add(xs_html *tag, xs_html *var[]); |
| 16 | #define xs_html_add(tag, ...) _xs_html_add(tag, (xs_html *[]) { __VA_ARGS__, NULL }) | 16 | #define xs_html_add(tag, ...) _xs_html_add(tag, (xs_html *[]) { __VA_ARGS__, NULL }) |
| 17 | 17 | ||
| 18 | xs_html *_xs_html_tag(char *tag, xs_html *var[]); | 18 | xs_html *_xs_html_tag(const char *tag, xs_html *var[]); |
| 19 | #define xs_html_tag(tag, ...) _xs_html_tag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) | 19 | #define xs_html_tag(tag, ...) _xs_html_tag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) |
| 20 | 20 | ||
| 21 | xs_html *_xs_html_sctag(char *tag, xs_html *var[]); | 21 | xs_html *_xs_html_sctag(const char *tag, xs_html *var[]); |
| 22 | #define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) | 22 | #define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL }) |
| 23 | 23 | ||
| 24 | xs_html *_xs_html_container(xs_html *var[]); | 24 | xs_html *_xs_html_container(xs_html *var[]); |
| 25 | #define xs_html_container(...) _xs_html_container((xs_html *[]) { __VA_ARGS__, NULL }) | 25 | #define xs_html_container(...) _xs_html_container((xs_html *[]) { __VA_ARGS__, NULL }) |
| 26 | 26 | ||
| 27 | void xs_html_render_f(xs_html *h, FILE *f); | 27 | void xs_html_render_f(xs_html *h, FILE *f); |
| 28 | xs_str *xs_html_render_s(xs_html *tag, char *prefix); | 28 | xs_str *xs_html_render_s(xs_html *tag, const char *prefix); |
| 29 | #define xs_html_render(tag) xs_html_render_s(tag, NULL) | 29 | #define xs_html_render(tag) xs_html_render_s(tag, NULL) |
| 30 | 30 | ||
| 31 | 31 | ||
| @@ -47,16 +47,16 @@ struct xs_html { | |||
| 47 | xs_html *next; | 47 | xs_html *next; |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | xs_str *xs_html_encode(char *str) | 50 | xs_str *xs_html_encode(const char *str) |
| 51 | /* encodes str using HTML entities */ | 51 | /* encodes str using HTML entities */ |
| 52 | { | 52 | { |
| 53 | xs_str *s = xs_str_new(NULL); | 53 | xs_str *s = xs_str_new(NULL); |
| 54 | int o = 0; | 54 | int o = 0; |
| 55 | char *e = str + strlen(str); | 55 | const char *e = str + strlen(str); |
| 56 | 56 | ||
| 57 | for (;;) { | 57 | for (;;) { |
| 58 | char *ec = "<>\"'&"; /* characters to escape */ | 58 | char *ec = "<>\"'&"; /* characters to escape */ |
| 59 | char *q = e; | 59 | const char *q = e; |
| 60 | int z; | 60 | int z; |
| 61 | 61 | ||
| 62 | /* find the nearest happening of a char */ | 62 | /* find the nearest happening of a char */ |
| @@ -90,7 +90,7 @@ xs_str *xs_html_encode(char *str) | |||
| 90 | 90 | ||
| 91 | #define XS_HTML_NEW() memset(xs_realloc(NULL, sizeof(xs_html)), '\0', sizeof(xs_html)) | 91 | #define XS_HTML_NEW() memset(xs_realloc(NULL, sizeof(xs_html)), '\0', sizeof(xs_html)) |
| 92 | 92 | ||
| 93 | xs_html *xs_html_attr(char *key, char *value) | 93 | xs_html *xs_html_attr(const char *key, const char *value) |
| 94 | /* creates an HTML block with an attribute */ | 94 | /* creates an HTML block with an attribute */ |
| 95 | { | 95 | { |
| 96 | xs_html *a = XS_HTML_NEW(); | 96 | xs_html *a = XS_HTML_NEW(); |
| @@ -108,7 +108,7 @@ xs_html *xs_html_attr(char *key, char *value) | |||
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | 110 | ||
| 111 | xs_html *xs_html_text(char *content) | 111 | xs_html *xs_html_text(const char *content) |
| 112 | /* creates an HTML block of text, escaping it previously */ | 112 | /* creates an HTML block of text, escaping it previously */ |
| 113 | { | 113 | { |
| 114 | xs_html *a = XS_HTML_NEW(); | 114 | xs_html *a = XS_HTML_NEW(); |
| @@ -120,7 +120,7 @@ xs_html *xs_html_text(char *content) | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | 122 | ||
| 123 | xs_html *xs_html_raw(char *content) | 123 | xs_html *xs_html_raw(const char *content) |
| 124 | /* creates an HTML block without escaping (for pre-formatted HTML, comments, etc) */ | 124 | /* creates an HTML block without escaping (for pre-formatted HTML, comments, etc) */ |
| 125 | { | 125 | { |
| 126 | xs_html *a = XS_HTML_NEW(); | 126 | xs_html *a = XS_HTML_NEW(); |
| @@ -152,7 +152,7 @@ xs_html *_xs_html_add(xs_html *tag, xs_html *var[]) | |||
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | static xs_html *_xs_html_tag_t(xs_html_type type, char *tag, xs_html *var[]) | 155 | static xs_html *_xs_html_tag_t(xs_html_type type, const char *tag, xs_html *var[]) |
| 156 | /* creates a tag with a variable list of attributes and subtags */ | 156 | /* creates a tag with a variable list of attributes and subtags */ |
| 157 | { | 157 | { |
| 158 | xs_html *a = XS_HTML_NEW(); | 158 | xs_html *a = XS_HTML_NEW(); |
| @@ -169,13 +169,13 @@ static xs_html *_xs_html_tag_t(xs_html_type type, char *tag, xs_html *var[]) | |||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | 171 | ||
| 172 | xs_html *_xs_html_tag(char *tag, xs_html *var[]) | 172 | xs_html *_xs_html_tag(const char *tag, xs_html *var[]) |
| 173 | { | 173 | { |
| 174 | return _xs_html_tag_t(XS_HTML_TAG, tag, var); | 174 | return _xs_html_tag_t(XS_HTML_TAG, tag, var); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | xs_html *_xs_html_sctag(char *tag, xs_html *var[]) | 178 | xs_html *_xs_html_sctag(const char *tag, xs_html *var[]) |
| 179 | { | 179 | { |
| 180 | return _xs_html_tag_t(XS_HTML_SCTAG, tag, var); | 180 | return _xs_html_tag_t(XS_HTML_SCTAG, tag, var); |
| 181 | } | 181 | } |
| @@ -239,7 +239,7 @@ void xs_html_render_f(xs_html *h, FILE *f) | |||
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | 241 | ||
| 242 | xs_str *xs_html_render_s(xs_html *tag, char *prefix) | 242 | xs_str *xs_html_render_s(xs_html *tag, const char *prefix) |
| 243 | /* renders to a string */ | 243 | /* renders to a string */ |
| 244 | { | 244 | { |
| 245 | xs_str *s = NULL; | 245 | xs_str *s = NULL; |