MCPcopy Create free account
hub / github.com/TASEmulators/fceux / DecData

Function DecData

src/utils/xstring.cpp:709–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707 }
708
709 unsigned DecData(const std::string& input, size_t& pos)
710 {
711 unsigned char headbyte = input[pos];
712 static const char sizes[16] = { 1,1,1,1,1,1,1,1, 0,0,0,0,2,2,3,4 };
713 static const unsigned minimums[4] = { 0, 0x80, 0x800, 0x10000 };
714 static const char masks[4] = { 0x7F, 0x1F, 0x0F, 0x07 };
715 unsigned len = sizes[headbyte >> 4];
716 if(len < 1 || pos+len > input.size()) { ++pos; return '?'; }
717 unsigned result=0, shl=0;
718 for(unsigned n = len; --n > 0; shl += 6)
719 {
720 unsigned char byte = input[pos+n];
721 if((byte & 0xC0) != 0x80) { ++pos; return '?'; }
722 result |= (byte & 0x3F) << shl;
723 }
724 result |= (headbyte & masks[len-1]) << shl;
725 if(result < minimums[len-1]) { ++pos; return '?'; }
726 pos += len;
727 return result;
728 }
729
730
731 std::wstring FromUtf8(std::string& input) // string -> wstring

Callers 1

FromUtf8Function · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected