MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / parse_string

Function parse_string

tinyemu/json.c:40–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38#include "fs_utils.h"
39
40static JSONValue parse_string(const char **pp)
41{
42 char buf[4096], *q;
43 const char *p;
44 int c, h;
45
46 q = buf;
47 p = *pp;
48 p++;
49 for(;;) {
50 c = *p++;
51 if (c == '\0' || c == '\n') {
52 return json_error_new("unterminated string");
53 } else if (c == '\"') {
54 break;
55 } else if (c == '\\') {
56 c = *p++;
57 switch(c) {
58 case '\'':
59 case '\"':
60 case '\\':
61 goto add_char;
62 case 'n':
63 c = '\n';
64 goto add_char;
65 case 'r':
66 c = '\r';
67 goto add_char;
68 case 't':
69 c = '\t';
70 goto add_char;
71 case 'x':
72 h = from_hex(*p++);
73 if (h < 0)
74 return json_error_new("invalig hex digit");
75 c = h << 4;
76 h = from_hex(*p++);
77 if (h < 0)
78 return json_error_new("invalig hex digit");
79 c |= h;
80 goto add_char;
81 default:
82 return json_error_new("unknown escape code");
83 }
84 } else {
85 add_char:
86 if (q >= buf + sizeof(buf) - 1)
87 return json_error_new("string too long");
88 *q++ = c;
89 }
90 }
91 *q = '\0';
92 *pp = p;
93 return json_string_new(buf);
94}
95
96static JSONProperty *json_object_get2(JSONObject *obj, const char *name)
97{

Callers 1

json_parse_value2Function · 0.85

Calls 3

json_error_newFunction · 0.85
from_hexFunction · 0.85
json_string_newFunction · 0.85

Tested by

no test coverage detected