Table 11.3. Predicates
基础示例:
在前面都没有详细说明is_xxxx是哪些函数,下面列出:
Algorithm name | Description | Functions |
---|---|---|
starts_with | Check if a string is a prefix of the other one | starts_with()istarts_with() |
ends_with | Check if a string is a suffix of the other one | ends_with()iends_with() |
contains | Check if a string is contained of the other one | contains()icontains() |
equals | Check if two strings are equal | equals()iequals() |
all | Check if all elements of a string satisfy the given predicate | all() |
基础示例:
1 //starts
2 assert(starts_with("boost_python-vc71-mt-1_33.dll", "boost"));
3 assert(!starts_with("boost_python-vc71-mt-1_33.dll", "BOOST"));
4 assert(istarts_with("boost_python-vc71-mt-1_33.dll", "BOOST"));
5 //ends
6 assert(ends_with("boost_python-vc71-mt-1_33.dll", ".dll"));
7 assert(!ends_with("boost_python-vc71-mt-1_33.dll", ".DLL"));
8 assert(iends_with("boost_python-vc71-mt-1_33.dll", ".DLL"));
9 //contains
10 assert(contains("boost_python-vc71-mt-1_33.dll", "python"));
11 assert(!contains("boost_python-vc71-mt-1_33.dll", "PYTHON"));
12 assert(icontains("boost_python-vc71-mt-1_33.dll", "PYTHON"));
13 //equals
14 assert(equals("boost", "boost"));
15 assert(!equals("boost", "BOOST"));
16 assert(iequals("boost", "BOOST"));
17 //Empty string test
18 assert(starts_with("boost_python-vc71-mt-1_33.dll", ""));
19 assert(ends_with("boost_python-vc71-mt-1_33.dll", ""));
20 assert(contains("boost_python-vc71-mt-1_33.dll", ""));
21 //all
22 assert(all("\x20\t\n\r", is_space()));
23 assert(all("\x20\t\n\r", is_classified(std::ctype_base::space)));
24 assert(all("\x20\t\n\r", is_any_of("\x20\t\n\r")));
25 assert(all("abcde", is_from_range('a','e')));
26 assert(all("abcde", is_from_range('a','z')));
27 assert(!all("abcde", is_from_range('b','c')));
28 assert(all("abc __ de", is_from_range('a','z') || is_space() || is_any_of("_")));
29
2 assert(starts_with("boost_python-vc71-mt-1_33.dll", "boost"));
3 assert(!starts_with("boost_python-vc71-mt-1_33.dll", "BOOST"));
4 assert(istarts_with("boost_python-vc71-mt-1_33.dll", "BOOST"));
5 //ends
6 assert(ends_with("boost_python-vc71-mt-1_33.dll", ".dll"));
7 assert(!ends_with("boost_python-vc71-mt-1_33.dll", ".DLL"));
8 assert(iends_with("boost_python-vc71-mt-1_33.dll", ".DLL"));
9 //contains
10 assert(contains("boost_python-vc71-mt-1_33.dll", "python"));
11 assert(!contains("boost_python-vc71-mt-1_33.dll", "PYTHON"));
12 assert(icontains("boost_python-vc71-mt-1_33.dll", "PYTHON"));
13 //equals
14 assert(equals("boost", "boost"));
15 assert(!equals("boost", "BOOST"));
16 assert(iequals("boost", "BOOST"));
17 //Empty string test
18 assert(starts_with("boost_python-vc71-mt-1_33.dll", ""));
19 assert(ends_with("boost_python-vc71-mt-1_33.dll", ""));
20 assert(contains("boost_python-vc71-mt-1_33.dll", ""));
21 //all
22 assert(all("\x20\t\n\r", is_space()));
23 assert(all("\x20\t\n\r", is_classified(std::ctype_base::space)));
24 assert(all("\x20\t\n\r", is_any_of("\x20\t\n\r")));
25 assert(all("abcde", is_from_range('a','e')));
26 assert(all("abcde", is_from_range('a','z')));
27 assert(!all("abcde", is_from_range('b','c')));
28 assert(all("abc __ de", is_from_range('a','z') || is_space() || is_any_of("_")));
29
在前面都没有详细说明is_xxxx是哪些函数,下面列出:
1 is_space // 空格
2 is_alnum // 字母和数字
3 is_alpha // 字母
4 is_cntrl // 控制字符
5 is_digit // 数字
6 is_graph // 可打印字符(不含空格)
7 is_lower // 小写
8 is_print // 可打印字符(含空格)
9 is_punct // 标点
10 is_upper // 大写
11 is_xdigit // 16进制数字
12 is_any_of //
13 is_from_range //
2 is_alnum // 字母和数字
3 is_alpha // 字母
4 is_cntrl // 控制字符
5 is_digit // 数字
6 is_graph // 可打印字符(不含空格)
7 is_lower // 小写
8 is_print // 可打印字符(含空格)
9 is_punct // 标点
10 is_upper // 大写
11 is_xdigit // 16进制数字
12 is_any_of //
13 is_from_range //