Class Escaping
- java.lang.Object
-
- com.vladsch.flexmark.util.sequence.Escaping
-
public class Escaping extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceEscaping.Replacer
-
Field Summary
Fields Modifier and Type Field Description static @NotNull CharPredicateAMP_BACKSLASH_SETprivate static java.util.regex.PatternAMP_ONLYprivate static java.util.regex.PatternBACKSLASH_ONLYprivate static java.util.regex.PatternBACKSLASH_OR_AMPprivate static java.util.regex.PatternCOLLAPSE_WHITESPACEprivate static Escaping.ReplacerCOLLAPSE_WHITESPACE_REPLACERprivate static java.lang.StringENTITYprivate static java.util.regex.PatternENTITY_ONLYprivate static java.util.regex.PatternENTITY_OR_ESCAPED_CHARprivate static Escaping.ReplacerENTITY_REPLACERstatic java.lang.StringESCAPABLEstatic java.lang.StringESCAPABLE_CHARSprivate static java.util.regex.PatternESCAPE_IN_URIprivate static java.util.regex.PatternESCAPE_URI_DECODEprivate static java.util.regex.PatternESCAPED_CHAR(package private) static char[]HEX_DIGITSprivate static java.util.Randomrandomprivate static Escaping.ReplacerREMOVE_REPLACERprivate static Escaping.ReplacerUNESCAPE_REPLACERprivate static Escaping.ReplacerUNSAFE_CHAR_REPLACERprivate static Escaping.ReplacerURL_DECODE_REPLACERprivate static Escaping.ReplacerURL_ENCODE_REPLACERprivate static java.util.regex.PatternWHITESPACEprivate static java.lang.StringXML_SPECIALprivate static java.util.regex.PatternXML_SPECIAL_OR_ENTITYprivate static java.util.regex.PatternXML_SPECIAL_RE
-
Constructor Summary
Constructors Constructor Description Escaping()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull BasedSequencecollapseWhitespace(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)static @NotNull java.lang.StringcollapseWhitespace(@NotNull java.lang.CharSequence s, boolean trim)Collapse regions of multiple white spaces to a single spaceprivate static @Nullable java.lang.Stringencode(char c)static @NotNull BasedSequenceescapeHtml(@NotNull BasedSequence s, boolean preserveEntities, @NotNull ReplacedTextMapper textMapper)static java.lang.StringescapeHtml(@NotNull java.lang.CharSequence s, boolean preserveEntities)static @NotNull BasedSequencenormalizeEndWithEOL(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)Normalize eol: embedded \r and \r\n are converted to \nstatic @NotNull java.lang.StringnormalizeEndWithEOL(@NotNull java.lang.CharSequence s)Normalize eol: embedded \r and \r\n are converted to \nstatic @NotNull BasedSequencenormalizeEOL(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)Normalize eol: embedded \r and \r\n are converted to \nstatic @NotNull BasedSequencenormalizeEOL(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper, boolean endWithEOL)Normalize eol: embedded \r and \r\n are converted to \nstatic @NotNull java.lang.StringnormalizeEOL(@NotNull java.lang.CharSequence s)Normalize eol: embedded \r and \r\n are converted to \nstatic @NotNull java.lang.StringnormalizeEOL(@NotNull java.lang.CharSequence s, boolean endWithEOL)Normalize eol: embedded \r and \r\n are converted to \nstatic @NotNull java.lang.StringnormalizeReference(@NotNull java.lang.CharSequence s, boolean changeCase)Normalize the link reference idstatic @NotNull java.lang.StringnormalizeReferenceChars(@NotNull java.lang.CharSequence s, boolean changeCase)Get a normalized the link reference id from reference charactersstatic @NotNull java.lang.Stringobfuscate(@NotNull java.lang.String email, boolean randomize)e-mail obfuscation from pegdownstatic @NotNull BasedSequencepercentDecodeUrl(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)static @NotNull java.lang.StringpercentDecodeUrl(@NotNull java.lang.CharSequence s)static @NotNull BasedSequencepercentEncodeUrl(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)static @NotNull java.lang.StringpercentEncodeUrl(@NotNull java.lang.CharSequence s)static @NotNull BasedSequenceremoveAll(@NotNull BasedSequence s, @NotNull java.lang.CharSequence remove, @NotNull ReplacedTextMapper textMapper)Replace entities and backslash escapes with literal characters.private static @NotNull BasedSequencereplaceAll(@NotNull java.util.regex.Pattern p, @NotNull BasedSequence s, int startOffset, int endOffset, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)private static @NotNull BasedSequencereplaceAll(@NotNull java.util.regex.Pattern p, @NotNull BasedSequence s, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)private static @NotNull BasedSequencereplaceAll(@NotNull java.util.regex.Pattern p, @NotNull BasedSequence s, @NotNull java.util.List<Range> ranges, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)private static @NotNull java.lang.StringreplaceAll(@NotNull java.util.regex.Pattern p, @NotNull java.lang.CharSequence s, @NotNull Escaping.Replacer replacer)static @NotNull BasedSequenceunescape(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)Replace entities and backslash escapes with literal characters.static @NotNull BasedSequenceunescapeHtml(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)Replace entities and backslash escapes with literal characters.static @NotNull BasedSequenceunescapeHtml(@NotNull BasedSequence s, @NotNull java.util.List<Range> ranges, @NotNull ReplacedTextMapper textMapper)Replace entities and backslash escapes with literal characters.static @NotNull java.lang.StringunescapeHtml(@NotNull java.lang.CharSequence s)Replace entities and backslash escapes with literal characters.static @NotNull java.lang.StringunescapeString(@NotNull java.lang.CharSequence s)Replace entities and backslash escapes with literal characters.static @NotNull java.lang.StringunescapeString(@NotNull java.lang.CharSequence s, boolean unescapeEntities)Replace entities and backslash escapes with literal characters.
-
-
-
Field Detail
-
ESCAPABLE_CHARS
public static final java.lang.String ESCAPABLE_CHARS
- See Also:
- Constant Field Values
-
ESCAPABLE
public static final java.lang.String ESCAPABLE
-
ENTITY
private static final java.lang.String ENTITY
- See Also:
- Constant Field Values
-
BACKSLASH_ONLY
private static final java.util.regex.Pattern BACKSLASH_ONLY
-
ESCAPED_CHAR
private static final java.util.regex.Pattern ESCAPED_CHAR
-
BACKSLASH_OR_AMP
private static final java.util.regex.Pattern BACKSLASH_OR_AMP
-
AMP_ONLY
private static final java.util.regex.Pattern AMP_ONLY
-
ENTITY_OR_ESCAPED_CHAR
private static final java.util.regex.Pattern ENTITY_OR_ESCAPED_CHAR
-
ENTITY_ONLY
private static final java.util.regex.Pattern ENTITY_ONLY
-
XML_SPECIAL
private static final java.lang.String XML_SPECIAL
- See Also:
- Constant Field Values
-
XML_SPECIAL_RE
private static final java.util.regex.Pattern XML_SPECIAL_RE
-
XML_SPECIAL_OR_ENTITY
private static final java.util.regex.Pattern XML_SPECIAL_OR_ENTITY
-
ESCAPE_IN_URI
private static final java.util.regex.Pattern ESCAPE_IN_URI
-
ESCAPE_URI_DECODE
private static final java.util.regex.Pattern ESCAPE_URI_DECODE
-
HEX_DIGITS
static final char[] HEX_DIGITS
-
WHITESPACE
private static final java.util.regex.Pattern WHITESPACE
-
COLLAPSE_WHITESPACE
private static final java.util.regex.Pattern COLLAPSE_WHITESPACE
-
UNSAFE_CHAR_REPLACER
private static final Escaping.Replacer UNSAFE_CHAR_REPLACER
-
COLLAPSE_WHITESPACE_REPLACER
private static final Escaping.Replacer COLLAPSE_WHITESPACE_REPLACER
-
UNESCAPE_REPLACER
private static final Escaping.Replacer UNESCAPE_REPLACER
-
REMOVE_REPLACER
private static final Escaping.Replacer REMOVE_REPLACER
-
ENTITY_REPLACER
private static final Escaping.Replacer ENTITY_REPLACER
-
URL_ENCODE_REPLACER
private static final Escaping.Replacer URL_ENCODE_REPLACER
-
URL_DECODE_REPLACER
private static final Escaping.Replacer URL_DECODE_REPLACER
-
AMP_BACKSLASH_SET
@NotNull public static final @NotNull CharPredicate AMP_BACKSLASH_SET
-
random
private static java.util.Random random
-
-
Method Detail
-
escapeHtml
public static java.lang.String escapeHtml(@NotNull @NotNull java.lang.CharSequence s, boolean preserveEntities)
-
escapeHtml
@NotNull public static @NotNull BasedSequence escapeHtml(@NotNull @NotNull BasedSequence s, boolean preserveEntities, @NotNull @NotNull ReplacedTextMapper textMapper)
-
unescapeString
@NotNull public static @NotNull java.lang.String unescapeString(@NotNull @NotNull java.lang.CharSequence s)Replace entities and backslash escapes with literal characters.- Parameters:
s- string to un-escape- Returns:
- un-escaped string
-
unescapeString
@NotNull public static @NotNull java.lang.String unescapeString(@NotNull @NotNull java.lang.CharSequence s, boolean unescapeEntities)Replace entities and backslash escapes with literal characters.- Parameters:
s- string to un-escapeunescapeEntities- true if HTML entities are to be unescaped- Returns:
- un-escaped string
-
unescape
@NotNull public static @NotNull BasedSequence unescape(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
Replace entities and backslash escapes with literal characters.- Parameters:
s- based sequence to un-escapetextMapper- replaced text mapper to update for the changed text- Returns:
- un-escaped sequence
-
removeAll
@NotNull public static @NotNull BasedSequence removeAll(@NotNull @NotNull BasedSequence s, @NotNull @NotNull java.lang.CharSequence remove, @NotNull @NotNull ReplacedTextMapper textMapper)
Replace entities and backslash escapes with literal characters.- Parameters:
s- sequence being changedremove- string to removetextMapper- replaced text mapper to update for the changed text- Returns:
- un-escaped sequence
-
unescapeHtml
@NotNull public static @NotNull java.lang.String unescapeHtml(@NotNull @NotNull java.lang.CharSequence s)Replace entities and backslash escapes with literal characters.- Parameters:
s- string to un-escape- Returns:
- un-escaped string
-
unescapeHtml
@NotNull public static @NotNull BasedSequence unescapeHtml(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
Replace entities and backslash escapes with literal characters.- Parameters:
s- based sequence to un-escapetextMapper- replaced text mapper to update for the changed text- Returns:
- un-escaped sequence
-
unescapeHtml
@NotNull public static @NotNull BasedSequence unescapeHtml(@NotNull @NotNull BasedSequence s, @NotNull @NotNull java.util.List<Range> ranges, @NotNull @NotNull ReplacedTextMapper textMapper)
Replace entities and backslash escapes with literal characters.- Parameters:
s- based sequence to un-escapetextMapper- replaced text mapper to update for the changed text- Returns:
- un-escaped sequence
-
normalizeEndWithEOL
@NotNull public static @NotNull java.lang.String normalizeEndWithEOL(@NotNull @NotNull java.lang.CharSequence s)Normalize eol: embedded \r and \r\n are converted to \nAppend EOL sequence if sequence does not already end in EOL
- Parameters:
s- sequence to convert- Returns:
- converted sequence
-
normalizeEOL
@NotNull public static @NotNull java.lang.String normalizeEOL(@NotNull @NotNull java.lang.CharSequence s)Normalize eol: embedded \r and \r\n are converted to \n- Parameters:
s- sequence to convert- Returns:
- converted sequence
-
normalizeEOL
@NotNull public static @NotNull java.lang.String normalizeEOL(@NotNull @NotNull java.lang.CharSequence s, boolean endWithEOL)Normalize eol: embedded \r and \r\n are converted to \n- Parameters:
s- sequence to convertendWithEOL- true if an EOL is to be appended to the end of the sequence if not already ending with one.- Returns:
- converted sequence
-
normalizeEndWithEOL
@NotNull public static @NotNull BasedSequence normalizeEndWithEOL(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
Normalize eol: embedded \r and \r\n are converted to \nAppend EOL sequence if sequence does not already end in EOL
- Parameters:
s- sequence to converttextMapper- text mapper to update for the replaced text- Returns:
- converted sequence
-
normalizeEOL
@NotNull public static @NotNull BasedSequence normalizeEOL(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
Normalize eol: embedded \r and \r\n are converted to \n- Parameters:
s- sequence to converttextMapper- text mapper to update for the replaced text- Returns:
- converted sequence
-
normalizeEOL
@NotNull public static @NotNull BasedSequence normalizeEOL(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper, boolean endWithEOL)
Normalize eol: embedded \r and \r\n are converted to \nAppend EOL sequence if sequence does not already end in EOL
- Parameters:
s- sequence to converttextMapper- text mapper to update for the replaced textendWithEOL- whether an EOL is to be appended to the end of the sequence if it does not already end with one.- Returns:
- converted sequence
-
percentEncodeUrl
@NotNull public static @NotNull java.lang.String percentEncodeUrl(@NotNull @NotNull java.lang.CharSequence s)- Parameters:
s- string to encode- Returns:
- encoded string
-
percentEncodeUrl
@NotNull public static @NotNull BasedSequence percentEncodeUrl(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
- Parameters:
s- string to encodetextMapper- text mapper to update for the replaced text- Returns:
- encoded string
-
percentDecodeUrl
@NotNull public static @NotNull java.lang.String percentDecodeUrl(@NotNull @NotNull java.lang.CharSequence s)- Parameters:
s- string to encode- Returns:
- encoded string
-
percentDecodeUrl
@NotNull public static @NotNull BasedSequence percentDecodeUrl(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
- Parameters:
s- string to encodetextMapper- text mapper to update for the replaced text- Returns:
- encoded string
-
normalizeReference
@NotNull public static @NotNull java.lang.String normalizeReference(@NotNull @NotNull java.lang.CharSequence s, boolean changeCase)Normalize the link reference id- Parameters:
s- sequence containing the link reference idchangeCase- if true then reference will be converted to lowercase- Returns:
- normalized link reference id
-
encode
@Nullable private static @Nullable java.lang.String encode(char c)
-
obfuscate
@NotNull public static @NotNull java.lang.String obfuscate(@NotNull @NotNull java.lang.String email, boolean randomize)e-mail obfuscation from pegdown- Parameters:
email- e-mail urlrandomize- true to randomize, false for testing- Returns:
- obfuscated e-mail url
-
normalizeReferenceChars
@NotNull public static @NotNull java.lang.String normalizeReferenceChars(@NotNull @NotNull java.lang.CharSequence s, boolean changeCase)Get a normalized the link reference id from reference charactersWill remove leading ![ or [ and trailing ], collapse multiple whitespaces to a space and optionally convert the id to lowercase.
- Parameters:
s- sequence containing the link reference idchangeCase- if true then reference will be converted to lowercase- Returns:
- normalized link reference id
-
collapseWhitespace
@NotNull public static @NotNull java.lang.String collapseWhitespace(@NotNull @NotNull java.lang.CharSequence s, boolean trim)Collapse regions of multiple white spaces to a single space- Parameters:
s- sequence to processtrim- true if the sequence should also be trimmed- Returns:
- processed sequence
-
collapseWhitespace
@NotNull public static @NotNull BasedSequence collapseWhitespace(@NotNull @NotNull BasedSequence s, @NotNull @NotNull ReplacedTextMapper textMapper)
-
replaceAll
@NotNull private static @NotNull java.lang.String replaceAll(@NotNull @NotNull java.util.regex.Pattern p, @NotNull @NotNull java.lang.CharSequence s, @NotNull @NotNull Escaping.Replacer replacer)
-
replaceAll
@NotNull private static @NotNull BasedSequence replaceAll(@NotNull @NotNull java.util.regex.Pattern p, @NotNull @NotNull BasedSequence s, @NotNull @NotNull Escaping.Replacer replacer, @NotNull @NotNull ReplacedTextMapper textMapper)
-
replaceAll
@NotNull private static @NotNull BasedSequence replaceAll(@NotNull @NotNull java.util.regex.Pattern p, @NotNull @NotNull BasedSequence s, int startOffset, int endOffset, @NotNull @NotNull Escaping.Replacer replacer, @NotNull @NotNull ReplacedTextMapper textMapper)
-
replaceAll
@NotNull private static @NotNull BasedSequence replaceAll(@NotNull @NotNull java.util.regex.Pattern p, @NotNull @NotNull BasedSequence s, @NotNull @NotNull java.util.List<Range> ranges, @NotNull @NotNull Escaping.Replacer replacer, @NotNull @NotNull ReplacedTextMapper textMapper)
-
-