| 1661 | } |
| 1662 | |
| 1663 | void JsonWriter::ContinueString(LPCWSTR pStr) |
| 1664 | { |
| 1665 | D3D12MA_ASSERT(m_InsideString); |
| 1666 | D3D12MA_ASSERT(pStr); |
| 1667 | |
| 1668 | for (const WCHAR *p = pStr; *p; ++p) |
| 1669 | { |
| 1670 | // the strings we encode are assumed to be in UTF-16LE format, the native |
| 1671 | // windows wide character Unicode format. In this encoding Unicode code |
| 1672 | // points U+0000 to U+D7FF and U+E000 to U+FFFF are encoded in two bytes, |
| 1673 | // and everything else takes more than two bytes. We will reject any |
| 1674 | // multi wchar character encodings for simplicity. |
| 1675 | UINT val = (UINT)*p; |
| 1676 | D3D12MA_ASSERT(((val <= 0xD7FF) || (0xE000 <= val && val <= 0xFFFF)) && |
| 1677 | "Character not currently supported."); |
| 1678 | switch (*p) |
| 1679 | { |
| 1680 | case L'"': m_SB.Add(L'\\'); m_SB.Add(L'"'); break; |
| 1681 | case L'\\': m_SB.Add(L'\\'); m_SB.Add(L'\\'); break; |
| 1682 | case L'/': m_SB.Add(L'\\'); m_SB.Add(L'/'); break; |
| 1683 | case L'\b': m_SB.Add(L'\\'); m_SB.Add(L'b'); break; |
| 1684 | case L'\f': m_SB.Add(L'\\'); m_SB.Add(L'f'); break; |
| 1685 | case L'\n': m_SB.Add(L'\\'); m_SB.Add(L'n'); break; |
| 1686 | case L'\r': m_SB.Add(L'\\'); m_SB.Add(L'r'); break; |
| 1687 | case L'\t': m_SB.Add(L'\\'); m_SB.Add(L't'); break; |
| 1688 | default: |
| 1689 | // conservatively use encoding \uXXXX for any Unicode character |
| 1690 | // requiring more than one byte. |
| 1691 | if (32 <= val && val < 256) |
| 1692 | m_SB.Add(*p); |
| 1693 | else |
| 1694 | { |
| 1695 | m_SB.Add(L'\\'); |
| 1696 | m_SB.Add(L'u'); |
| 1697 | for (UINT i = 0; i < 4; ++i) |
| 1698 | { |
| 1699 | UINT hexDigit = (val & 0xF000) >> 12; |
| 1700 | val <<= 4; |
| 1701 | if (hexDigit < 10) |
| 1702 | m_SB.Add(L'0' + (WCHAR)hexDigit); |
| 1703 | else |
| 1704 | m_SB.Add(L'A' + (WCHAR)hexDigit); |
| 1705 | } |
| 1706 | } |
| 1707 | break; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | void JsonWriter::ContinueString(UINT num) |
| 1713 | { |
no test coverage detected