1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Translate JSON5-only string literal escape sequences into the JSON equivalents.

FossilOrigin-Name: 14e82f36eed31af1237898728bf353b968523c62b1f8d1d90dbbabd92d0c2834
This commit is contained in:
drh
2023-04-27 12:24:00 +00:00
parent c5ee2d8e80
commit f59c01e24c
3 changed files with 42 additions and 8 deletions

View File

@@ -302,8 +302,42 @@ static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
** features.
*/
static void jsonAppendNormalizedString(JsonString *p, const char *zIn, u32 N){
int i;
jsonAppendChar(p, '"');
jsonAppendRaw(p, &zIn[1], N-2); /* TODO: translate JSON5 escapes */
zIn++;
N -= 2;
while( N>0 ){
for(i=0; i<N && zIn[i]!='\\'; i++){}
if( i>0 ){
jsonAppendRaw(p, zIn, i);
zIn += i;
N -= i;
if( N==0 ) break;
}
assert( zIn[0]=='\\' );
switch( zIn[1] ){
case '\'':
jsonAppendChar(p, '\'');
break;
case 'v':
jsonAppendRaw(p, "\\u0009", 6);
break;
case 'x':
jsonAppendRaw(p, "\\u00", 4);
jsonAppendRaw(p, &zIn[2], 2);
zIn += 2;
N -= 2;
break;
case '0':
jsonAppendRaw(p, "\\u0000", 6);
break;
default:
jsonAppendRaw(p, zIn, 2);
break;
}
zIn += 2;
N -= 2;
}
jsonAppendChar(p, '"');
}