MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / decode

Method decode

src/cpp/encoding/Encodings.cpp:40–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40String 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
69namespace
70{

Callers

nothing calls this directly

Calls 11

ThrowFunction · 0.85
NewGCPrivateFunction · 0.85
memcpyFunction · 0.85
isAsciiUtf8BufferFunction · 0.85
InternalNewFunction · 0.85
InternalReallocFunction · 0.85
toAsciiStringFunction · 0.85
StringClass · 0.50
getByteCountFunction · 0.50
isEmptyMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected