widechar

How multibyte string is converted to wide-character string in fxprintf.c in glibc?

て烟熏妆下的殇ゞ 提交于 2020-02-05 05:12:46
问题 Currently, the logic in glibc source of perror is such: If stderr is oriented, use it as is, else dup() it and use perror() on dup() 'ed fd . If stderr is wide-oriented, the following logic from stdio-common/fxprintf.c is used: size_t len = strlen (fmt) + 1; wchar_t wfmt[len]; for (size_t i = 0; i < len; ++i) { assert (isascii (fmt[i])); wfmt[i] = fmt[i]; } res = __vfwprintf (fp, wfmt, ap); The format string is converted to wide-character form by the following code, which I do not understand:

How to make std::wofstream write UTF-8?

▼魔方 西西 提交于 2020-01-14 04:25:44
问题 I am redirecting std::wclog to a file for logging in my program: std::wclog.rdbuf((new std::wofstream("C:\\path\\to\\file.log", std::ios::app))->rdbuf()); Logging happens by writing to std::wclog : std::wclog << "Schöne Grüße!" << std::endl; Surprisingly I found that the file is being written in ANSI. (This would be totally acceptable for ofstream and clog , but I had expected wofstream and wclog to produce some kind of unicode output.) I want to be able to log in CYK langugages as well (e.g.

fwprintf omits wide chars

Deadly 提交于 2020-01-04 05:49:10
问题 I'm trying to create wide chars file using MinGW C on Windows, however wide chars seem to be omitted. My code: const wchar_t* str = L"příšerně žluťoučký kůň úpěl ďábelské ódy"; FILE* fd = fopen("file.txt","w"); // FILE* fd = _wfopen(L"demo.txgs",L"w"); // attempt to open wide file doesn't help fwide(fd,1); // attempt to force wide mode, doesn't help fwprintf(fd,L"%ls",str); // fputws(p,fd); // stops output after writing "p" (1B file size) fclose(fd); File contents píern luouký k úpl ábelské

May wchar_t be promoted to wint_t?

孤者浪人 提交于 2020-01-04 02:18:25
问题 I see one contradiction of glibc reference and Amendment 1 to C90. The quote from glibc reference says that wchar_t may be promoted to wint_t: if wchar_t is defined as char the type wint_t must be defined as int due to the parameter promotion But AMD1 says this: Currently, an existing implementation could have wchar_t be int and wint_t be long, and default promotions would not change int to long. Basically, this is due to wchar_t and wint_t being typedefs. Hence, we will not now have wchar_t

fgetws fails to get the exact wide char string from FILE*

て烟熏妆下的殇ゞ 提交于 2019-12-25 03:01:12
问题 I am using fgetws to get some string line by line from a FILE. The FILE I have is from a popen command. Here is the code snippet: FILE* pInstalledApps = popen( command.c_str(), "r" ); if( NULL != pInstalledApps ) { wchar_t currentAppPath [kMaximumAppPathLength]; // Reading app paths one line at a time. while ( ! feof (pInstalledApps) ) { if ( fgetws ( currentAppPath, kMaximumAppPathLength, pInstalledApps) == NULL ) { break; } wchar_t *pCharPos = NULL; if ( ( pCharPos = wcschr( currentAppPath,

Why there are no “unsigned wchar_t” and “signed wchar_t” types?

拥有回忆 提交于 2019-12-23 12:44:08
问题 The signedness of char is not standardized. Hence there are signed char and unsigned char types. Therefore functions which work with single character must use the argument type which can hold both signed char and unsigned char (this type was chosen to be int ), because if the argument type was char , we would get type conversion warnings from the compiler (if -Wconversion is used) in code like this: char c = 'ÿ'; if (islower((unsigned char) c)) ... warning: conversion to ‘char’ from ‘unsigned

Why there are no “unsigned wchar_t” and “signed wchar_t” types?

。_饼干妹妹 提交于 2019-12-23 12:39:32
问题 The signedness of char is not standardized. Hence there are signed char and unsigned char types. Therefore functions which work with single character must use the argument type which can hold both signed char and unsigned char (this type was chosen to be int ), because if the argument type was char , we would get type conversion warnings from the compiler (if -Wconversion is used) in code like this: char c = 'ÿ'; if (islower((unsigned char) c)) ... warning: conversion to ‘char’ from ‘unsigned

Displaying wide chars with printf

♀尐吖头ヾ 提交于 2019-12-22 05:09:23
问题 I'm trying to understand how does printf work with wide characters ( wchar_t ). I've made the following code samples : Sample 1 : #include <stdio.h> #include <stdlib.h> int main(void) { wchar_t *s; s = (wchar_t *)malloc(sizeof(wchar_t) * 2); s[0] = 42; s[1] = 0; printf("%ls\n", s); free(s); return (0); } output : * Everything is fine here : my character ( * ) is correctly displayed. Sample 2 : I wanted to display an other kind of character. On my system, wchar_t seem encoded on 4 bytes. So I

iostreams - Print `wchar_t` or `charXX_t` value as a character

丶灬走出姿态 提交于 2019-12-13 13:05:33
问题 If you feed a wchar_t , char16_t , or char32_t value to a narrow ostream, it will print the numeric value of the code point. #include <iostream> using std::cout; int main() { cout << 'x' << L'x' << u'x' << U'x' << '\n'; } prints x120120120 . This is because there is an operator<< for the specific combination of basic_ostream with its charT , but there aren't analogous operators for the other character types, so they get silently converted to int and printed that way. Similarly, non-narrow

Convert Char into AnsiChar or WideChar (Delphi)

孤街浪徒 提交于 2019-12-12 18:09:45
问题 I'm upgrading a very old (10+ years) application to the latest Delphi XE. There are a number of errors I keep getting like Incompatible types: 'WideChar' and 'AnsiChar' I have been just casting the char to the right type: ex. AWideChar = WideChar(fncReturnsChar); Is this going to cause problems? 回答1: There might be problems in there for you. Here is a white paper on Unicode in Delphi by Marco Cantù. http://edn.embarcadero.com/article/38980 回答2: var Initials: String[10]; FullName: String;