Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Japanese half/full width conversion

Tags:

c++

c

glib

I'm facing a character width problem in Japanese using glib::ustring.

I have this string: ウェッジパンプス

I want to convert it to: ウエッシパンプス

Using ustring::normalize, i get this string: ウェッジパンプス (in fact, here, each character with accent fills two characters width)

Is there a standard method to do this kind of processing? Is ICU better at doing this?

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


1 Answers

There is LCMapString that can do conversion between half/full width 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;
}

ref:

  • http://www.gesource.jp/programming/bcb/39.html
like image 114
YOU Avatar answered Aug 02 '26 01:08

YOU



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!