std::collate<CharT>::transform, do_transform
来自cppreference.com
在标头 <locale> 定义
|
||
public: string_type transform( const CharT* low, const CharT* high ) const; |
(1) | |
protected: virtual string_type do_transform( const CharT* low, const CharT* high ) const; |
(2) | |
1) 公开成员函数,调用最终派生类的受保护虚成员函数
do_transform
。参数
low | - | 指向要变换的字符序列中首字符的指针 |
high | - | 要变换的序列的尾后一位置指针 |
返回值
变换后的字符串,它使得被变换字符串的字典序比较能用于取代对原字符串的校排。"C" 本地环境中,返回的字符串为 [
low,
high)
的准确副本。其他本地环境中,返回字符串的内容是实现定义的,而且可考虑到大小可能更长。
注解
除了在校排中使用外,本地环境特定的变换字符串格式还为 std::regex_traits::transform_primary 所知,它能够提取等价类信息。
示例
运行此代码
#include <iomanip> #include <iostream> #include <locale> int main() { std::locale::global(std::locale("sv_SE.utf8")); auto& f = std::use_facet<std::collate<wchar_t>>(std::locale()); std::wstring in1 = L"\u00e4ngel"; std::wstring in2 = L"\u00e5r"; std::wstring out1 = f.transform(&in1[0], &in1[0] + in1.size()); std::wstring out2 = f.transform(&in2[0], &in2[0] + in2.size()); std::wcout << "瑞典本地环境中: "; if (out1 < out2) std::wcout << in1 << " 先于 " << in2 << '\n'; else std::wcout << in2 << " 先于 " << in1 << '\n'; std::wcout << "字典序比较: "; if (in1 < in2) std::wcout << in1 << " 先于 " << in2 << '\n'; else std::wcout << in2 << " 先于 " << in1 << '\n'; }
输出:
瑞典本地环境中: år 先于 ängel 字典序比较: ängel 先于 år
参阅
变换字符串,使得 strcmp 会返回与 strcoll 相同的结果 (函数) | |
变换宽字符串,使得 wcscmp 会产生与 wsccoll 相同的结果 (函数) |