isWhitespace() is not what it claims to be

The following code is straightforward and takes a couple of whacks at seeing if isWhitespace() thinks the newline is truly white space.

char buf[256];

  • Serial.println(isWhitespace('\n'));*
  • buf[0] = '\n';*
  • Serial.println(isWhitespace(buf[0]));*
    The newline character is whitespace according to the isWhitespace() docs. But the above code produces zero values for isWhitespace()'s result!!!

So, um, it seems to me isWhitespace() doesn't work as advertised. What might I be missing?


The problem is that isSpace() does what isWhitespace() should do and vice versa. This was reported some time ago here:

I have submitted a pull request to fix the issue:

It's uncertain whether the accepted solution will be to change the code to match the documentation or to change the documentation to match the code. Either way, it will be some time before the change occurs so you'll need to work with the behavior of the existing code.