MCPcopy Create free account
hub / github.com/ElementsProject/lightning / csv_safe_str

Function csv_safe_str

plugins/bkpr/incomestmt.c:95–109  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

93 * there's already double-quotes? Well we swap these to
94 * single-quotes (') and then use the json_escape function */
95static char *csv_safe_str(const tal_t *ctx, const char *input TAKES)
96{
97 struct json_escape *esc;
98 char *dupe;
99
100 /* Update the double-quotes in place */
101 dupe = tal_strdup(tmpctx, input);
102 for (size_t i = 0; dupe[i] != '\0'; i++) {
103 if (dupe[i] == '"')
104 dupe[i] = '\'';
105 }
106
107 esc = json_escape(tmpctx, take(dupe));
108 return tal_fmt(ctx, "\"%s\"", esc->s);
109}
110
111static struct income_event *maybe_chain_income(const tal_t *ctx,
112 const struct bkpr *bkpr,

Callers 3

koinly_entryFunction · 0.85
harmony_entryFunction · 0.85
quickbooks_entryFunction · 0.85

Calls 1

json_escapeClass · 0.70

Tested by

no test coverage detected