| 38 | } |
| 39 | |
| 40 | String cpp::encoding::Ascii::decode(View<uint8_t> view) |
| 41 | { |
| 42 | if (view.isEmpty()) |
| 43 | { |
| 44 | return hx::Throw(HX_CSTRING("View is empty")); |
| 45 | } |
| 46 | |
| 47 | auto bytes = int64_t{ 0 }; |
| 48 | auto i = int64_t{ 0 }; |
| 49 | auto chars = view.reinterpret<char>(); |
| 50 | |
| 51 | while (i < chars.length && 0 != chars.ptr[i]) |
| 52 | { |
| 53 | bytes += sizeof(char); |
| 54 | i++; |
| 55 | } |
| 56 | |
| 57 | if (0 == bytes) |
| 58 | { |
| 59 | return String::emptyString; |
| 60 | } |
| 61 | |
| 62 | auto backing = hx::NewGCPrivate(0, bytes + sizeof(char)); |
| 63 | |
| 64 | std::memcpy(backing, view.ptr.ptr, bytes); |
| 65 | |
| 66 | return String(static_cast<const char*>(backing), bytes / sizeof(char)); |
| 67 | } |
| 68 | |
| 69 | namespace |
| 70 | { |
nothing calls this directly
no test coverage detected