Boost String Algorithms Library 函数详解二 (predicate)

Table 11.3. Predicates

 

Algorithm nameDescriptionFunctions
starts_withCheck if a string is a prefix of the other onestarts_with()
istarts_with()
ends_withCheck if a string is a suffix of the other oneends_with()
iends_with()
containsCheck if a string is contained of the other onecontains()
icontains()
equalsCheck if two strings are equalequals()
iequals()
allCheck if all elements of a string satisfy the given predicateall()


基础示例:

 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      


在前面都没有详细说明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  //
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值