Japanese half / full width conversion

I ran into the problem of character width in Japanese using glib :: ustring.

I have this line: ウ γ‚§ ッ γ‚Έ パ ン γƒ— γ‚Ή

I want to convert it to: ウ エ ッ γ‚· パ ン γƒ— γ‚Ή

Using ustring :: normalize, I get this line: ウ γ‚§ ッ γ‚Έ パ ン γƒ— γ‚Ή (in fact, each character with an accent fills the width of two characters)

Is there a standard method for handling this kind? Is OIT more effective?

I need to convert Japanese strings to one of two formats because a half-width string is different from the same width.

+3
source share
1 answer

LCMapString, / hiragana/katakana

AnsiString text = "ε€‰ζ›γ™γ‚‹ζ–‡ε­—εˆ—"; //input text
//倉換方法 how to convert
DWORD flags = LCMAP_FULLWIDTH; //全角文字にします。flag to convert to full width
//DWORD flags = LCMAP_HALFWIDTH; //εŠθ§’ζ–‡ε­—γ«γ—γΎγ™οΌ‰γ€‚to half width
//DWORD flags = LCMAP_HIRAGANA; //γ²γ‚‰γŒγͺにします。to hiragana
//DWORD flags = LCMAP_KATAKANA; //γ‚«γ‚Ώγ‚«γƒŠγ«γ—γΎγ™γ€‚to katakana
const int size = text.Length() * 2 + 1;
char* s = new char[size];
try
{
  ZeroMemory(s, size);
  LCMapString(GetUserDefaultLCID(),
              flags,
              text.c_str(),
              text.Length() + 1,
              s,
              size);
  AnsiString newtext = s; //ε€‰ζ›γ—γŸζ–‡ε­—εˆ— converted text
  return newtext;
}

+1

Source: https://habr.com/ru/post/1754211/


All Articles