Search code examples
javawhitespaceguava

What's the difference between BREAKING_WHITESPACE and WHITESPACE in Guava CharMatcher


In guava CharMatcher there are 2 inner class BREAKING_WHITESPACE and WHITESPACE, and the definition of BREAKING_WHITESPACE is : a whitespace which can be interpreted as a break between words for formatting purposes

What does it mean?

Can anyone answer this question ?

If you can provide an example for the diff it would be nice

Thx in advance


Solution

  • This is fairly general character stuff, not Guava specific:
    http://en.wikipedia.org/wiki/Non-breaking_space#Non-breaking_behavior
    Actually the Javadoc says it all:

    Determines whether a character is a breaking whitespace (that is, a whitespace which can be interpreted as a break between words for formatting purposes).

    You put a non-breaking space in text between two words which must stay on the same line. Often it gets used for numbers with units like 123.456 MPa. In HTML you'd write  , ever seen it?

    Out of all whitespace chars, there are some non-breaking, e.g. U+0202F and U+000A0.