Facebook
From aaaaaaaaa, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 161
  1. std::string decodeUnicodeEscapeSequences(const std::string& input) {
  2.     std::regex pattern("\\\\u([0-9A-Fa-f]{4})");
  3.     std::string output;
  4.     std::smatch match;
  5.  
  6.     auto pos = input.cbegin();
  7.     while (std::regex_search(pos, input.cend(), match, pattern)) {
  8.         output += match.prefix().str();
  9.         auto codepoint = std::stoi(match[1], nullptr, 16);
  10.         output += static_cast<char>((codepoint >> 12) | 0xE0);
  11.         output += static_cast<char>(((codepoint >> 6) & 0x3F) | 0x80);
  12.         output += static_cast<char>((codepoint & 0x3F) | 0x80);
  13.         pos = match.suffix().first;
  14.     }
  15.     output += std::string(pos, input.cend());
  16.     return output;
  17. }