MCPcopy Create free account
hub / github.com/CLIUtils/CLI11 / string extract_binary_string

Method string extract_binary_string

include/CLI/impl/StringTools_inl.hpp:484–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482}
483
484CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string) {
485 std::size_t start{0};
486 std::size_t tail{0};
487 size_t ssize = escaped_string.size();
488 if(escaped_string.compare(0, 3, "B\"(") == 0 && escaped_string.compare(ssize - 2, 2, ")\"") == 0) {
489 start = 3;
490 tail = 2;
491 } else if(escaped_string.compare(0, 4, "'B\"(") == 0 && escaped_string.compare(ssize - 3, 3, ")\"'") == 0) {
492 start = 4;
493 tail = 3;
494 }
495
496 if(start == 0) {
497 return escaped_string;
498 }
499 std::string outstring;
500
501 outstring.reserve(ssize - start - tail);
502 std::size_t loc = start;
503 while(loc < ssize - tail) {
504 // ssize-2 to skip )" at the end
505 if(escaped_string[loc] == '\\' && (escaped_string[loc + 1] == 'x' || escaped_string[loc + 1] == 'X')) {
506 auto c1 = escaped_string[loc + 2];
507 auto c2 = escaped_string[loc + 3];
508
509 std::uint32_t res1 = hexConvert(c1);
510 std::uint32_t res2 = hexConvert(c2);
511 if(res1 <= 0x0F && res2 <= 0x0F) {
512 loc += 4;
513 outstring.push_back(static_cast<char>(res1 * 16 + res2));
514 continue;
515 }
516 }
517 outstring.push_back(escaped_string[loc]);
518 ++loc;
519 }
520 return outstring;
521}
522
523CLI11_INLINE void remove_quotes(std::vector<std::string> &args) {
524 for(auto &arg : args) {

Callers

nothing calls this directly

Calls 1

compareMethod · 0.80

Tested by

no test coverage detected