Mercurial > urweb
comparison src/c/urweb.c @ 1286:829da30fb808
Fix C-side jsification of UTF-8 strings
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Tue, 10 Aug 2010 16:02:55 -0400 |
parents | 236dc296c32d |
children | b4480a56cab7 |
comparison
equal
deleted
inserted
replaced
1285:514be09d5018 | 1286:829da30fb808 |
---|---|
1334 | 1334 |
1335 r = s2 = ctx->heap.front; | 1335 r = s2 = ctx->heap.front; |
1336 *s2++ = '"'; | 1336 *s2++ = '"'; |
1337 | 1337 |
1338 for (; *s; s++) { | 1338 for (; *s; s++) { |
1339 char c = *s; | 1339 unsigned char c = *s; |
1340 | 1340 |
1341 switch (c) { | 1341 switch (c) { |
1342 case '"': | 1342 case '"': |
1343 strcpy(s2, "\\\""); | 1343 strcpy(s2, "\\\""); |
1344 s2 += 2; | 1344 s2 += 2; |
1350 case '\\': | 1350 case '\\': |
1351 strcpy(s2, "\\\\"); | 1351 strcpy(s2, "\\\\"); |
1352 s2 += 2; | 1352 s2 += 2; |
1353 break; | 1353 break; |
1354 default: | 1354 default: |
1355 if (isprint((int)c)) | 1355 if (isprint((int)c) || c >= 128) |
1356 *s2++ = c; | 1356 *s2++ = c; |
1357 else { | 1357 else { |
1358 sprintf(s2, "\\%3o", c); | 1358 sprintf(s2, "\\%3o", c); |
1359 s2 += 4; | 1359 s2 += 4; |
1360 } | 1360 } |
1364 strcpy(s2, "\""); | 1364 strcpy(s2, "\""); |
1365 ctx->heap.front = s2 + 2; | 1365 ctx->heap.front = s2 + 2; |
1366 return r; | 1366 return r; |
1367 } | 1367 } |
1368 | 1368 |
1369 uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c) { | 1369 uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c1) { |
1370 unsigned char c = c1; | |
1370 char *r, *s2; | 1371 char *r, *s2; |
1371 | 1372 |
1372 uw_check_heap(ctx, 6); | 1373 uw_check_heap(ctx, 6); |
1373 | 1374 |
1374 r = s2 = ctx->heap.front; | 1375 r = s2 = ctx->heap.front; |
1386 case '\\': | 1387 case '\\': |
1387 strcpy(s2, "\\\\"); | 1388 strcpy(s2, "\\\\"); |
1388 s2 += 2; | 1389 s2 += 2; |
1389 break; | 1390 break; |
1390 default: | 1391 default: |
1391 if (isprint((int)c)) | 1392 if (isprint((int)c) || c >= 128) |
1392 *s2++ = c; | 1393 *s2++ = c; |
1393 else { | 1394 else { |
1394 sprintf(s2, "\\%3o", c); | 1395 sprintf(s2, "\\%3o", (unsigned char)c); |
1395 s2 += 4; | 1396 s2 += 4; |
1396 } | 1397 } |
1397 } | 1398 } |
1398 | 1399 |
1399 strcpy(s2, "\""); | 1400 strcpy(s2, "\""); |
1408 | 1409 |
1409 r = s2 = ctx->script.front; | 1410 r = s2 = ctx->script.front; |
1410 *s2++ = '"'; | 1411 *s2++ = '"'; |
1411 | 1412 |
1412 for (; *s; s++) { | 1413 for (; *s; s++) { |
1413 char c = *s; | 1414 unsigned char c = *s; |
1414 | 1415 |
1415 switch (c) { | 1416 switch (c) { |
1416 case '\'': | 1417 case '\'': |
1417 strcpy(s2, "\\"); | 1418 strcpy(s2, "\\"); |
1418 s2 += 2; | 1419 s2 += 2; |
1420 case '\\': | 1421 case '\\': |
1421 strcpy(s2, "\\\\"); | 1422 strcpy(s2, "\\\\"); |
1422 s2 += 2; | 1423 s2 += 2; |
1423 break; | 1424 break; |
1424 default: | 1425 default: |
1425 if (isprint((int)c)) | 1426 if (isprint((int)c) || c >= 128) |
1426 *s2++ = c; | 1427 *s2++ = c; |
1427 else { | 1428 else { |
1428 sprintf(s2, "\\%3o", c); | 1429 sprintf(s2, "\\%3o", c); |
1429 s2 += 4; | 1430 s2 += 4; |
1430 } | 1431 } |