std:: ctype
|
헤더에 정의됨
<locale>
|
||
|
template
<
class
CharT
>
class ctype ; |
||
클래스
ctype
는 문자 분류 기능을 캡슐화합니다.
std::
basic_istream
<
CharT
>
를 통해 수행되는 모든 스트림 입력 연산은 입력 토큰화를 위한 공백 문자를 식별하기 위해 스트림에 임베드된 로캘의
std::ctype<CharT>
를 사용합니다. 스트림 출력 연산은 출력 전에 좁은 문자 인수에 대해
std::ctype<CharT>::widen()
를 적용합니다.
상속 다이어그램
목차 |
특수화
표준 라이브러리는 다음과 같은 특수화를 제공함을 보장합니다 (이들은 모든 locale 객체에 의해 구현되어야 하는 요구사항 입니다):
|
헤더 파일에 정의됨
<locale>
|
|
std::ctype<char>
|
기본 "C" 로케일 분류의 좁은 문자(narrow character)에 해당하는 기능을 제공합니다. 이 특수화는 문자 분류를 위해 테이블 조회를 사용합니다 |
| std :: ctype < wchar_t > | 기본 문자 집합에 적합한 와이드 문자(wide character) 분류를 제공합니다 |
중첩 타입
| 타입 | 정의 |
char_type
|
CharT
|
데이터 멤버
| 멤버 | 설명 |
std::locale::id
id
[static]
|
facet 의 식별자 |
멤버 함수
새로운
ctype
패싯을 생성합니다
(public member function) |
|
ctype
패싯을 소멸합니다
(protected member function) |
|
do_is
를 호출합니다
(public member function) |
|
do_scan_is
를 호출합니다
(public member function) |
|
do_scan_not
를 호출합니다
(public member function) |
|
do_toupper
를 호출합니다
(public member function) |
|
do_tolower
를 호출합니다
(public member function) |
|
do_widen
를 호출합니다
(public member function) |
|
do_narrow
를 호출합니다
(public member function) |
보호된 멤버 함수
|
[virtual]
|
문자 또는 문자 시퀀스를 분류합니다
(가상 protected 멤버 함수) |
|
[virtual]
|
시퀀스에서 주어진 분류에 맞는 첫 번째 문자를 찾습니다
(가상 protected 멤버 함수) |
|
[virtual]
|
시퀀스에서 주어진 분류에 실패하는 첫 번째 문자를 찾습니다
(가상 protected 멤버 함수) |
|
[virtual]
|
문자 또는 문자들을 대문자로 변환합니다
(가상 protected 멤버 함수) |
|
[virtual]
|
문자 또는 문자들을 소문자로 변환합니다
(가상 protected 멤버 함수) |
|
[virtual]
|
문자 또는 문자들을
char
에서
CharT
로 변환합니다
(가상 protected 멤버 함수) |
|
[virtual]
|
문자 또는 문자들을
CharT
에서
char
로 변환합니다
(가상 protected 멤버 함수) |
std:: ctype_base 에서 상속됨
중첩 타입
| 타입 | 정의 |
mask
|
지정되지 않은 BitmaskType 타입 (열거형, 정수 타입, 또는 비트셋) |
멤버 상수
|
space
[static]
|
mask
의 공백 문자 분류를 식별하는 값
(public static member constant) |
|
print
[static]
|
mask
의 출력 가능 문자 분류를 식별하는 값
(public static member constant) |
|
cntrl
[static]
|
mask
의 제어 문자 분류를 식별하는 값
(public static member constant) |
|
upper
[static]
|
mask
의 대문자 문자 분류를 식별하는 값
(public static member constant) |
|
lower
[static]
|
mask
의 소문자 문자 분류를 식별하는 값
(public static member constant) |
|
alpha
[static]
|
mask
의 알파벳 문자 분류를 식별하는 값
(public static member constant) |
|
digit
[static]
|
mask
의 숫자 문자 분류를 식별하는 값
(public static member constant) |
|
punct
[static]
|
mask
의 구두점 문자 분류를 식별하는 값
(public static member constant) |
|
xdigit
[static]
|
mask
의 16진수 숫자 문자 분류를 식별하는 값
(public static member constant) |
|
blank
[static]
(C++11)
|
mask
의 공백 문자 분류를 식별하는 값
(public static member constant) |
|
alnum
[static]
|
alpha
|
digit
(public static member constant) |
|
graph
[static]
|
alnum
|
punct
(public static member constant) |
예제
다음 예제는
ctype<char>
이외의
ctype
을 수정하여 CSV 파일을 토큰화하는 방법을 보여줍니다:
#include <iostream> #include <locale> #include <sstream> struct csv_whitespace : std::ctype<wchar_t> { bool do_is(mask m, char_type c) const { if ((m & space) && c == L' ') return false; // space will NOT be classified as whitespace if ((m & space) && c == L',') return true; // comma will be classified as whitespace return ctype::do_is(m, c); // leave the rest to the base class } }; int main() { std::wstring in = L"Column 1,Column 2,Column 3\n123,456,789"; std::wstring token; std::wcout << "default locale:\n"; std::wistringstream s1(in); while (s1 >> token) std::wcout << " " << token << '\n'; std::wcout << "locale with modified ctype:\n"; std::wistringstream s2(in); csv_whitespace* my_ws = new csv_whitespace; s2.imbue(std::locale(s2.getloc(), my_ws)); while (s2 >> token) std::wcout << " " << token << '\n'; }
출력:
default locale: Column 1,Column 2,Column 3 123,456,789 locale with modified ctype: Column 1 Column 2 Column 3 123 456 789
참고 항목
|
std::ctype
의
char
타입에 대한 특수화
(클래스 템플릿 특수화) |
|
|
문자 분류 범주를 정의함
(클래스) |
|
|
명명된 로캘에 대한 시스템 제공
std::ctype
을 나타냄
(클래스 템플릿) |