|
bool is (mask m, charT c) const;
const charT* is (const charT* low, const charT* high, mask* vec) const;
Classify characters
The first version, returns whether c belongs to any of the categories specified in bitmask m.
The second version classifies the characters in the range [low,high) sequentially filling the array vec with the bitmask classification of each character.
During its operation, the version of this function in the generic template simply calls the virtual protected member do_is, which is the member function in charge of performing the actions described above.
Conversely, in the char specialization (ctype<char>), this function uses the internal table to directly return the results.
Parameters
- m
- Bitmask of member type ctype::mask (inherited from ctype_base) specifying against which category the character is checked. If the bitmask combines more than one category, the function returns true if the character belongs to any of the categories.
It may be any bitwise combination of the following member enum values:
value | Characteristics |
space | White-space character |
print | Printable character |
cntrl | Control character |
upper | Uppercase letter |
lower | Lowercase letter |
alpha | Alphabetic letter |
digit | Decimal digit |
punct | Punctuation mark |
xdigit | Hexadecimal character |
For a detailed list of the classification of characters of type char, see the reference for cctype.
- c
- Character to classify.
charT is the template parameter of ctype (i.e., the facet's character type).
- low, high
- Pointer to the initial and final characters of the sequence. The range used is [low,high), which contains all the characters between low and high, including the character pointed by low but not the character pointed by high.
charT is the template parameter of ctype (i.e., the facet's character type).
- vec
- Destination array, with enough storage for at least (high-low) elements of type ctype::mask.
This array is filled with the combination of ctype::mask values corresponding to each character.
Return value
The first version returns true if c can be classified in any of the categories passed as mask m.
The second version returns high.
charT is the template parameter of ctype (i.e., the facet's character type).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
// ctype::is example
#include <iostream>
#include <locale>
using namespace std;
int main ()
{
locale loc;
char quote[] = "It is wonderful how much may be done if we are always doing.";
// (Attributed to Thomas Jefferson)
int length = sizeof(quote);
ctype<char>::mask * masks = new ctype<char>::mask [length];
cout << '"' << quote << '"' << endl;
cout << "The quote begins with an uppercase letter? ";
bool upper = use_facet< ctype<char> >(loc).is( ctype<char>::upper, quote[0]);
cout << boolalpha << upper << endl;
int cx = 0;
use_facet< ctype<char> >(loc).is (quote, quote+length, masks);
for (int i=0; i<length; ++i) if (masks[i] & ctype<char>::space) ++cx;
cout << "The quote has " << cx << " whitespaces.\n";
return 0;
}
|
Output:
"It is wonderful how much may be done if we are always doing."
The quote begins with an uppercase letter? true
The quote has 12 whitespaces.
|
See also
ctype::scan_is | Return first character in category (public member function) |
ctype::scan_not | Return first character not in category (public member function) |
ctype::do_is | Classify characters [virtual] (virtual protected member function) |
|