在线文档教程
C++
本土化 | Localizations

do_transform

整理::转换,做[医]变换

Defined in header
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%29公共成员函数,调用受保护的虚拟成员函数do_transform最派生的类。

2%29转换字符序列[low, high)与字符串进行比较,按字典顺序计算为%28例如。带着operator<对于字符串%29和调用的结果transform()在另一个字符串上,产生与调用do_compare()在同样的两条线上。

参数

low-pointer to the first character in the sequence to transform
high-one past the end pointer for the sequence to transform

返回值

该字符串被转换,使转换后的字符串的字典比较可以被使用,而不是对原始字符串进行校对。在“C”区域设置中,返回的字符串是[low, high)在其他语言环境中,返回的字符串的内容是实现定义的,大小可能要长得多。

注记

除了在排序规则中使用之外,转换后的字符串的特定实现格式还可以在STD::regex[医]性状<>:转换[医]初等,它能够提取等价类信息。

二次

#include <iostream> #include <iomanip> #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 << "In the Swedish locale: "; if(out1 < out2) std::wcout << in1 << " before " << in2 << '\n'; else std::wcout << in2 << " before " << in1 << '\n'; std::wcout << "In lexicographic comparison: "; if(in1 < in2) std::wcout << in1 << " before " << in2 << '\n'; else std::wcout << in2 << " before " << in1 << '\n'; }

二次

产出:

二次

In the Swedish locale: år before ängel In lexicographic comparison: ängel before år

二次

另见

strxfrmtransform a string so that strcmp would produce the same result as strcoll (function)
wcsxfrmtransform a wide string so that wcscmp would produce the same result as wcscoll (function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/locale/COLATE/Transform