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

Function csv_safe_str

plugins/bkpr/incomestmt.c:112–126  ·  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

110 * there's already double-quotes? Well we swap these to
111 * single-quotes (') and then use the json_escape function */
112static char *csv_safe_str(const tal_t *ctx, char *input TAKES)
113{
114 struct json_escape *esc;
115 char *dupe;
116
117 /* Update the double-quotes in place */
118 dupe = tal_strdup(tmpctx, input);
119 for (size_t i = 0; dupe[i] != '\0'; i++) {
120 if (dupe[i] == '"')
121 dupe[i] = '\'';
122 }
123
124 esc = json_escape(tmpctx, take(dupe));
125 return tal_fmt(ctx, "\"%s\"", esc->s);
126}
127
128static struct income_event *maybe_chain_income(const tal_t *ctx,
129 struct db *db,

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