| 1479 | |
| 1480 | /// |
| 1481 | void sParseList(const char* str, Vector< String >& outList) |
| 1482 | { |
| 1483 | // Skip the initial '( '. |
| 1484 | |
| 1485 | const char* ptr = str; |
| 1486 | while (*ptr && dIsspace(*ptr)) |
| 1487 | ptr++; |
| 1488 | |
| 1489 | if (*ptr == '(') |
| 1490 | { |
| 1491 | ptr++; |
| 1492 | while (*ptr && dIsspace(*ptr)) |
| 1493 | ptr++; |
| 1494 | } |
| 1495 | |
| 1496 | // Parse out list items. |
| 1497 | |
| 1498 | while (*ptr && *ptr != ')') |
| 1499 | { |
| 1500 | // Find end of element. |
| 1501 | |
| 1502 | const char* start = ptr; |
| 1503 | |
| 1504 | bool inString = false; |
| 1505 | U32 nestingCount = 0; |
| 1506 | |
| 1507 | while (*ptr && ((*ptr != ')' && *ptr != ',') || nestingCount > 0 || inString)) |
| 1508 | { |
| 1509 | if (*ptr == '(') |
| 1510 | nestingCount++; |
| 1511 | else if (*ptr == ')') |
| 1512 | nestingCount--; |
| 1513 | else if (*ptr == '"') |
| 1514 | inString = !inString; |
| 1515 | else if (*ptr == '\\' && ptr[1] == '"') |
| 1516 | ptr++; |
| 1517 | ptr++; |
| 1518 | } |
| 1519 | |
| 1520 | // Backtrack to remove trailing whitespace. |
| 1521 | |
| 1522 | const char* end = ptr; |
| 1523 | if (*end == ',' || *end == ')') |
| 1524 | end--; |
| 1525 | while (end > start && dIsspace(*end)) |
| 1526 | end--; |
| 1527 | if (*end) |
| 1528 | end++; |
| 1529 | |
| 1530 | // Add to list. |
| 1531 | |
| 1532 | if (start != end) |
| 1533 | outList.push_back(String(start, end - start)); |
| 1534 | |
| 1535 | // Skip comma and whitespace. |
| 1536 | |
| 1537 | if (*ptr == ',') |
| 1538 | ptr++; |
no test coverage detected