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 () |
Basic example:
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
Which functions are described in detail in the previous section, which are listed below:
1 Is_space // Space
2 Is_alnum // Letters and numbers
3 Is_alpha // Letter
4 Is_cntrl // Control characters
5 Is_digit // Number
6 Is_graph // Printable characters (excluding spaces)
7 Is_lower // Lowercase
8 Is_print // Printable characters (including spaces)
9 Is_punct // Punctuation
10 Is_upper // Uppercase
11 Is_xdigit // Hexadecimal number
12 Is_any_of //
13 Is_from_range //