In place replacement std :: string / std :: wstring?

Continued in C ++ and UTF8 - Why not just replace ASCII?

Why is there no std::ustring that can replace as std::string , std::wstring in new applications?

Of course, with appropriate support in the standard library. Similar to how boost::filesystem3::path does not care about the string representation and works with both std::string and std::wstring .

+4
source share
2 answers

Why do you need to replace something?

string and wstring are string classes corresponding to char and wchar_t , which, in the context of interacting with the environment, are designed to transfer data encoded, respectively, with a "narrow multi-byte representation of the system" and a fixed width in "system encoding".

On the other hand, u8 / u / u , as well as char16_t and char32_t , as well as the corresponding string classes, are intended for storing Unicode code sequences encoded in UTF-8/16/32.

The latter is a separate problem area from the former. The standard does not contain a mechanism for combining two domains (and usually requires a library such as iconv() to make this bridge portable, for example, by recoding WCHAR_T / UTF-32).

Here is my standard list of related questions: # 1 , # 2 , # 3

+4
source

There std::u16string and std::u32string . Standard libraries in which you might want to use them, for example. to name the file to be opened with fstream will not be changed to use them, because they really cannot. For example, some platforms take an almost arbitrary byte string to name the file to open, without a specific encoding. The need to run this through a string with a specific encoding could break the job and be incompatible.

+2
source

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


All Articles