Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
locale
has_facet
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
locale
tolower
toupper
use_facet
standard facets:
codecvt
codecvt_base
codecvt_byname
collate
collate_byname
ctype
ctype_base
ctype_byname
messages
messages_base
messages_byname
moneypunct
moneypunct_byname
money_base
money_get
money_put
numpunct
numpunct_byname
num_get
num_put
time_base
time_get
time_get_byname
time_put
time_put_byname
ctype
ctype::ctype
public member functions:
ctype::is
ctype::narrow
ctype::scan_is
ctype::scan_not
ctype::tolower
ctype::toupper
ctype::widen
public member types:
ctype::char_type
ctype::mask
protected members:
ctype::do_is
ctype::do_narrow
ctype::do_scan_is
ctype::do_scan_not
ctype::do_tolower
ctype::do_toupper
ctype::do_widen
ctype::~ctype


ctype::is

public member function
        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:
valueCharacteristics
spaceWhite-space character
printPrintable character
cntrlControl character
upperUppercase letter
lowerLowercase letter
alphaAlphabetic letter
digitDecimal digit
punctPunctuation mark
xdigitHexadecimal 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