Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ bool output_csv(struct whisper_context * ctx, const char * fname) {
return true;
}

char *escape_double_quotes(const char *str) {
char *escape_double_quotes_and_backslashes(const char *str) {
if (str == NULL) {
return NULL;
}

size_t escaped_length = strlen(str) + 1;

for (size_t i = 0; str[i] != '\0'; i++) {
if (str[i] == '"') {
if (str[i] == '"' || str[i] == '\\') {
escaped_length++;
}
}
Expand All @@ -395,12 +395,10 @@ char *escape_double_quotes(const char *str) {

size_t pos = 0;
for (size_t i = 0; str[i] != '\0'; i++) {
if (str[i] == '"') {
if (str[i] == '"' || str[i] == '\\') {
escaped[pos++] = '\\';
escaped[pos++] = '"';
} else {
escaped[pos++] = str[i];
}
escaped[pos++] = str[i];
}

// no need to set zero due to calloc() being used prior
Expand Down Expand Up @@ -451,7 +449,7 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper

auto value_s = [&](const char *name, const char *val, bool end = false) {
start_value(name);
char * val_escaped = escape_double_quotes(val);
char * val_escaped = escape_double_quotes_and_backslashes(val);
fout << "\"" << val_escaped << (end ? "\"\n" : "\",\n");
free(val_escaped);
};
Expand Down