|
10 | 10 | //
|
11 | 11 |
|
12 | 12 | #include "api/Support/Radix.hpp"
|
| 13 | +#include "api/Support/Debug.hpp" |
13 | 14 | #include <algorithm>
|
14 | 15 | #include <vector>
|
15 | 16 |
|
@@ -242,5 +243,84 @@ toBaseFN(
|
242 | 243 | return llvm::StringRef(dest.data(), n);
|
243 | 244 | }
|
244 | 245 |
|
| 246 | +llvm::StringRef |
| 247 | +toBase32( |
| 248 | + std::string& dest, |
| 249 | + llvm::StringRef src) |
| 250 | +{ |
| 251 | +#if 0 |
| 252 | + std::vector<std::uint8_t> v; |
| 253 | + v.reserve(2 * ((binaryString.size() + 14) / 15)); |
| 254 | + while(binaryString.size() >= 15) |
| 255 | + { |
| 256 | + std::uint16_t u = |
| 257 | + (binaryString[ 0]-'0') * 0x0001 + |
| 258 | + (binaryString[ 1]-'0') * 0x0002 + |
| 259 | + (binaryString[ 2]-'0') * 0x0004 + |
| 260 | + (binaryString[ 3]-'0') * 0x0008 + |
| 261 | + (binaryString[ 4]-'0') * 0x0010 + |
| 262 | + (binaryString[ 5]-'0') * 0x0020 + |
| 263 | + (binaryString[ 6]-'0') * 0x0040 + |
| 264 | + (binaryString[ 7]-'0') * 0x0080 + |
| 265 | + (binaryString[ 8]-'0') * 0x0100 + |
| 266 | + (binaryString[ 9]-'0') * 0x0200 + |
| 267 | + (binaryString[10]-'0') * 0x0400 + |
| 268 | + (binaryString[11]-'0') * 0x0800 + |
| 269 | + (binaryString[12]-'0') * 0x1000 + |
| 270 | + (binaryString[13]-'0') * 0x2000 + |
| 271 | + (binaryString[14]-'0') * 0x4000; |
| 272 | + v.push_back( u & 0x00ff); |
| 273 | + v.push_back((u & 0xff00) >> 8); |
| 274 | + binaryString = binaryString.substr(15); |
| 275 | + } |
| 276 | + if(! binaryString.empty()) |
| 277 | + { |
| 278 | + char temp[15] = { |
| 279 | + '0', '0', '0', '0', '0', '0', '0', |
| 280 | + '0', '0', '0', '0', '0', '0', '0', '0' }; |
| 281 | + std::memcpy(temp, binaryString.data(), binaryString.size()); |
| 282 | + std::uint16_t u = |
| 283 | + (temp[ 0]-'0') * 0x0001 + |
| 284 | + (temp[ 1]-'0') * 0x0002 + |
| 285 | + (temp[ 2]-'0') * 0x0004 + |
| 286 | + (temp[ 3]-'0') * 0x0008 + |
| 287 | + (temp[ 4]-'0') * 0x0010 + |
| 288 | + (temp[ 5]-'0') * 0x0020 + |
| 289 | + (temp[ 6]-'0') * 0x0040 + |
| 290 | + (temp[ 7]-'0') * 0x0080 + |
| 291 | + (temp[ 8]-'0') * 0x0100 + |
| 292 | + (temp[ 9]-'0') * 0x0200 + |
| 293 | + (temp[10]-'0') * 0x0400 + |
| 294 | + (temp[11]-'0') * 0x0800 + |
| 295 | + (temp[12]-'0') * 0x1000 + |
| 296 | + (temp[13]-'0') * 0x2000 + |
| 297 | + (temp[14]-'0') * 0x4000; |
| 298 | + v.push_back( u & 0x00ff); |
| 299 | + v.push_back((u & 0xff00) >> 8); |
| 300 | + } |
| 301 | + dest.clear(); |
| 302 | + Assert((v.size() & 1) == 0); |
| 303 | + dest.reserve(3 * (v.size() / 2)); |
| 304 | + auto it = v.data(); |
| 305 | + auto const end = it + v.size(); |
| 306 | + while(it != end) |
| 307 | + { |
| 308 | + static constexpr char alphabet[33] = |
| 309 | + "012345abcdefghijklmnopqrstuvwxyz"; |
| 310 | + std::uint16_t t = 256 * it[1] + it[0]; |
| 311 | + dest.push_back(alphabet[(t & 0x001f)]); |
| 312 | + dest.push_back(alphabet[(t & 0x03e0) >> 5]); |
| 313 | + dest.push_back(alphabet[(t & 0x7c00) >> 10]); |
| 314 | + it += 2; |
| 315 | + } |
| 316 | + while(! dest.empty()) |
| 317 | + if(dest.back() == '0') |
| 318 | + dest.pop_back(); |
| 319 | + else |
| 320 | + break; |
| 321 | +#endif |
| 322 | + return dest; |
| 323 | +} |
| 324 | + |
245 | 325 | } // mrdox
|
246 | 326 | } // clang
|
0 commit comments