20 Eylül 2017 Çarşamba

c32rtomb

Giriş
Şu satırı dahil ederiz.
#include <uchar.h>
Verilen Unicode Code Point'i multi-byte hale getirir.

Hangi Encoding Kullanılır
Bu konu karışık. Bir açıklama şöyle
The multibyte encoding used by c32rtomb() is the multibyte encoding from the default "C" locale.
Bir başka açıklama şöyle
libc uses "C" locale by default, which uses ISO-8859-1 as the encoding. To change the encoding to which system environment specifies, usually UTF-8 but might be others, use setlocale(LC_CTYPE, "").

In Windows, VS2015+, however, c32rtomb always converts to UTF-8.
C
Örnek
Şöyle yaparız.
char buffer[4];
len = c32rtomb(buffer, L'☺', 0);
C++
Şu satırı dahil ederiz.
#include <cuchar>
Örnek
Şöyle yaparız.
std::u32string u32 = U"this is a wide string";

std::string buffer (1000, '\0');
char* ptr = &buffer[0];
std::mbstate_t state {};
for(auto u : u32) {
  ptr += std::c32rtomb(ptr, u, &state);
}
buffer.resize(ptr - &buffer[0]);

Hiç yorum yok:

Yorum Gönder