Mercurial > foo_out_sdl
comparison foosdk/sdk/pfc/string-conv-lite.cpp @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #include "pfc-lite.h" | |
| 2 #include "string_conv.h" | |
| 3 #include "string-conv-lite.h" | |
| 4 | |
| 5 namespace pfc { | |
| 6 wstringLite wideFromUTF8(const char* pUTF8, size_t inSize) { | |
| 7 wstringLite ret; | |
| 8 size_t estimate = pfc::stringcvt::estimate_utf8_to_wide(pUTF8, inSize); | |
| 9 ret.m_buffer.resize(estimate); | |
| 10 pfc::stringcvt::convert_utf8_to_wide(ret.m_buffer.get_ptr(), estimate, pUTF8, inSize); | |
| 11 return ret; | |
| 12 } | |
| 13 string8 utf8FromWide(const wchar_t* pWide, size_t inSize) { | |
| 14 string8 ret; | |
| 15 size_t estimate = pfc::stringcvt::estimate_wide_to_utf8(pWide,inSize); | |
| 16 PFC_ASSERT(estimate > 0); | |
| 17 char* ptr = ret.lock_buffer(estimate-1/*nullterm included in estimate*/); | |
| 18 pfc::stringcvt::convert_wide_to_utf8(ptr, estimate, pWide, inSize); | |
| 19 ret.unlock_buffer(); | |
| 20 return ret; | |
| 21 } | |
| 22 wstringLite wideFromUTF8(const char* pUTF8) { | |
| 23 wstringLite ret; | |
| 24 size_t estimate = pfc::stringcvt::estimate_utf8_to_wide(pUTF8); | |
| 25 ret.m_buffer.resize(estimate); | |
| 26 pfc::stringcvt::convert_utf8_to_wide_unchecked(ret.m_buffer.get_ptr(), pUTF8); | |
| 27 return ret; | |
| 28 } | |
| 29 string8 utf8FromWide(const wchar_t* pWide) { | |
| 30 return utf8FromWide(pWide, SIZE_MAX); | |
| 31 } | |
| 32 } |
