Namespaces
Variants

std::collate<CharT>:: transform, do_transform

From cppreference.net
헤더 파일에 정의됨 <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) Public 멤버 함수로서, 가장 파생된 클래스의 protected virtual 멤버 함수 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 와 동일한 결과를 생성하도록 함
(함수)