C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- std::locale
- std::use_facet
- std::has_facet
- std::isspace(std::locale)
- std::isblank(std::locale)
- std::codecvt
- std::wstring_convert
- std::iscntrl(std::locale)
- std::isupper(std::locale)
- std::islower(std::locale)
- std::isalpha(std::locale)
- std::isdigit(std::locale)
- std::ispunct(std::locale)
- std::isxdigit(std::locale)
- std::isalnum(std::locale)
- std::isprint(std::locale)
- std::isgraph(std::locale)
- std::toupper(std::locale)
- std::tolower(std::locale)
- std::wbuffer_convert
- std::ctype_base
- std::codecvt_base
- std::messages_base
- std::time_base
- std::money_base
- std::ctype
- std::ctype<char>
- std::collate
- std::messages
- std::time_get
- std::time_put
- std::num_get
- std::num_put
- std::numpunct
- std::money_get
- std::money_put
- std::moneypunct
- std::ctype_byname
- std::codecvt_byname
- std::messages_byname
- std::collate_byname
- std::time_get_byname
- std::time_put_byname
- std::numpunct_byname
- std::moneypunct_byname
- std::codecvt_utf8
- std::codecvt_utf16
- std::codecvt_utf8_utf16
- std::codecvt_mode
- std::setlocale
- std::localeconv
- std::lconv
- LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME
- 注é
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >æ¬å°ååº > std::collate
std::collate
| å®ä¹äºå¤´æä»¶ <locale>
|
||
| template< class CharT > class collate; |
||
ç±» std::collate å°è£ åç¬¦ä¸²çæ¬å°ç¯å¢éå®å¯¹ç §ï¼æ¯è¾ï¼ååå¸ãæ¤å¹³é¢ä¸º std::basic_regex æç¨ï¼å¹¶è½ä»¥ std::locale::operator() ç´æ¥åºç¨å°æææå¾ string æ¯è¾è°è¯çæ åç®æ³ã
ç»§æ¿å¾
æ ååºæä¾äºä¸ªå¤ç«ï¼ä¸ä¾èµæ¬å°ç¯å¢ï¼çç¹åï¼
| å®ä¹äºå¤´æä»¶
<locale> | |
| std::collate<char> | å®ç°åèå符串çåå ¸åºå®åº |
| std::collate<wchar_t> | å®ç°å®½å符串çåå ¸åºå®åº |
å¦å¤ï¼ C++ ç¨åºä¸æé çæ¯ä¸ª locale 对象é½å®è£ è¿äºç¹åçå ¶èªèº«ï¼æ¬å°ç¯å¢éå®ï¼çæ¬ã
æåç±»å
| Â | |
| æåç±»å | å®ä¹ |
char_type
|
CharT
|
string_type
|
std::basic_string<CharT>
|
æå彿°
| æé æ°ç collate å¹³é¢ (å ¬å¼æå彿°) | |
| 鿝 collate å¹³é¢ (åä¿æ¤æå彿°) | |
è°ç¨ do_compare (å ¬å¼æå彿°) | |
è°ç¨ do_transform (å ¬å¼æå彿°) | |
è°ç¨ do_hash (å ¬å¼æå彿°) |
æå对象
| static std::locale::id id |
locale ç id (å ¬å¼æå对象) |
åä¿æ¤æå彿°
| [è] |
ç¨æ¤å¹³é¢ç对ç
§è§åæ¯è¾äºä¸ªå符串 (èåä¿æ¤æå彿°) |
| [è] |
忢å符串ï¼ä½¿å¾è½ç¨æ¯è¾æ¿æ¢å¯¹ç
§ (èåä¿æ¤æå彿°) |
| [è] |
çæä½¿ç¨æ¤å¹³é¢å¯¹ç
§è§åçæ´æ°åå¸å¼ (èåä¿æ¤æå彿°) |
示ä¾
è¿è¡æ¤ä»£ç
#include <locale> #include <iostream> #include <string> #include <vector> #include <algorithm> Â int main() { std::wcout.imbue(std::locale("")); std::vector<std::wstring> v = {L"ar", L"zebra", L"\u00f6grupp", L"Zebra", L"\u00e4ngel", L"\u00e5r", L"f\u00f6rnamn"}; Â std::wcout << "Default locale collation order: "; std::sort(v.begin(), v.end()); for (auto s : v) std::wcout << s << ' '; std::wcout << '\n'; Â std::wcout << "English locale collation order: "; std::sort(v.begin(), v.end(), std::locale("en_US.UTF-8")); for (auto s : v) std::wcout << s << ' '; std::wcout << '\n'; Â std::wcout << "Swedish locale collation order: "; std::sort(v.begin(), v.end(), std::locale("sv_SE.UTF-8")); for (auto s : v) std::wcout << s << ' '; std::wcout << '\n'; }
è¾åºï¼
Default locale collation order: Zebra ar förnamn zebra ängel år ögrupp English locale collation order: ängel ar år förnamn ögrupp zebra Zebra Swedish locale collation order: ar förnamn zebra Zebra år ängel ögrupp
åé
| ç¨æ¤ locale ç collate å»é¢ä»¥åå
¸åºæ¯è¾ä¸¤ä¸ªå符串 ( std::locale çå
¬å¼æå彿°) | |
| 为å
·å locale å建 collate å¹³é¢ (类模æ¿) |