summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jplist.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/jplist.c b/src/jplist.c
index 889ce30..3d3cad2 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -462,19 +462,9 @@ static plist_t parse_primitive(const char* js, jsmntok_t* tokens, int* index)
462 return val; 462 return val;
463} 463}
464 464
465static plist_t parse_string(const char* js, jsmntok_t* tokens, int* index) 465static char* unescape_string(const char* str_val, size_t str_len, size_t *new_len)
466{ 466{
467 if (tokens[*index].type != JSMN_STRING) {
468 PLIST_JSON_ERR("%s: token type != JSMN_STRING\n", __func__);
469 return NULL;
470 }
471
472 const char* str_val = js + tokens[*index].start;
473 size_t str_len = tokens[*index].end - tokens[*index].start;
474 char* strval = strndup(str_val, str_len); 467 char* strval = strndup(str_val, str_len);
475 plist_t node;
476
477 /* unescape */
478 size_t i = 0; 468 size_t i = 0;
479 while (i < str_len) { 469 while (i < str_len) {
480 if (strval[i] == '\\' && i < str_len-1) { 470 if (strval[i] == '\\' && i < str_len-1) {
@@ -543,6 +533,23 @@ static plist_t parse_string(const char* js, jsmntok_t* tokens, int* index)
543 } 533 }
544 i++; 534 i++;
545 } 535 }
536 strval[str_len] = '\0';
537 if (new_len) {
538 *new_len = str_len;
539 }
540 return strval;
541}
542
543static plist_t parse_string(const char* js, jsmntok_t* tokens, int* index)
544{
545 if (tokens[*index].type != JSMN_STRING) {
546 PLIST_JSON_ERR("%s: token type != JSMN_STRING\n", __func__);
547 return NULL;
548 }
549
550 size_t str_len = 0; ;
551 char* strval = unescape_string(js + tokens[*index].start, tokens[*index].end - tokens[*index].start, &str_len);
552 plist_t node;
546 553
547 plist_data_t data = plist_new_plist_data(); 554 plist_data_t data = plist_new_plist_data();
548 data->type = PLIST_STRING; 555 data->type = PLIST_STRING;
@@ -604,7 +611,7 @@ static plist_t parse_object(const char* js, jsmntok_t* tokens, int* index)
604 int j = (*index)+1; 611 int j = (*index)+1;
605 for (num = 0; num < num_tokens; num++) { 612 for (num = 0; num < num_tokens; num++) {
606 if (tokens[j].type == JSMN_STRING) { 613 if (tokens[j].type == JSMN_STRING) {
607 char* key = strndup(js + tokens[j].start, tokens[j].end - tokens[j].start); 614 char* key = unescape_string(js + tokens[j].start, tokens[j].end - tokens[j].start, NULL);
608 plist_t val = NULL; 615 plist_t val = NULL;
609 j++; 616 j++;
610 num++; 617 num++;