widechar

How to avoid integer promotion in C?

冷暖自知 提交于 2019-12-12 06:52:39
问题 It is not clear how to write portable code in C, using wide-character API. Consider this example: #include <locale.h> #include <wchar.h> #include <wctype.h> int main(void) { setlocale(LC_CTYPE, "C.UTF-8"); wchar_t wc = L'ÿ'; if (iswlower(wc)) return 0; return 1; } Compiling it with gcc-6.3.0 using -Wconversion option gives this warning: test.c: In function 'main': test.c:9:16: warning: conversion to 'wint_t {aka unsigned int}' from 'wchar_t {aka int}' may change the sign of the result [-Wsign

Using Wide Character Constants with clang Gets “extraneous characters in wide character constant ignored” Error

瘦欲@ 提交于 2019-12-12 04:28:55
问题 I recently decided to switch to clang from gcc and I’m getting the following warning for my use of wide character constants: "extraneous characters in wide character constant ignored" . Here is the code that gets the warning: wstring& line; … for (wstring::iterator ch = line.begin(); ch != line.end(); ++ch) switch (*ch) { case L'│': *ch = L'|'; break; case L'﹤': *ch = L'<'; break; case L'﹥': *ch = L'>'; break; case L'﹙': *ch = L'('; break; case L'﹚': *ch = L')'; break; default: break; } Here,

What is the largest code point for 16-bit wchar_t type?

泄露秘密 提交于 2019-12-12 03:06:06
问题 It is said here that UTF-16's largest code point is 10FFFF Also it is written on that page that BMP characters require one 16-bit code unit to process or store. But in bit representation 10FFFF is 0001 0000 1111 1111 1111 1111 We see that it occupies more than 15 bits of 16-bit wchar_t (an implementation is allowed to support wide characters with >=0 value only, independently of signedness of wchar_t ) What is the real largest code point for 16-bit wchar_t ? 回答1: It is said here that UTF-16's

How to convert java strings to wide character strings using JNI

随声附和 提交于 2019-12-11 17:44:45
问题 Several months ago, I wrote a Java API that use JNI to wrap around a C API. The C API used char strings and I used GetStringUTFChars to create the C strings from the Java Strings. I neglected to think through the problems that might arise with non-ASCII characters. Since then the creator of the C API has created wide character equivalents to each of his C functions that require or return wchar_t strings. I would like to update my Java API to use these wide character functions and overcome the

Guarantee on size ordering on char, wchar_t, char16_t, char32_t

一笑奈何 提交于 2019-12-10 18:05:38
问题 Does the C++ standard provide any guarantee on the ordering of the size in bytes of char , wchar_t , char16_t , char32_t ? (any extract from the standard is welcome) For example do I have the guarantee that: sizeof(char) <= sizeof(wchar_t) <= sizeof(char16_t) <= sizeof(char32_t) 回答1: It's 1 == sizeof(char) <= sizeof(wchar_t) and 1 == sizeof(char) <= sizeof(char16_t) <= sizeof(char32_t) . 5.3.3/1 Sizeof [expr.sizeof] ... sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1. ... [

Converting C++ std::wstring to utf8 with std::codecvt_xxx

≯℡__Kan透↙ 提交于 2019-12-07 11:07:25
问题 C++11 has tools to convert wide char strings std::wstring from/to utf8 representation: std::codecvt , std::codecvt_utf8 , std::codecvt_utf8_utf16 etc. Which one is usable by Windows app to convert regular wide char Windows strings std::wstring to utf8 std::string ? Is it always works without configuring locales? 回答1: Depends how you convert them. You need to specify the source encoding type and the target encoding type. wstring is not a format, it just defines a data type. Now usually when

What is the difference between Ansichar and char? [duplicate]

随声附和 提交于 2019-12-04 07:11:11
问题 This question already has answers here : What is the difference between WideChar and AnsiChar? (2 answers) Closed 5 years ago . I recently ran into this data type mismatch. This is I never saw before. I hope someone could explain what these are and how are they different. Error I got was F2063. [DCC Error] E2010 Incompatible types: 'AnsiChar' and 'Char' 回答1: Historically in Delphi, the Char type was effectively a synonym for the ANSIChar type. That is, a single byte representing a character

What is the difference between Ansichar and char? [duplicate]

ε祈祈猫儿з 提交于 2019-12-02 13:38:51
This question already has an answer here: What is the difference between WideChar and AnsiChar? 2 answers I recently ran into this data type mismatch. This is I never saw before. I hope someone could explain what these are and how are they different. Error I got was F2063. [DCC Error] E2010 Incompatible types: 'AnsiChar' and 'Char' Historically in Delphi, the Char type was effectively a synonym for the ANSIChar type. That is, a single byte representing a character from an ANSI codepage. NOTE: This is a simplification that ignores the complications arising from multibyte characters which could

_T( ) macro changes for UNICODE character data

梦想的初衷 提交于 2019-12-01 04:58:06
I have UNICODE application where in we use _T(x) which is defined as follows. #if defined(_UNICODE) #define _T(x) L ##x #else #define _T(x) x #endif I understand that L gets defined to wchar_t, which will be 4 bytes on any platform. Please correct me if I am wrong. My requirement is that I need L to be 2 bytes. So as compiler hack I started using -fshort-wchar gcc flag. But now I need my application to be moved to zSeries where I don't get to see the effect of -fshort-wchar flag in that platform. In order for me to be able to port my application on zSeries, I need to modify _T( ) macro in such

_T( ) macro changes for UNICODE character data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 02:07:45
问题 I have UNICODE application where in we use _T(x) which is defined as follows. #if defined(_UNICODE) #define _T(x) L ##x #else #define _T(x) x #endif I understand that L gets defined to wchar_t, which will be 4 bytes on any platform. Please correct me if I am wrong. My requirement is that I need L to be 2 bytes. So as compiler hack I started using -fshort-wchar gcc flag. But now I need my application to be moved to zSeries where I don't get to see the effect of -fshort-wchar flag in that