Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Many classes allow inclusion of escape sequences in character and string literals; examples include java.util.regex.Pattern as well as classes that support XML- and SQL-based actions by passing string arguments to methods. According to the Java Language Specification [JLS 2011 ], §3.10.6, "Escape Sequences for Character and String Literals" [JLS 2011],"

The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash characters in character literals (§3.10.4) and string literals (§3.10.5).

...

This compliant solution shows the correctly escaped value of the string literal WORDS that results in a regular expression designed to split on word boundaries.:

Code Block
bgColor#ccccff
public class Splitter {
  private final String WORDS = "\\b"; // Interpreted as two chars, '\' and 'b'. Correctly splits on word boundaries

  public String[] split(String input){
    Pattern pattern = Pattern.compile(WORDS);
    String[] input_array = pattern.split(input);
    return input_array;
  }
}

...

This compliant solution shows the correctly escaped value of the WORDS property.:

Code Block
bgColor#ccccff
WORDS: \\b

...