Changeset 73914 in vbox
- Timestamp:
- Aug 27, 2018 12:40:34 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r73909 r73914 1519 1519 * 1520 1520 * 1521 * Group 5, XML / HTML escapers:1521 * Group 5, XML / HTML, JSON and URI escapers: 1522 1522 * - \%RMas - Takes a string pointer (const char *) and outputs 1523 1523 * it as an attribute value with the proper escaping. … … 1526 1526 * - \%RMes - Takes a string pointer (const char *) and outputs 1527 1527 * it as an element with the necessary escaping. 1528 * 1529 * - \%RMjs - Takes a string pointer (const char *) and outputs 1530 * it in quotes with proper JSON escaping. 1528 1531 * 1529 1532 * - \%RMpf - Takes a string pointer (const char *) and outputs … … 1541 1544 * 1542 1545 * 1543 * Group 6, JSON escapers: 1544 * - \%RJs - Takes a string pointer (const char *) and outputs 1545 * it in quotes with proper escaping. 1546 * 1547 * 1548 * Group 7, CPU Architecture Register dumpers: 1546 * Group 6, CPU Architecture Register dumpers: 1549 1547 * - \%RAx86[reg] - Takes a 64-bit register value if the register is 1550 1548 * 64-bit or smaller. Check the code wrt which -
trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp
r73902 r73914 38 38 39 39 40 41 40 /********************************************************************************************************************************* 42 41 * RTCRestObjectBase implementation * … … 621 620 RTCRestOutputBase &RTCRestString::serializeAsJson(RTCRestOutputBase &a_rDst) const 622 621 { 623 a_rDst.printf("%R Js", m_psz);622 a_rDst.printf("%RMjs", m_psz); 624 623 return a_rDst; 625 624 } -
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r73910 r73914 1293 1293 1294 1294 /* 1295 * Group 5, XML / HTML escapers.1295 * Group 5, XML / HTML, JSON and URI escapers. 1296 1296 */ 1297 1297 case 'M': … … 1300 1300 if (chWhat == 'a' || chWhat == 'e') 1301 1301 { 1302 /* XML attributes and element values. */ 1302 1303 bool fAttr = chWhat == 'a'; 1303 1304 char chType = (*ppszFormat)[1]; … … 1364 1365 } 1365 1366 } 1367 else if (chWhat == 'j') 1368 { 1369 /* JSON string escaping. */ 1370 char const chType = (*ppszFormat)[1]; 1371 *ppszFormat += 2; 1372 switch (chType) 1373 { 1374 case 's': 1375 { 1376 const char *pszStr = va_arg(*pArgs, char *); 1377 size_t cchOutput; 1378 ssize_t cchStr; 1379 ssize_t offCur; 1380 ssize_t offLast; 1381 1382 if (!VALID_PTR(pszStr)) 1383 pszStr = "<NULL>"; 1384 cchStr = RTStrNLen(pszStr, (unsigned)cchPrecision); 1385 1386 cchOutput = pfnOutput(pvArgOutput, "\"", 1); 1387 if (!(fFlags & RTSTR_F_LEFT)) 1388 while (--cchWidth >= cchStr) 1389 cchOutput += pfnOutput(pvArgOutput, " ", 1); 1390 1391 offLast = offCur = 0; 1392 while (offCur < cchStr) 1393 { 1394 unsigned int const uch = pszStr[offCur]; 1395 if ( uch >= 0x5d 1396 || (uch >= 0x20 && uch != 0x22 && uch != 0x5c)) 1397 offCur++; 1398 else 1399 { 1400 if (offLast < offCur) 1401 cchOutput += pfnOutput(pvArgOutput, &pszStr[offLast], offCur - offLast); 1402 switch ((char)uch) 1403 { 1404 case '"': cchOutput += pfnOutput(pvArgOutput, "\\\"", 2); break; 1405 case '\\': cchOutput += pfnOutput(pvArgOutput, "\\\\", 2); break; 1406 case '/': cchOutput += pfnOutput(pvArgOutput, "\\/", 2); break; 1407 case '\b': cchOutput += pfnOutput(pvArgOutput, "\\b", 2); break; 1408 case '\f': cchOutput += pfnOutput(pvArgOutput, "\\f", 2); break; 1409 case '\n': cchOutput += pfnOutput(pvArgOutput, "\\n", 2); break; 1410 case '\t': cchOutput += pfnOutput(pvArgOutput, "\\t", 2); break; 1411 default: 1412 { 1413 RTUNICP uc = 0xfffd; /* replacement character */ 1414 const char *pszCur = &pszStr[offCur]; 1415 int rc = RTStrGetCpEx(&pszCur, &uc); 1416 if (RT_SUCCESS(rc)) 1417 offCur += pszCur - &pszStr[offCur] - 1; 1418 if (uc >= 0xfffe) 1419 uc = 0xfffd; /* replacement character */ 1420 szBuf[0] = '\\'; 1421 szBuf[1] = 'u'; 1422 szBuf[2] = g_szHexDigits[(uc >> 12) & 0xf]; 1423 szBuf[3] = g_szHexDigits[(uc >> 8) & 0xf]; 1424 szBuf[4] = g_szHexDigits[(uc >> 4) & 0xf]; 1425 szBuf[5] = g_szHexDigits[ uc & 0xf]; 1426 szBuf[6] = '\0'; 1427 cchOutput += pfnOutput(pvArgOutput, szBuf, 6); 1428 break; 1429 } 1430 } 1431 offLast = ++offCur; 1432 } 1433 } 1434 if (offLast < offCur) 1435 cchOutput += pfnOutput(pvArgOutput, &pszStr[offLast], offCur - offLast); 1436 1437 while (--cchWidth >= cchStr) 1438 cchOutput += pfnOutput(pvArgOutput, " ", 1); 1439 cchOutput += pfnOutput(pvArgOutput, "\"", 1); 1440 return cchOutput; 1441 } 1442 1443 default: 1444 AssertMsgFailed(("Invalid IPRT format type '%.10s'!\n", pszFormatOrg)); 1445 } 1446 } 1366 1447 else if (chWhat == 'p') 1367 1448 { … … 1429 1510 } 1430 1511 1512 #endif /* IN_RING3 */ 1513 1431 1514 /* 1432 * Groups 6 - JSON. 1433 */ 1434 case 'J': 1435 { 1436 char chType = (*ppszFormat)[0]; 1437 *ppszFormat += 1; 1438 switch (chType) 1439 { 1440 case 's': 1441 { 1442 const char *pszStr = va_arg(*pArgs, char *); 1443 size_t cchOutput; 1444 ssize_t cchStr; 1445 ssize_t offCur; 1446 ssize_t offLast; 1447 1448 if (!VALID_PTR(pszStr)) 1449 pszStr = "<NULL>"; 1450 cchStr = RTStrNLen(pszStr, (unsigned)cchPrecision); 1451 1452 cchOutput = pfnOutput(pvArgOutput, "\"", 1); 1453 if (!(fFlags & RTSTR_F_LEFT)) 1454 while (--cchWidth >= cchStr) 1455 cchOutput += pfnOutput(pvArgOutput, " ", 1); 1456 1457 offLast = offCur = 0; 1458 while (offCur < cchStr) 1459 { 1460 unsigned int const uch = pszStr[offCur]; 1461 if ( uch >= 0x5d 1462 || (uch >= 0x20 && uch != 0x22 && uch != 0x5c)) 1463 offCur++; 1464 else 1465 { 1466 if (offLast < offCur) 1467 cchOutput += pfnOutput(pvArgOutput, &pszStr[offLast], offCur - offLast); 1468 switch ((char)uch) 1469 { 1470 case '"': cchOutput += pfnOutput(pvArgOutput, "\\\"", 2); break; 1471 case '\\': cchOutput += pfnOutput(pvArgOutput, "\\\\", 2); break; 1472 case '/': cchOutput += pfnOutput(pvArgOutput, "\\/", 2); break; 1473 case '\b': cchOutput += pfnOutput(pvArgOutput, "\\b", 2); break; 1474 case '\f': cchOutput += pfnOutput(pvArgOutput, "\\f", 2); break; 1475 case '\n': cchOutput += pfnOutput(pvArgOutput, "\\n", 2); break; 1476 case '\t': cchOutput += pfnOutput(pvArgOutput, "\\t", 2); break; 1477 default: 1478 cchOutput += pfnOutput(pvArgOutput, "\\u00", 2); 1479 cchOutput += pfnOutput(pvArgOutput, &g_szHexDigits[(uch >> 4) & 0xf], 1); 1480 cchOutput += pfnOutput(pvArgOutput, &g_szHexDigits[uch & 0xf], 1); 1481 break; 1482 } 1483 offLast = ++offCur; 1484 } 1485 } 1486 if (offLast < offCur) 1487 cchOutput += pfnOutput(pvArgOutput, &pszStr[offLast], offCur - offLast); 1488 1489 while (--cchWidth >= cchStr) 1490 cchOutput += pfnOutput(pvArgOutput, " ", 1); 1491 cchOutput += pfnOutput(pvArgOutput, "\"", 1); 1492 return cchOutput; 1493 } 1494 1495 default: 1496 AssertMsgFailed(("Invalid IPRT format type '%.10s'!\n", pszFormatOrg)); 1497 } 1498 break; 1499 } 1500 1501 #endif /* IN_RING3 */ 1502 1503 /* 1504 * Groups 7 - CPU Architecture Register Formatters. 1515 * Groups 6 - CPU Architecture Register Formatters. 1505 1516 * "%RAarch[reg]" 1506 1517 */
Note:
See TracChangeset
for help on using the changeset viewer.