std::ctype<char>::scan_is
来自 cppreference.cn
< cpp | 本地化 | ctype char
定义于头文件 <locale> |
||
const char* scan_is( mask m, const char* beg, const char* end ) const; |
(1) | |
在字符数组 [
beg,
end)
中定位第一个满足分类掩码 m 的字符,即第一个字符 c
使得 table()[(unsigned char) c] & m 返回 true。
如果 (unsigned char)c >= std::ctype<char>::table_size,则会用一个实现定义的值替换 table()[(unsigned char)c],对于不同的 c 值可能不同。
目录 |
[编辑] 参数
m | - | 要搜索的掩码 |
beg | - | 指向要搜索字符数组中第一个字符的指针 |
end | - | 指向要搜索字符数组末尾之后一个位置的指针 |
[编辑] 返回值
指向 [
beg,
end)
中满足掩码的第一个字符的指针,如果没有找到这样的字符,则返回 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'
[编辑] 参阅
[virtual] |
在一个序列中定位第一个符合给定分类的字符 ( std::ctype<CharT> 的虚保护成员函数) |
使用分类表在序列中定位第一个不符合给定分类的字符 (公有成员函数) |