2011-01-06 2 views
1

나는 내 문자열, bool 쌍 벡터를 정렬하는 데 사용할 클래스가 있습니다. 내 문자열은 utf-8로 인코딩됩니다.std :: locale 사용에 대한 도움말?

zap 
    apple 
    école 
    blue 
    erable 

이로 분류 것이라고 :

apple 
blue 
école 
erable 
zap 
나는 그 사람의 로케일이 예를 들어로 설정되어있는 경우 즉, 프랑스어, 나는 사용자가 입력 한 경우 희망 할 수 있도록 그들을 정렬 할

내 표준 : : 로케일 클래스는 이것이다 :

class AguiLBLocaleCompare : 
    public std::binary_function<std::pair<std::string, bool>, 
    std::pair<std::string,bool>, bool> { 
protected: 
    const std::collate<char> &coll; 
public: 
    AguiLBLocaleCompare(std::locale loc) 
     : coll(std::use_facet<std::collate<char> >(loc)) {} 
    bool operator()(const std::pair<std::string, bool> &a, 
     const std::pair<std::string, bool> &b) const { 
     // std::collate::compare() takes C-style string (begin, end)s and 
     // returns values like strcmp or strcoll. Compare to 0 for results 
     // expected for a less<>-style comparator. 
     return coll.compare(a.first.c_str(), a.first.c_str() + a.first.size(), 
      b.first.c_str(), b.first.c_str() + b.first.size()) < 0; 
    } 
}; 

다음 내 항목이 정렬 방법은 다음과 같습니다

void AguiListBox::sort() 
{ 
    if(!isReverseSorted()) 
     std::sort(items.begin(),items.end(),AguiLBLocaleCompare(WHAT_DO_I_PUT_HERE)); 
    else 
     std::sort(items.rbegin(),items.rend(),AguiLBLocaleCompare(WHAT_DO_I_PUT_HERE)); 
} 

그래서 원하는 효과를 얻기 위해 생성자를 넣어야할지 모르겠습니다.

나는 std::locale()을 시도했지만, 내가 원하는 것이 아닌 zap의 z 다음에 악센트를 정렬했다.

항목은

std::vector<std::pair<std::string, bool>> 

감사

+0

어떤 플랫폼을 사용하고 계십니까? C++ 로켈 지원은 악명이 높습니다. –

+0

저는 Windows 7에 있습니다. – jmasterx

+0

구문 상 모든 로케일을 입력 할 수 있습니다. 'std :: locale :: locale ("fr_FR.utf8")'그러나 어떤 로케일 윈도우가 사용 가능한지 또는 그들의 C++ 로케일 이름이 무엇인지는 잘 모른다. –

답변

1

내가 VC++을 생각하지 않는 UTF-8 로켈을 지원합니다. convert에서 wstring으로 설정하고 collate<wchar_t>을 사용하거나 UTF-8 로캘을 지원하는 C++ 라이브러리로 전환해야합니다.

Windows/VC++의 로켈 이름은 UNIX에서와 다릅니다. MSDN의 Language and Country/Region Strings (CRT)을 참조하십시오.

관련 문제