名前空間
変種
操作

std::ctype<char>

From cppreference.com
< cpp‎ | locale
 
 
 
 
ヘッダー <locale> で定義
template<>
class ctype<char>;

このstd::ctypeの特殊化は、型charの文字分類機能をカプセル化します。仮想関数を使用する汎用std::ctypeとは異なり、この特殊化はテーブルルックアップを使用して文字を分類します(一般的に高速です)。

基底クラスstd::ctype<char>は、最小限の「C」ロケールに相当する文字分類を実装します。非デフォルトの分類テーブル引数で構築された場合、またはstd::ctype_byname<char>として、またはユーザー定義の派生ファセットとして構築された場合、分類ルールは拡張または変更される可能性があります。すべてのstd::istreamの書式付き入力関数は、入力解析中の文字分類にstd::ctype<char>を使用する必要があります。

cpp/locale/ctype basecpp/locale/locale/facetstd-ctype char-inheritance.svg

継承図

目次

[編集] ネストされた型

定義
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) [編集]
「C」ロケールの文字分類テーブルを取得します。
(public static member function) [編集]
分類テーブルを使用して、文字または文字シーケンスを分類します。
(public member function) [編集]
分類テーブルを使用して、指定された分類に適合するシーケンス内の最初の文字を検索します。
(public member function) [編集]
分類テーブルを使用して、指定された分類に失敗するシーケンス内の最初の文字を検索します。
(public member function) [編集]
do_toupperを呼び出します。
(public member function of std::ctype<CharT>) [編集]
do_tolowerを呼び出します。
(public member function of std::ctype<CharT>) [編集]
do_widenを呼び出します。
(public member function of std::ctype<CharT>) [編集]
do_narrowを呼び出します。
(public member function of std::ctype<CharT>) [編集]

[編集] protectedメンバー関数

[virtual]
文字または文字を大文字に変換します。
(virtual protected member function of std::ctype<CharT>) [編集]
[virtual]
文字または文字を小文字に変換します。
(virtual protected member function of std::ctype<CharT>) [編集]
[virtual]
charからCharTへ文字または文字を変換します。
(virtual protected member function of std::ctype<CharT>) [編集]
[virtual]
CharTからcharへ文字または文字を変換します。
(virtual protected member function of std::ctype<CharT>) [編集]

std::ctype_baseから継承

ネストされた型

定義
mask 未指定のBitmaskType型(列挙型、整数型、またはビットセット)

メンバ定数

スペース
[static]
空白文字の分類を識別するmaskの値
(公開静的メンバ定数)
print
[static]
印刷可能文字の分類を識別するmaskの値
(公開静的メンバ定数)
cntrl
[static]
制御文字の分類を識別するmaskの値
(公開静的メンバ定数)
upper
[static]
大文字の分類を識別するmaskの値
(公開静的メンバ定数)
lower
[static]
小文字の分類を識別するmaskの値
(公開静的メンバ定数)
alpha
[static]
アルファベット文字の分類を識別するmaskの値
(公開静的メンバ定数)
digit
[static]
数字文字の分類を識別するmaskの値
(公開静的メンバ定数)
punct
[static]
句読点文字の分類を識別するmaskの値
(公開静的メンバ定数)
xdigit
[static]
16進数数字の分類を識別するmaskの値
(公開静的メンバ定数)
blank
[static] (C++11)
空白文字の分類を識別するmaskの値
(公開静的メンバ定数)
alnum
[static]
alpha | digit
(公開静的メンバ定数)
graph
[static]
alnum | punct
(公開静的メンバ定数)

[編集]

次の例は、コンマ区切り値をトークン化するために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 を表す
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)