Sweetener - Escapes
Everyone, sooner or later, must face with escaping characters problem. For this reason we have created a special class Escapes
as part of sweetener
project, which goal is solve this problem. Escapes
class contains five special methods to escape special characters for:
- regular expression -
public static String escapeRegexp(String value)
- html -
public static String escapeHtml(String value)
- url -
public static String escapeUrl(String value)
- xml -
public static String escapeXml(String value)
- json -
public static String escapeJson(String value)
Below are five examples, one for each method:
We have predicted situations in which you would like to define mapping by yourself. So, you can define special characters and use it! It is extremely easy:
But what if to the existing characters you’d like to add your own, or remove superfluous? If you would like to use symbols already defined, you can get it:
Note that always when you get existing characters (for example Escapes.getUrlspecials()
), method returns a new map. Original map is not modified.