static char* S_extract_path_part(const char *path, const char *dir, const char *ext) { size_t path_len = strlen(path); size_t dir_len = strlen(dir); size_t ext_len = strlen(ext); if (path_len <= dir_len + ext_len) { CFCUtil_die("Unexpected path '%s'", path); } if (strncmp(path, dir, dir_len) != 0) { CFCUtil_die("'%s' doesn't start with '%s'", path, dir); } if (strcmp(path + path_len - ext_len, ext) != 0) { CFCUtil_die("'%s' doesn't end with '%s'", path, ext); } const char *src = path + dir_len; size_t path_part_len = path_len - (dir_len + ext_len); while (path_part_len && *src == CHY_DIR_SEP_CHAR) { ++src; --path_part_len; } return CFCUtil_strndup(src, path_part_len); }
// Parse a double quoted string. Don't allow escapes. static JSONNode* S_parse_json_string(const char **json) { const char *text = *json; if (*text != '\"') { return NULL; } text++; const char *start = text; while (*text != '"') { if (*text == '\\' || *text == '\0') { return NULL; } text++; } JSONNode *node = (JSONNode*)calloc(1, sizeof(JSONNode)); node->type = JSON_STRING; node->string = CFCUtil_strndup(start, text - start); // Move pointer. text++; *json = text; return node; }