I use to employ the following method to detect if a character is a whitespace:
Character.isWhiteSpace(char character);
Now I need to detect all the variants of line breaks (\n
, \r
, etc.) for all platforms (Linux, Windows, Mac OSX, etc.). Is there any similar way to detect if a character is a line break? If there is not, how can I detect all the possible variants?
Edit from comments: As I didn't know that line breaks can be represented by several characters, I add some context to the question.
I'm implementing the write(char[] buffer, int offset, int length)
method in a Writer
(see Javadoc). In addition to other operations, I need to detect line breaks inside the buffer
. I'm trying to avoid creating an String
from the buffer
to preserve memory, as I've seen that sometimes the buffer
is too big (several MB).
Is there any way to detect line breaks without creating a String
?