MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / hexToVec4B

Method hexToVec4B

source/core/StarColor.cpp:612–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612Vec4B Color::hexToVec4B(StringView s) {
613 Array<uint8_t, 4> cbytes;
614
615 if (s.utf8Size() == 3) {
616 nibbleDecode(s.utf8Ptr(), 3, (char*)cbytes.data(), 4);
617 cbytes[0] = (cbytes[0] << 4) | cbytes[0];
618 cbytes[1] = (cbytes[1] << 4) | cbytes[1];
619 cbytes[2] = (cbytes[2] << 4) | cbytes[2];
620 cbytes[3] = 255;
621 } else if (s.utf8Size() == 4) {
622 nibbleDecode(s.utf8Ptr(), 4, (char*)cbytes.data(), 4);
623 cbytes[0] = (cbytes[0] << 4) | cbytes[0];
624 cbytes[1] = (cbytes[1] << 4) | cbytes[1];
625 cbytes[2] = (cbytes[2] << 4) | cbytes[2];
626 cbytes[3] = (cbytes[3] << 4) | cbytes[3];
627 } else if (s.utf8Size() == 6) {
628 hexDecode(s.utf8Ptr(), 6, (char*)cbytes.data(), 4);
629 cbytes[3] = 255;
630 } else if (s.utf8Size() == 8) {
631 hexDecode(s.utf8Ptr(), 8, (char*)cbytes.data(), 4);
632 } else {
633 throw ColorException(strf("Improper size {} for hex string '{}' in Color::hexToVec4B", s.utf8Size(), s), false);
634 }
635
636 return Vec4B(std::move(cbytes));
637}
638
639}

Callers

nothing calls this directly

Calls 6

nibbleDecodeFunction · 0.85
hexDecodeFunction · 0.85
strfFunction · 0.85
utf8SizeMethod · 0.45
utf8PtrMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected