I noticed the addition of std::isblank (in <locale>
) and std::isblank (in <cctype>
) in C++11. I found this page which says Returns true if c is a blank character; that is, a space or a tab.
(for "C" locale), so possibly a blank character is a subset of a whitespace character, however I do not understand the reason for the distinction since we have std::isspace
. Why was std::isblank
added to the standard library?
UPDATE According to here, it looks like the POSIX specification was the first to introduce the "blank" character class and then the C and C++ standards followed suit.
isblank() in C/C++. The isblank()function returns non-zero if ch is a character for which isspace() returns true and is used to separate words. Thus for English, the blank characters are space and horizontal tab. The isspace() simply return true if the character is a space.
In other words blank character is a space character used to separate words within a line of text and isblank () is used to identify it. isblank () considers blank characters the tab character (‘ ’) and the space character (‘ ‘). we replace the space with a newline character.
Like all other functions from <cctype>, the behavior of std::isblank is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain char s (or signed char s), the argument should first be converted to unsigned char :
difference between isblank() and isspace() The isspace() simply return true if the character is a space. In other words blank character is a space character used to separate words within a line of text and isblank() is used to identify it. isblank() considers blank characters the tab character (‘t’) and the space character (‘ ‘).
possibly a blank character is a subset of a whitespace character
Definitely a subset. C99 7.4.1.3/2 says, "a standard blank character or is one of a locale-specific set of characters for which isspace is true".
It continues with what I think is the motivation: "and that is used to separate words within a line of text".
isspace
returns true for some characters that are not used to separate words within a line of text. Principally, linebreaks.
Obviously this refers to the isspace
and isblank
in <cctype>
, not the one in <locale>
as you asked, but I don't think that makes any difference. I don't think the standard really makes it explicit, but the two refer to the same list of "character types".
Both are locale-aware – the differences lie within the rules of each locale, which would be too large a list to enumerate here (assuming there is a single, exhaustive list to begin with).
Of particular interest is the default C locale, for which the behavior is as follows:
isspace
returns true
for space, form feed, line feed, carriage return, horizontal tab, and vertical tab.isblank
returns true
only for space and horizontal tab.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With