Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why was std::isblank added in C++11?

Tags:

c++

c++11

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.

like image 260
Jesse Good Avatar asked Oct 15 '12 00:10

Jesse Good


People also ask

What is the use of isblank in C++?

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.

What is the difference between isblank () and is blank ()?

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.

Why is STD::isblank undefined?

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 :

What is the difference between isblank () and isspace ()?

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 (‘ ‘).


2 Answers

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".

like image 118
Steve Jessop Avatar answered Sep 21 '22 11:09

Steve Jessop


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.
like image 27
ildjarn Avatar answered Sep 25 '22 11:09

ildjarn