Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save t-mat/9071ac1c5dfde7a785ad to your computer and use it in GitHub Desktop.
Save t-mat/9071ac1c5dfde7a785ad to your computer and use it in GitHub Desktop.
Win32 : Katakana to Hiragana conversion by LCMapStringEx()
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <wtypes.h>
#include <vector>
#include <string>
#include <iostream>
std::wstring katakanaToHiragana(const std::wstring& str) {
const auto* s = str.c_str();
const auto l = str.size();
const int requestBufLen = LCMapStringEx(
LOCALE_NAME_USER_DEFAULT
, LCMAP_HIRAGANA
, s
, l
, nullptr
, 0
, nullptr
, nullptr
, 0
);
std::vector<wchar_t> buf(requestBufLen);
const int result = LCMapStringEx(
LOCALE_NAME_USER_DEFAULT
, LCMAP_HIRAGANA
, s
, l
, buf.data()
, buf.size()
, nullptr
, nullptr
, 0
);
return buf.data();
}
int main() {
_tsetlocale(LC_ALL, _T(""));
const std::wstring katakana = L"アカサタナ";
const auto hiragana = katakanaToHiragana(katakana);
std::wcout << katakana << std::endl;
std::wcout << hiragana << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment