Facebook
From aaaaaaaaa, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 158
  1. std::string result;
  2.     auto iter = std::sregex_iterator(input.begin(), input.end(), pattern);
  3.     auto end = std::sregex_iterator();
  4.     size_t lastPos = 0;
  5.  
  6.     for (; iter != end; ++iter) {
  7.         const std::smatch& match = *iter;
  8.         result.append(input, lastPos, match.position() - lastPos);
  9.  
  10.         // Convert hexadecimal codepoint to integer
  11.         int codepoint = std::stoi(match[1].str(), nullptr, 16);
  12.  
  13.         // Append the Unicode character to the result string
  14.         result.push_back(static_cast<char>(codepoint));
  15.  
  16.         // Update last position
  17.         lastPos = match.position() + match.length();
  18.     }
  19.  
  20.     // Append the rest of the input string
  21.     result.append(input, lastPos, input.length() - lastPos);
  22.  
  23.     return result;