1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Scott Robinson
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Authors: Scott Robinson <scott@quadhome.com>
22 #include "notmuch-client.h"
25 * json_quote_str derived from cJSON's print_string_ptr,
26 * Copyright (c) 2009 Dave Gamble
30 json_quote_str(const void *ctx, const char *str)
40 for (ptr = str; *ptr; len++, ptr++) {
41 if (*ptr < 32 || *ptr == '\"' || *ptr == '\\')
45 out = talloc_array (ctx, char, len + 3);
52 if (*ptr > 31 && *ptr != '\"' && *ptr != '\\') {
57 case '\"': *ptr2++ = '\"'; break;
58 case '\\': *ptr2++ = '\\'; break;
59 case '\b': *ptr2++ = 'b'; break;
60 case '\f': *ptr2++ = 'f'; break;
61 case '\n': *ptr2++ = 'n'; break;
62 case '\r': *ptr2++ = 'r'; break;
63 case '\t': *ptr2++ = 't'; break;
64 default: ptr2--; break;