public member function
<locale>
std::ctype::scan_is
const char_type* scan_is (mask m, const char_type* low, const char_type* high) const;
Return first character in category
Returns the first character in the range [low,high)
that classifies into any of the categories specified in m. If no such character is found in the range, high is returned.
In ctype's generic template, this function simply calls the virtual protected member do_scan_is, which does the above by default.
In the char
specialization (ctype<char>
), this function uses the internal table to directly return the results without calling any virtual member.
Parameters
- m
- Bitmask of member type mask (inherited from ctype_base) specifying the categories to scan for. If the bitmask combines more than one category, the function returns a pointer to the first character that belongs to any of the categories.
It may be any bitwise combination of the following member bitmask values:
member constant | value | description |
space | unspecified (unique bits) | white-space character |
print | unspecified (unique bits) | printable character |
cntrl | unspecified (unique bits) | control character |
upper | unspecified (unique bits) | uppercase letter |
lower | unspecified (unique bits) | lowercase letter |
alpha | unspecified (unique bits) | alphabetic character |
digit | unspecified (unique bits) | decimal digit |
punct | unspecified (unique bits) | punctuation character |
xdigit | unspecified (unique bits) | hexadecimal digit |
alnum | alpha|digit | alpha-numeric character |
graph | alnum|punct | character with graphic representation |
member constant | value | description |
space | unspecified (unique bits) | white-space character |
print | unspecified (unique bits) | printable character |
cntrl | unspecified (unique bits) | control character |
upper | unspecified (unique bits) | uppercase letter |
lower | unspecified (unique bits) | lowercase letter |
alpha | unspecified (unique bits) | alphabetic character |
digit | unspecified (unique bits) | decimal digit |
punct | unspecified (unique bits) | punctuation character |
xdigit | unspecified (unique bits) | hexadecimal digit |
blank | unspecified (unique bits) | blank character |
alnum | alpha|digit | alpha-numeric character |
graph | alnum|punct | character with graphic representation |
See <cctype> for details on how ASCII characters are classified with respect to these categories.
- low, high
- Pointer to the beginning and end of the sequence of characters. 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.
Note that null characters (if any) are also considered, and the function proceeds beyond them, until a match is found or the entire range is completed.
Member type char_type is the facet's character type (defined as an alias of ctype's template parameter, charT).
Return value
A pointer to the first element in the range that classifies, or high if none is found.
Member type char_type is the facet's character type (defined as an alias of ctype's template parameter, charT).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// ctype::scan_is example
#include <iostream> // std::cout
#include <locale> // std::locale, std::ctype, std::use_facet
int main ()
{
std::locale loc;
const char quote[] = "Characters do not change. Opinions alter, but characters are only developed.";
// (quoting Benjamin Disraeli)
// get a pointer to the first "punctuation" character:
const char * p = std::use_facet< std::ctype<char> >(loc).scan_is ( std::ctype<char>::punct, quote, quote+76 );
std::cout << "The second sentence is: " << p << '\n';
return 0;
}
| |
Output:
The second sentence is: . Opinions alter, but characters are only developed.
|
Data races
The object, and the elements in the range [low,high)
, are accessed.
Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the object.
See also
- ctype::is
- Classify characters (public member function
)
- ctype::scan_not
- Return first character not in category (public member function
)
- ctype::do_scan_is
- Return first character in category [virtual] (protected virtual member function
)