MCPcopy Create free account
hub / github.com/Kitware/CMake / encodeString

Method encodeString

Source/cmBase32.cxx:39–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37cmBase32Encoder::cmBase32Encoder() = default;
38
39std::string cmBase32Encoder::encodeString(unsigned char const* input,
40 size_t len, bool padding)
41{
42 std::string res;
43
44 static size_t const blockSize = 5;
45 static size_t const bufferSize = 8;
46 char buffer[bufferSize];
47
48 unsigned char const* end = input + len;
49 while ((input + blockSize) <= end) {
50 Base32Encode5(input, buffer);
51 res.append(buffer, bufferSize);
52 input += blockSize;
53 }
54
55 size_t remain = static_cast<size_t>(end - input);
56 if (remain != 0) {
57 // Temporary source buffer filled up with 0s
58 unsigned char padded[blockSize];
59 for (size_t ii = 0; ii != remain; ++ii) {
60 padded[ii] = input[ii];
61 }
62 for (size_t ii = remain; ii != blockSize; ++ii) {
63 padded[ii] = 0;
64 }
65
66 Base32Encode5(padded, buffer);
67 size_t numPad(0);
68 switch (remain) {
69 case 1:
70 numPad = 6;
71 break;
72 case 2:
73 numPad = 4;
74 break;
75 case 3:
76 numPad = 3;
77 break;
78 case 4:
79 numPad = 1;
80 break;
81 default:
82 break;
83 }
84 res.append(buffer, bufferSize - numPad);
85 if (padding) {
86 for (size_t ii = 0; ii != numPad; ++ii) {
87 res.push_back(paddingChar);
88 }
89 }
90 }
91
92 return res;
93}

Callers 1

getMethod · 0.80

Calls 3

Base32Encode5Function · 0.85
appendMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected