Facebook
From aaaaa, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 154
  1. std::string MyConversion(const std::string& sSrc) {
  2.     std::string result;
  3.     size_t nSize = sSrc.size();
  4.     size_t i = 0;
  5.     while (i < nSize) {
  6.         if ('\\' == sSrc[i] && 'u' == sSrc[i + 1]) {
  7.             // This assumes that all hex codes consist of four characters
  8.             char cSave = sSrc[i + 6];
  9.             sSrc[i + 6] = 0;
  10.             result += static_cast<char>(std::strtoul(sSrc.substr(i + 2, 4).c_str(), NULL, 16));
  11.             i += 6;
  12.             sSrc[i] = cSave;
  13.         } else
  14.             result += sSrc[i];
  15.         ++i;
  16.     }
  17.     return result;
  18. }