std:: ctype <char>
|
헤더 파일에 정의됨
<locale>
|
||
|
template
<>
class ctype < char > ; |
||
이 특수화는 std::ctype 의 char 타입에 대한 문자 분류 기능을 캡슐화합니다. 가상 함수를 사용하는 일반 목적의 std::ctype 과 달리, 이 특수화는 문자를 분류하기 위해 테이블 조회를 사용합니다(일반적으로 더 빠릅니다).
기본 클래스
std::ctype
<
char
>
는 최소 "C" 로캘과 동등한 문자 분류를 구현합니다. 분류 규칙은 기본이 아닌 분류 테이블 인수로 생성되거나,
std::
ctype_byname
<
char
>
로 생성되거나, 사용자 정의 파생 패싯으로 생성될 경우 확장되거나 수정될 수 있습니다. 모든
std::istream
형식화 입력 함수는 입력 구문 분석 중 문자 분류를 위해
std::ctype
<
char
>
를 사용해야 합니다.
상속 다이어그램
목차 |
중첩 타입
| 유형 | 정의 |
char_type
|
char |
데이터 멤버
| 멤버 | 설명 |
std::locale::id
id
[static]
|
패싯 의 식별자 |
const
std::
size_t
table_size
[static]
|
분류 테이블의 크기, 최소 256 |
멤버 함수
|
새로운
ctype
<
char
>
패싯을 생성합니다
(public member function) |
|
|
ctype
<
char
>
패싯을 소멸시킵니다
(protected member function) |
|
|
문자 분류 테이블을 얻습니다
(public member function) |
|
|
[static]
|
"C" 로케일 문자 분류 테이블을 얻습니다
(public static member function) |
|
분류 테이블을 사용하여 문자나 문자 시퀀스를 분류합니다
(public member function) |
|
|
분류 테이블을 사용하여 주어진 분류에 부합하는 시퀀스 내 첫 번째 문자를 찾습니다
(public member function) |
|
|
분류 테이블을 사용하여 주어진 분류에 실패하는 시퀀스 내 첫 번째 문자를 찾습니다
(public member function) |
|
do_toupper
를 호출합니다
(
std::ctype<CharT>
의 public member function)
|
|
do_tolower
를 호출합니다
(
std::ctype<CharT>
의 public member function)
|
|
do_widen
를 호출합니다
(
std::ctype<CharT>
의 public member function)
|
|
do_narrow
를 호출합니다
(
std::ctype<CharT>
의 public member function)
|
보호된 멤버 함수
|
[virtual]
|
문자 또는 문자들을 대문자로 변환
(
std::ctype<CharT>
의
virtual protected 멤버 함수)
|
|
[virtual]
|
문자 또는 문자들을 소문자로 변환
(
std::ctype<CharT>
의
virtual protected 멤버 함수)
|
|
[virtual]
|
문자 또는 문자들을
char
에서
CharT
로 변환
(
std::ctype<CharT>
의
virtual protected 멤버 함수)
|
|
[virtual]
|
문자 또는 문자들을
CharT
에서
char
로 변환
(
std::ctype<CharT>
의
virtual 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]
|
16진수 숫자 문자 분류를 식별하는
mask
값
(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 > 수정하는 방법을 보여줍니다:
#include <cstddef> #include <iostream> #include <locale> #include <sstream> #include <vector> // This ctype facet classifies commas and endlines as whitespace struct csv_whitespace : std::ctype<char> { static const mask* make_table() { // make a copy of the "C" locale table static std::vector<mask> v(classic_table(), classic_table() + table_size); v[','] |= space; // comma will be classified as whitespace v[' '] &= ~space; // space will not be classified as whitespace return &v[0]; } csv_whitespace(std::size_t refs = 0) : ctype(make_table(), false, refs) {} }; int main() { std::string in = "Column 1,Column 2,Column 3\n123,456,789"; std::string token; std::cout << "Default locale:\n"; std::istringstream s1(in); while (s1 >> token) std::cout << " " << token << '\n'; std::cout << "Locale with modified ctype:\n"; std::istringstream s2(in); s2.imbue(std::locale(s2.getloc(), new csv_whitespace)); while (s2 >> token) std::cout << " " << 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
결함 보고서
다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 695 | C++98 |
table()
및
classic_table()
함수가 protected 멤버 함수였음
|
public으로 변경 |
참고 항목
|
문자 분류 테이블을 정의함
(클래스 템플릿) |
|
|
문자 분류 범주를 정의함
(클래스) |
|
|
명명된 로캘에 대한 시스템 제공
std::ctype
을 나타냄
(클래스 템플릿) |