diff options
author | bpc2003 <wpesfriendnva@gmail.com> | 2025-05-21 11:07:50 -0400 |
---|---|---|
committer | bpc2003 <wpesfriendnva@gmail.com> | 2025-05-21 11:07:50 -0400 |
commit | a08b44e1c6fbd8b56011a969f8c11bcc630e1ee0 (patch) | |
tree | 5a4337c8993f1bee673d4de819a5b64fe0aa1f95 /src/include/xml | |
parent | 3c07894d658c3fa75f1cd1fd524e7464d9d95f1d (diff) |
Decrease visibilty in encode and decode functions
Diffstat (limited to 'src/include/xml')
-rw-r--r-- | src/include/xml/decode.c | 11 | ||||
-rw-r--r-- | src/include/xml/encode.c | 7 | ||||
-rw-r--r-- | src/include/xml/xml.h | 7 |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/include/xml/decode.c b/src/include/xml/decode.c index 14af551..dccbc2f 100644 --- a/src/include/xml/decode.c +++ b/src/include/xml/decode.c @@ -10,7 +10,14 @@ static int check_closing_tag(char *xml, int *pos, char *tag, int *err); static void set_tag(char *xml, map_t **map, int *closed, int *pos); static void set_value(char *xml, int *pos, map_t **map); -map_t *decode(char *xml, int *pos, int *len) { +static map_t *decode_helper(char *xml, int *pos, int *len); + +map_t *decode(char *xml) { + int start = 0, len = 0; + return decode_helper(xml, &start, &len); +} + +static map_t *decode_helper(char *xml, int *pos, int *len) { if (*len) ++(*len); else @@ -26,7 +33,7 @@ map_t *decode(char *xml, int *pos, int *len) { } else if (xml[i] == '<' && closed) set_tag(xml, &decoded, &closed, &i); else if (xml[i] == '<' && !closed) { - map_t *ndec = decode(xml, &i, &(decoded->n)); + map_t *ndec = decode_helper(xml, &i, &(decoded->n)); decoded->size = sizeof(map_t); if (decoded->n > 1) decoded->payload = diff --git a/src/include/xml/encode.c b/src/include/xml/encode.c index 60e418d..6ed753e 100644 --- a/src/include/xml/encode.c +++ b/src/include/xml/encode.c @@ -5,8 +5,11 @@ #include "xml.h" static void check(char **str, int *len, int *used, int n); +static char *encode_helper(map_t *map, int len); -char *encode(map_t *map, int len) { +char *encode(map_t *map) { return encode_helper(map, 1); } + +static char *encode_helper(map_t *map, int len) { int slen = 128, used = 0; char *str = calloc(slen, sizeof(char)); @@ -25,7 +28,7 @@ char *encode(map_t *map, int len) { check(&str, &slen, &used, 1); strcat(str, ">"); if (map[i].size == sizeof(map_t)) { - char *rt = encode((map_t *)map[i].payload, map[i].n); + char *rt = encode_helper((map_t *)map[i].payload, map[i].n); if (rt == NULL) return NULL; check(&str, &slen, &used, strlen(rt)); diff --git a/src/include/xml/xml.h b/src/include/xml/xml.h index c812005..eb250e3 100644 --- a/src/include/xml/xml.h +++ b/src/include/xml/xml.h @@ -17,14 +17,11 @@ typedef struct { int n_attrs; } map_t; -// TODO: make encode more reliant on helpers -// to make function more private - /* decode: decodes the provided xml statement into a map_t */ -map_t *decode(char *xml, int *pos, int *len); +map_t *decode(char *xml); /* encode: encodes the provided map_t into a xml statement */ -char *encode(map_t *map, int len); +char *encode(map_t *map); /* freemap: frees a map and its children */ void freemap(map_t *map); |