string WdtUri::escape()

in WdtTransferRequest.cpp [59:76]


string WdtUri::escape(const string& binaryStr) {
  string res;
  res.reserve(binaryStr.length());  // most time nothing to escape
  for (unsigned char c : binaryStr) {
    // Allow 0-9 A-Z a-z (alphanum) and , : . _ + - (note that : is arguable)
    // (and we could use an array lookup instead of a bunch of ||s)
    if (c == ',' || c == ':' || c == '.' || c == '_' || c == '+' || c == '-' ||
        (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
        (c >= '0' && c <= '9')) {
      res.push_back(c);
    } else {
      res.push_back('%');
      res.push_back(toHex(c >> 4));
      res.push_back(toHex(c & 0xf));
    }
  }
  return res;
}