CSVs don't like ',' in the middle. We short circuit this * by wrapping the desc in double-quotes ("). But what if * there's already double-quotes? Well we swap these to * single-quotes (') and then use the json_escape function */
| 96 | * there's already double-quotes? Well we swap these to |
| 97 | * single-quotes (') and then use the json_escape function */ |
| 98 | static char *csv_safe_str(const tal_t *ctx, const char *input TAKES) |
| 99 | { |
| 100 | struct json_escape *esc; |
| 101 | char *dupe; |
| 102 | |
| 103 | /* Update the double-quotes in place */ |
| 104 | dupe = tal_strdup(tmpctx, input); |
| 105 | for (size_t i = 0; dupe[i] != '\0'; i++) { |
| 106 | if (dupe[i] == '"') |
| 107 | dupe[i] = '\''; |
| 108 | } |
| 109 | |
| 110 | esc = json_escape(tmpctx, take(dupe)); |
| 111 | return tal_fmt(ctx, "\"%s\"", esc->s); |
| 112 | } |
| 113 | |
| 114 | static struct income_event *maybe_chain_income(const tal_t *ctx, |
| 115 | const struct bkpr *bkpr, |
no test coverage detected