diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 30a2b8090c4fd9bab667814c518ec4a9ec41628d
parent dc797245bbccdfaab4c6c0c145617c17ac2a2f78
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sat, 14 Sep 2024 14:39:21 +0200

feat: remove unneeded extract_json_value()

Diffstat:
Msrc/utils.c | 40----------------------------------------
Msrc/utils.h | 1-
2 files changed, 0 insertions(+), 41 deletions(-)

diff --git a/src/utils.c b/src/utils.c @@ -27,46 +27,6 @@ bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i) { return (access(epath, F_OK) != -1); } -char* extract_json_value(const char* json, char* key, bool quoted) { - // work on a copy of the json - char* jsoncp = (char*) malloc(strlen(json) * sizeof(char) + 1); - if (jsoncp == NULL) { - perror("malloc failed"); - return NULL; - } - strcpy(jsoncp, json); - - char* tok = strtok(jsoncp, " "); - while (tok != NULL) { - if (strstr(tok, key) != NULL) { - tok = strtok(NULL, " "); // value - break; - } - // key was not in this tok, advance tok - tok = strtok(NULL, " "); - } - - // remove quotes and comma or commma only - if (quoted) { - tok = strtok(tok, "\""); - } else { - tok = strtok(tok, ","); - } - - char* res = NULL; - if (tok != NULL) { - res = (char*) malloc(strlen(tok) * sizeof(char) + 1); - if (res == NULL) { - perror("malloc failed"); - return NULL; - } - strcpy(res, tok); - } - - free(jsoncp); - return res; -} - char* fold(const char* str) { // work on a copy of the str char* strcp = (char *) malloc(strlen(str) * sizeof(char) + 1); diff --git a/src/utils.h b/src/utils.h @@ -23,7 +23,6 @@ void update_date(WINDOW* header, struct tm* curs_date); bool date_has_entry(const char* dir, size_t dir_size, const struct tm* i); -char* extract_json_value(const char* json, char* key, bool quoted); char* fold(const char* str); char* unfold(const char* str); char* extract_ical_field(const char* ical, char* key, long* start_pos, bool multline);