std::ctype::widen
STD::Ctype::加宽,做[医]扩宽
Defined in header | | |
---|---|---|
public: CharT widen( char c ) const; | (1) | |
public: const char* widen( const char* beg, const char* end, CharT* dst ) const; | (2) | |
protected: virtual CharT do_widen( char c ) const; | (3) | |
protected: virtual const char* do_widen( const char* beg, const char* end, CharT* dst ) const; | (4) | |
1,2%29的公共成员函数,调用受保护的虚拟成员函数。do_widen
最派生的类。
3%29转换单字节字符。c
对相应的宽字符表示使用最简单的合理变换。通常,这只适用于其多字节编码为单字节%28e.g的字符。U+0000-U+007 F在UTF-8%29。
4%29对字符数组中的每个字符[beg, end)
的字符数组中的连续位置写入相应的加宽字符。dst
...
加宽总是返回一个宽字符,但是只有编写C++程序%29所需的基本源字符集%28 latin字符、数字和标点符号才能保证具有唯一、定义良好的拓宽转换,而且还可以通过以下方式保证转换是可逆的narrow()
29%。在实践中,所有多字节表示为单个字节的字符通常都会被扩展到它们的宽字符对应项,而其他可能的单字节值通常映射到相同的占位符值,通常是。CharT(-1)
...
如果成功,拓宽将保留已知的所有字符分类类别。is()
...
参数
c | - | character to convert |
---|---|---|
dflt | - | default value to produce if the conversion fails |
beg | - | pointer to the first character in an array of characters to convert |
end | - | one past the end pointer for the array of characters to convert |
dst | - | pointer to the first element of the array of char to fill |
返回值
1,3%29增广字符
2,4%29end
例
二次
#include <locale>
#include <iostream>
void try_widen(const std::ctype<wchar_t>& f, char c)
{
wchar_t w = f.widen(c
std::cout << "The single-byte character " << +(unsigned char)c
<< " widens to " << +w << '\n';
}
int main()
{
std::locale::global(std::locale("cs_CZ.iso88592")
auto& f = std::use_facet<std::ctype<wchar_t>>(std::locale()
std::cout << std::hex << std::showbase << "In Czech ISO-8859-2 locale:\n";
try_widen(f, 'a'
try_widen(f, '\xdf' // German letter ß (U+00df) in ISO-8859-2
try_widen(f, '\xec' // Czech letter ě (U+011b) in ISO-8859-2
std::locale::global(std::locale("cs_CZ.utf8")
auto& f2 = std::use_facet<std::ctype<wchar_t>>(std::locale()
std::cout << "In Czech UTF-8 locale:\n";
try_widen(f2, 'a'
try_widen(f2, '\xdf'
try_widen(f2, '\xec'
}
二次
产出:
二次
In Czech ISO-8859-2 locale:
The single-byte character 0x61 widens to 0x61
The single-byte character 0xdf widens to 0xdf
The single-byte character 0xec widens to 0x11b
In Czech UTF-8 locale:
The single-byte character 0x61 widens to 0x61
The single-byte character 0xdf widens to 0xffffffff
The single-byte character 0xec widens to 0xffffffff
二次
另见
narrow | invokes do_narrow (public member function) |
---|---|
widen | widens characters (public member function of std::basic_ios) |
btowc | widens a single-byte narrow character to wide character, if possible (function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。