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
。2) 將字元序列
[
low,
high)
轉換為一個字串,該字串與另一個字串呼叫 transform()
的結果進行字典比較(例如,使用字串的 operator<
),產生與對這兩個相同字串呼叫 do_compare() 相同的結果。目錄 |
[編輯] 引數
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 << "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
[編輯] 另請參閱
轉換字串,使 strcmp 產生與 strcoll 相同的結果(函式) | |
轉換寬字串,使 wcscmp 產生與 wcscoll 相同的結果(函式) |