#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
using namespace boost;
using namespace std;
int main(
int argc,
char **argv)
{
string str(
"readme.txt");
if(ends_with(str,
"txt")){
cout << to_upper_copy(str) +
"UPPER" << endl;
assert(ends_with(str,
"txt"));
}
replace_first(str,
"readme",
"followme");
cout << str << endl;
vector<char> v(str.begin(),str.end());
vector<char> v2 = to_upper_copy(erase_first_copy(v,
"txt"));
for(
int i =
0;i < v2.size();++i){
cout << v2[i] ;
}
cout << endl;
string str1(
"I Don't Known.\n");
cout << to_upper_copy(str1) << endl;
cout << str1 << endl;
to_lower(str1);
cout << str1 << endl;
string str2(
"Power Bob");
assert(iends_with(str2,
"bob"));
assert(!ends_with(str2,
"bob"));
assert(starts_with(str2,
"Pow"));
assert(contains(str2,
"er"));
string str3 = to_lower_copy(str2);
assert(iequals(str3,str2));
string str4(
"power suit");
assert(ilexicographical_compare(str2,str4));
assert(all(str3.substr(
0,
5),is_lower()));
string str5(
"Anna");
string str6(
"anna");
assert(!is_equal()(str5,str6));
assert(is_less()(str5,str6));
format fmt(
"|%s|\n");
string str7 =
" samus aran ";
cout << fmt % trim_copy(str7) << endl;
cout << fmt % trim_left_copy(str7) << endl;
trim_right(str7);
cout << fmt % str7;
string str8 =
"2016 hello world!";
cout << str8 << endl;
cout << fmt % trim_left_copy_if(str8,is_digit());
cout << fmt % trim_right_copy_if(str8,is_punct());
cout << fmt % trim_copy_if(str8,is_punct() || is_digit() || is_space());
string str9 =
"Long long ago,there was a king";
format fmt2(
"|%s|.pos = %d\n");
iterator_range<
string::iterator> rge;
rge = find_first(str9,
"long");
cout << fmt2 % rge %(rge.begin()-str9.begin());
rge = ifind_first(str9,
"long");
cout << fmt2 % rge %(rge.begin()-str9.begin());
rge = find_nth(str9,
"ng",
2);
cout << fmt2 % rge %(rge.begin()-str9.begin());
rge = find_head(str9,
4);
cout << fmt2 % rge %(rge.begin()-str9.begin());
rge = find_tail(str9,
5);
cout << fmt2 % rge %(rge.begin()-str9.begin());
rge = find_first(str9,
"ewy89");
assert(rge.empty() && !rge);
string str10 =
"Long long ago,there was a king\n";
cout << replace_first_copy(str10,
"long",
"Long ");
replace_last(str10,
"ng",
"mm");
cout << str10 << endl;
replace_tail(str10,
4,
"wwww");
cout << str10 << endl;
cout << ierase_all_copy(str10,
"ago");
cout << replace_nth_copy(str10,
"e",
1,
"1");
cout << erase_tail_copy(str10,
10);
return (
0);
}
转载请注明原文地址: https://ju.6miu.com/read-1000132.html