Facebook
From aaaa, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 154
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5. std::string unescapeUnicode(const std::string& input) {
  6.     // Regular expression pattern to match Unicode escape sequences
  7.     std::regex pattern("\\\\u([0-9A-Fa-f]{4})");
  8.  
  9.     // Function to replace each Unicode escape sequence with its corresponding character
  10.     auto replaceUnicode = [&](const std::smatch& match) -> std::string {
  11.         int codepoint = std::stoi(match[1].str(), nullptr, 16);
  12.         return std::string(1, static_cast<char>(codepoint));
  13.     };
  14.  
  15.     // Use std::regex_replace to replace all occurrences of Unicode escape sequences
  16.     return std::regex_replace(input, pattern, replaceUnicode);
  17. }
  18.