Boost之string算法库

标准库里的string虽然功能强大,但它还是缺少很多常用功能,如trim,大小写转换等。作为标准库的补充,Boost承担起了弥补这些缺点的任务,于是就有了Boost String Algorithms Library

快速参考

Boost.String Algo提供了标准库中没有提供的字符串操作功能,比如大小写转换,正则表达式查找等。它的命名规则是:如果函数是大小写无关的,则带有前缀 i。如果返回结果是一份拷贝(即没有修改输入字串),则带 _copy后缀。

算 法

Table 18.1. 大小写转换

算法名称描述函数
to_upper转成大写to_upper_copy()
to_upper()
to_lower转成小写to_lower_copy()
to_lower()

Table 18.2. Trimming

算法名称描述函数
trim_left去除字符串左边的空格字符trim_left_copy_if()
trim_left_if()
trim_left_copy()
trim_left()
trim_right去除字符串右边的空格字符trim_right_copy_if()
trim_right_if()
trim_right_copy()
trim_right()
trim去除字符串左右两边的空格字符trim_copy_if()
trim_if()
trim_copy()
trim()

Table 18.3.判断

算法名称描述函数
starts_with一个字符串是否是另一字符串的前缀starts_with()
istarts_with()
ends_with一个字符串是否是另一字符串的后缀ends_with()
iends_with()
contains一个字符串是否被另一字符串包含contains()
icontains()
equals两个字符串是否相同equals()
iequals()
lexicographical_compare一个字符串是否小于另一字符串(按字典排序)lexicographical_compare()
ilexicographical_compare()
all字符串中所有的字符是否都满足指定条件all()

Table 18.4. 查找算法

算法名称描述函数
find_first查找子串第一次在被查找串中出现的位置find_first()
ifind_first()
find_last查找子串最后一次在被查找串中的位置find_last()
ifind_last()
find_nth查找子串第n次出现在被查找串中的位置find_nth()
ifind_nth()
find_head返回字符串头部位置find_head()
find_tail返回字符串尾部位置find_tail()
find_token查找第一次匹配的tokenfind_token()
find_regex使用正则表达式查找子串位置find_regex()
find使用通用算法Finder查找子串位置find()

Table 18.5. 删除/替换

算法名称描述函数
replace/erase_first替换/删除第一次出现在被查找串中的子串replace_first()
replace_first_copy()
ireplace_first()
ireplace_first_copy()
erase_first()
erase_first_copy()
ierase_first()
ierase_first_copy()
replace/erase_last替换/删除最后一次出现在被查找串中的子串replace_last()
replace_last_copy()
ireplace_last()
ireplace_last_copy()
erase_last()
erase_last_copy()
ierase_last()
ierase_last_copy()
replace/erase_nth替换/删除第n次出现在被查找串中的子串replace_nth()
replace_nth_copy()
ireplace_nth()
ireplace_nth_copy()
erase_nth()
erase_nth_copy()
ierase_nth()
ierase_nth_copy()
replace/erase_all替换/删除所有的子串replace_all()
replace_all_copy()
ireplace_all()
ireplace_all_copy()
erase_all()
erase_all_copy()
ierase_all()
ierase_all_copy()
replace/erase_head替换/删除头部几个字符replace_head()
replace_head_copy()
erase_head()
erase_head_copy()
replace/erase_tail替换/删除尾部几个字符replace_tail()
replace_tail_copy()
erase_tail()
erase_tail_copy()
replace/erase_regex替换/删除一个匹配正则表达式的子串replace_regex()
replace_regex_copy()
erase_regex()
erase_regex_copy()
replace/erase_regex_all替换/删除所有匹配正则表达式的子串replace_all_regex()
replace_all_regex_copy()
erase_all_regex()
erase_all_regex_copy()
find_format通用替换算法find_format()
find_format_copy()
find_format_all()
find_format_all_copy()()

Table 18.6. 切分

算法名称描述函数
find_all查找/提取 所有匹配的子串find_all()
ifind_all()
find_all_regex()
split切分字符串split()
split_regex()
iter_find使用Finder查找所有的子串并存入指定的容器中iter_find()
iter_split使用Finder查找子串并把它作为分隔符切分字符串iter_split()

Table 18.7. 连接

算法名称描述函数
join合并容器中的所有字符串成一个长字符串join
join_if合并容器中所有满足条件的字符串成一个长字符串join_if()

Finders and Formatters

Table 18.8. Finders(查找器)

Finder描述Generators
first_finder查找第一次匹配的字符串first_finder()
last_finder查找最后一次匹配的字符串last_finder()
nth_finder查找第n次匹配的字符串nth_finder()
head_finder接收字符串头部head_finder()
tail_finder接收字符串尾部tail_finder()
token_finder在字符串中查找匹配的 tokentoken_finder()
range_finder总是返回整个字符串range_finder()
regex_finder使用正则表达式查找字符串regex_finder()

Table 18.9. Formatters(格式化器)

Formatter描述Generators
const_formatter总是返回指定的字符串const_formatter()
identity_formatter返回原字符串identity_formatter()
empty_formatter总是返回空字符串empty_formatter()
regex_formatter正则表达式格式化器,它用来与regex_finder配合使用regex_formatter()

迭代器

Table 18.10. Find Iterators

Iterator name描述Iterator class
find_iteratorIterates through matching substrings in the inputfind_iterator
split_iteratorIterates through gaps between matching substrings in the inputsplit_iterator

归类

Table 18.11. Predicates

Predicate name描述Generator
is_classifiedGeneric ctype mask based classificationis_classified()
is_spaceRecognize spacesis_space()
is_alnumRecognize alphanumeric charactersis_alnum()
is_alphaRecognize lettersis_alpha()
is_cntrlRecognize control charactersis_cntrl()
is_digitRecognize decimal digitsis_digit()
is_graphRecognize graphical charactersis_graph()
is_lowerRecognize lower case charactersis_lower()
is_printRecognize printable charactersis_print()
is_punctRecognize punctuation charactersis_punct()
is_upperRecognize uppercase charactersis_upper()
is_xdigitRecognize hexadecimal digitsis_xdigit()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值