我想要一個函數'降低'(從單詞)在兩種語言上正確工作,例如英語和俄語。我該怎麼辦?我應該使用std :: wstring,還是我可以使用std :: string? 另外我希望它是跨平臺的,不要重新發明輪子。如何使語言友好的功能降低?
2
A
回答
6
對於這種事情的規範庫是ICU:
還有一個升壓包裝:
http://www.boost.org/doc/libs/1_55_0/libs/locale/doc/html/index.html
另見這個問題: Is there an STL and UTF-8 friendly C++ Wrapper for ICU, or other powerful Unicode library
首先確保你瞭解這個騙局您可以牢牢掌握Unicode和更一般的編碼系統。
一些很好的讀取快速啓動:
0
我認爲這個解決方案是確定的。我不確定它適合所有情況,但這很有可能。
#include <locale>
#include <codecvt>
#include <string>
std::string toLowerCase (const std::string& word) {
std::wstring_convert<std::codecvt_utf8<wchar_t> > conv;
std::locale loc("en_US.UTF-8");
std::wstring wword = conv.from_bytes(word);
for (int i = 0; i < wword.length(); ++i) {
wword[i] = std::tolower(word[i], loc);
}
return conv.to_bytes(wword);
}
相關問題
- 1. 好友功能
- 2. MPI分鐘功能降低
- 3. JAVASCRIPT亮度功能 - 降低
- 4. 降低功耗
- 5. 如何正確訪問好友功能?
- 6. 如何編寫DataFrame友好功能
- 7. 如何使用此功能降低怎麼辦?
- 8. 如何使用CTRL + p使用打印機友好的功能?
- 9. 好友功能和實現
- 10. 訪問好友功能
- 11. 爲「查找好友」功能
- 12. 實現好友功能
- 13. 如何降低select語句的成本?
- 14. 如何降低
- 15. Cloudant列表功能或單獨降低
- 16. 降低過載功能(常量和VS&)
- 17. 主成分分析和功能降低
- 18. 降低python降價能力
- 19. 如何降低Windows CE設備上的ActiveSync功能
- 20. neo4j匹配語句性能降低
- 21. 如何降低使用jQuery
- 22. 如何降低助推術語dismax
- 23. 實施語法降低語言解析器
- 24. 索引如何降低MySQL的性能?
- 25. 如何實現一種功能語言
- 26. 功能的「自然語言」
- 27. Lisp語言的功能
- 28. 跨多個文件的好友功能
- 29. 用戶友好的網址從功能
- 30. NVL()降低性能
這是一個複雜的問題。確保你知道區域設置,並且你已經閱讀了這個:http://www.joelonsoftware.com/articles/Unicode.html –
最後,爲了做到這一點,你不得不使用unicode字符串,您選擇的編碼(更喜歡UTF-8)。對於單個unicode代碼點,未正確定義更改大小寫(低,高,標題,摺疊)。儘管如此,還有很多語言對這些轉換的定義有衝突。 – Deduplicator
所以我應該使用unicode,還有什麼?我確切知道我將會擁有哪些語言。其中之一。它無法幫助一些 - 如何? –