命名空间
变体
操作

std::ctype<char>::scan_is

来自 cppreference.cn
< cpp‎ | locale‎ | ctype char
 
 
 
 
 
定义于头文件 <locale>
const char* scan_is( mask m, const char* beg, const char* end ) const;
(1)

在字符数组 [begend) 中定位首个满足分类掩码 m 的字符,亦即首个字符 c 使得 table()[(unsigned char) c] & m 将返回 true

(unsigned char)c >= std::ctype<char>::table_size,则会用实现定义的值代替 table()[(unsigned char)c],对于 c 的不同值可能不同。

内容

[编辑] 参数

m - 要搜索的掩码
beg - 指向要搜索的字符数组中首个字符的指针
end - 指向要搜索的字符数组的末尾后一个位置的指针

[编辑] 返回值

指向 [begend) 中首个满足掩码的字符的指针,或者若未找到这种字符则为 end

[编辑] 注解

与主模板 std::ctype 不同,此特化在分类字符时不做虚函数调用。要定制行为,派生类可以向基类构造函数提供非默认的分类表。

[编辑] 示例

#include <iostream>
#include <iterator>
#include <locale>
 
int main()
{
    std::locale loc("");
    auto& f = std::use_facet<std::ctype<char>>(loc);
 
    // skip until the first letter
    char s1[] = "      \t\t\n  Test";
    const char* p1 = f.scan_is(std::ctype_base::alpha, std::begin(s1), std::end(s1));
    std::cout << '\'' << p1 << "'\n";
 
    // skip until the first letter
    char s2[] = "123456789abcd";
    const char* p2 = f.scan_is(std::ctype_base::alpha, std::begin(s2), std::end(s2));
    std::cout << '\'' << p2 << "'\n";
}

输出

'Test'
'abcd'

[编辑] 参见

[虚函数]
定位序列中首个符合给定分类的字符
(std::ctype<CharT> 的虚保护成员函数) [编辑]
定位序列中首个不符合给定分类的字符,使用分类表
(公开成员函数) [编辑]