Go Down

Topic: isWhitespace() is not what it claims to be (Read 241 times) previous topic - next topic

robertschulman

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?

bob

pert

The problem is that isSpace() does what isWhitespace() should do and vice versa. This was reported some time ago here:
https://github.com/arduino/Arduino/issues/7041

I have submitted a pull request to fix the issue:
https://github.com/arduino/ArduinoCore-API/pull/27

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.

Go Up