Skip to content

Instantly share code, notes, and snippets.

@mortehu
Last active September 22, 2016 00:22
Show Gist options
  • Save mortehu/48eceafeb6cff05002759e9434f887c4 to your computer and use it in GitHub Desktop.
Save mortehu/48eceafeb6cff05002759e9434f887c4 to your computer and use it in GitHub Desktop.
UTF-8 case folding in C++14
#include <codecvt>
#include <iomanip>
#include <iostream>
#include <locale>
#include <string>
#include "zip.h" // See https://gist.github.com/mortehu/373069390c75b02f98b655e3f7dbef9a
const auto low = u8"abcæøåαβγ";
const auto upp = u8"ABCÆØÅΑΒΓ";
int main(int argc, char** argv) {
const std::locale locale("en_US.UTF-8");
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> ucs2conv;
auto low_ucs = ucs2conv.from_bytes(low);
auto upp_ucs = ucs2conv.from_bytes(upp);
for (auto&& g : zip(low_ucs, upp_ucs))
{
std::cerr << std::setw(3) << std::tolower(std::get<0>(g), locale) << ' '
<< std::tolower(std::get<1>(g), locale) << '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment