Table 11.3. Predicates
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 //
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具