Created
February 19, 2015 05:02
-
-
Save t-mat/9071ac1c5dfde7a785ad to your computer and use it in GitHub Desktop.
Win32 : Katakana to Hiragana conversion by LCMapStringEx()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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