| 2213 | */ |
| 2214 | |
| 2215 | std::wstring String::GetWideString() const |
| 2216 | { |
| 2217 | static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t size is not supported"); |
| 2218 | if (m_sharedString->size == 0) |
| 2219 | return std::wstring(); |
| 2220 | |
| 2221 | std::wstring str; |
| 2222 | str.reserve(m_sharedString->size); |
| 2223 | |
| 2224 | if (sizeof(wchar_t) == 4) // I want a static_if :( |
| 2225 | utf8::utf8to32(begin(), end(), std::back_inserter(str)); |
| 2226 | else |
| 2227 | { |
| 2228 | utf8::unchecked::iterator<const char*> it(m_sharedString->string.get()); |
| 2229 | do |
| 2230 | { |
| 2231 | char32_t cp = *it; |
| 2232 | if (cp <= 0xFFFF && (cp < 0xD800 || cp > 0xDFFF)) // @Laurent Gomila |
| 2233 | str.push_back(static_cast<wchar_t>(cp)); |
| 2234 | else |
| 2235 | str.push_back(L'?'); |
| 2236 | } |
| 2237 | while (*it++); |
| 2238 | } |
| 2239 | |
| 2240 | return str; |
| 2241 | } |
| 2242 | |
| 2243 | /*! |
| 2244 | * \brief Gets the word until next separator |
no test coverage detected