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

Method encode

src/cpp/encoding/Encodings.cpp:16–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16int64_t cpp::encoding::Ascii::encode(const String& string, View<uint8_t> buffer)
17{
18 if (null() == string)
19 {
20 hx::NullReference("String", false);
21 }
22
23 if (string.isUTF16Encoded())
24 {
25 hx::Throw(HX_CSTRING("String cannot be encoded to ASCII"));
26 }
27
28 auto src = cpp::marshal::View<char>(string.raw_ptr(), string.length).reinterpret<uint8_t>();
29
30 if (src.tryCopyTo(buffer))
31 {
32 return src.length;
33 }
34 else
35 {
36 return hx::Throw(HX_CSTRING("Buffer too small"));
37 }
38}
39
40String cpp::encoding::Ascii::decode(View<uint8_t> view)
41{

Callers

nothing calls this directly

Calls 10

NullReferenceFunction · 0.85
ThrowFunction · 0.85
tryCopyToMethod · 0.80
copyToMethod · 0.80
nullClass · 0.50
getByteCountFunction · 0.50
isEmptyMethod · 0.45
sliceMethod · 0.45
PointerMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected