Top Inners Fields Constructors Methods
com.vladsch.flexmark.util.sequence

public Class Escaping

extends Object
Class Inheritance
Imports
com.vladsch.flexmark.util.misc.CharPredicate, .Utils, org.jetbrains.annotations.NotNull, .Nullable, java.nio.charset.StandardCharsets, java.util.List, .Random, java.util.regex.Matcher, .Pattern

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface

Field Summary

Modifier and TypeField and Description
public static final @NotNull CharPredicate
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Escaping.Replacer
private static final String
private static final Pattern
private static final Pattern
private static final Escaping.Replacer
public static final String
public static final String
private static final Pattern
private static final Pattern
private static final Pattern
pack-priv static final char[]
private static Random
private static final Escaping.Replacer
private static final Escaping.Replacer
private static final Escaping.Replacer
private static final Escaping.Replacer
private static final Escaping.Replacer
private static final Pattern
private static final String
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static @NotNull String

Returns:

processed sequence
collapseWhitespace
(@NotNull CharSequence
sequence to process
s
,
boolean
true if the sequence should also be trimmed
trim
)

Collapse regions of multiple white spaces to a single space

public static @NotNull BasedSequence
private static @Nullable String
encode(char c)

public static String
escapeHtml(@NotNull CharSequence s, boolean preserveEntities)

public static @NotNull BasedSequence
escapeHtml(@NotNull BasedSequence s, boolean preserveEntities, @NotNull ReplacedTextMapper textMapper)

public static @NotNull String

Returns:

converted sequence
normalizeEndWithEOL
(@NotNull CharSequence
sequence to convert
s
)

Normalize eol: embedded \r and \r\n are converted to \n

Append EOL sequence if sequence does not already end in EOL

public static @NotNull BasedSequence

Returns:

converted sequence
normalizeEndWithEOL
(@NotNull BasedSequence
sequence to convert
s
,
@NotNull ReplacedTextMapper
text mapper to update for the replaced text
textMapper
)

Normalize eol: embedded \r and \r\n are converted to \n

Append EOL sequence if sequence does not already end in EOL

public static @NotNull String

Returns:

converted sequence
normalizeEOL
(@NotNull CharSequence
sequence to convert
s
)

Normalize eol: embedded \r and \r\n are converted to \n

public static @NotNull String

Returns:

converted sequence
normalizeEOL
(@NotNull CharSequence
sequence to convert
s
,
boolean
true if an EOL is to be appended to the end of the sequence if not already ending with one.
endWithEOL
)

Normalize eol: embedded \r and \r\n are converted to \n

public static @NotNull BasedSequence

Returns:

converted sequence
normalizeEOL
(@NotNull BasedSequence
sequence to convert
s
,
@NotNull ReplacedTextMapper
text mapper to update for the replaced text
textMapper
)

Normalize eol: embedded \r and \r\n are converted to \n

public static @NotNull BasedSequence

Returns:

converted sequence
normalizeEOL
(@NotNull BasedSequence
sequence to convert
s
,
@NotNull ReplacedTextMapper
text mapper to update for the replaced text
textMapper
,
boolean
whether an EOL is to be appended to the end of the sequence if it does not already end with one.
endWithEOL
)

Normalize eol: embedded \r and \r\n are converted to \n

Append EOL sequence if sequence does not already end in EOL

public static @NotNull String

Returns:

normalized link reference id
normalizeReference
(@NotNull CharSequence
sequence containing the link reference id
s
,
boolean
if true then reference will be converted to lowercase
changeCase
)

Normalize the link reference id

public static @NotNull String

Returns:

normalized link reference id
normalizeReferenceChars
(@NotNull CharSequence
sequence containing the link reference id
s
,
boolean
if true then reference will be converted to lowercase
changeCase
)

Get a normalized the link reference id from reference characters

Will remove leading ![ or [ and trailing ], collapse multiple whitespaces to a space and optionally convert the id to lowercase.

public static @NotNull String

Returns:

obfuscated e-mail url
obfuscate
(@NotNull String
e-mail url
email
,
boolean
true to randomize, false for testing
randomize
)

e-mail obfuscation from pegdown

public static @NotNull String

Returns:

encoded string
percentDecodeUrl
(@NotNull CharSequence
string to encode
s
)

public static @NotNull BasedSequence

Returns:

encoded string
percentDecodeUrl
(@NotNull BasedSequence
string to encode
s
,
@NotNull ReplacedTextMapper
text mapper to update for the replaced text
textMapper
)

public static @NotNull String

Returns:

encoded string
percentEncodeUrl
(@NotNull CharSequence
string to encode
s
)

public static @NotNull BasedSequence

Returns:

encoded string
percentEncodeUrl
(@NotNull BasedSequence
string to encode
s
,
@NotNull ReplacedTextMapper
text mapper to update for the replaced text
textMapper
)

public static @NotNull BasedSequence

Returns:

un-escaped sequence
removeAll
(@NotNull BasedSequence
sequence being changed
s
,
@NotNull CharSequence
string to remove
remove
,
@NotNull ReplacedTextMapper
replaced text mapper to update for the changed text
textMapper
)

Replace entities and backslash escapes with literal characters.

private static @NotNull String
private static @NotNull BasedSequence
private static @NotNull BasedSequence
replaceAll(@NotNull Pattern p, @NotNull BasedSequence s, int startOffset, int endOffset, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)

private static @NotNull BasedSequence
public static @NotNull BasedSequence

Returns:

un-escaped sequence
unescape
(@NotNull BasedSequence
based sequence to un-escape
s
,
@NotNull ReplacedTextMapper
replaced text mapper to update for the changed text
textMapper
)

Replace entities and backslash escapes with literal characters.

public static @NotNull String

Returns:

un-escaped string
unescapeHtml
(@NotNull CharSequence
string to un-escape
s
)

Replace entities and backslash escapes with literal characters.

public static @NotNull BasedSequence

Returns:

un-escaped sequence
unescapeHtml
(@NotNull BasedSequence
based sequence to un-escape
s
,
@NotNull ReplacedTextMapper
replaced text mapper to update for the changed text
textMapper
)

Replace entities and backslash escapes with literal characters.

public static @NotNull BasedSequence

Returns:

un-escaped sequence
unescapeHtml
(@NotNull BasedSequence
based sequence to un-escape
s
,
@NotNull List<Range> ranges, @NotNull ReplacedTextMapper
replaced text mapper to update for the changed text
textMapper
)

Replace entities and backslash escapes with literal characters.

public static @NotNull String

Returns:

un-escaped string
unescapeString
(@NotNull CharSequence
string to un-escape
s
)

Replace entities and backslash escapes with literal characters.

public static @NotNull String

Returns:

un-escaped string
unescapeString
(@NotNull CharSequence
string to un-escape
s
,
boolean
true if HTML entities are to be unescaped
unescapeEntities
)

Replace entities and backslash escapes with literal characters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AMP_BACKSLASH_SETback to summary
public static final @NotNull CharPredicate AMP_BACKSLASH_SET
Annotations
@NotNull
AMP_ONLYback to summary
private static final Pattern AMP_ONLY
BACKSLASH_ONLYback to summary
private static final Pattern BACKSLASH_ONLY
BACKSLASH_OR_AMPback to summary
private static final Pattern BACKSLASH_OR_AMP
COLLAPSE_WHITESPACEback to summary
private static final Pattern COLLAPSE_WHITESPACE
COLLAPSE_WHITESPACE_REPLACERback to summary
private static final Escaping.Replacer COLLAPSE_WHITESPACE_REPLACER
ENTITYback to summary
private static final String ENTITY
ENTITY_ONLYback to summary
private static final Pattern ENTITY_ONLY
ENTITY_OR_ESCAPED_CHARback to summary
private static final Pattern ENTITY_OR_ESCAPED_CHAR
ENTITY_REPLACERback to summary
private static final Escaping.Replacer ENTITY_REPLACER
ESCAPABLEback to summary
public static final String ESCAPABLE
ESCAPABLE_CHARSback to summary
public static final String ESCAPABLE_CHARS
ESCAPE_IN_URIback to summary
private static final Pattern ESCAPE_IN_URI
ESCAPE_URI_DECODEback to summary
private static final Pattern ESCAPE_URI_DECODE
ESCAPED_CHARback to summary
private static final Pattern ESCAPED_CHAR
HEX_DIGITSback to summary
pack-priv static final char[] HEX_DIGITS
randomback to summary
private static Random random
REMOVE_REPLACERback to summary
private static final Escaping.Replacer REMOVE_REPLACER
UNESCAPE_REPLACERback to summary
private static final Escaping.Replacer UNESCAPE_REPLACER
UNSAFE_CHAR_REPLACERback to summary
private static final Escaping.Replacer UNSAFE_CHAR_REPLACER
URL_DECODE_REPLACERback to summary
private static final Escaping.Replacer URL_DECODE_REPLACER
URL_ENCODE_REPLACERback to summary
private static final Escaping.Replacer URL_ENCODE_REPLACER
WHITESPACEback to summary
private static final Pattern WHITESPACE
XML_SPECIALback to summary
private static final String XML_SPECIAL
XML_SPECIAL_OR_ENTITYback to summary
private static final Pattern XML_SPECIAL_OR_ENTITY
XML_SPECIAL_REback to summary
private static final Pattern XML_SPECIAL_RE

Constructor Detail

Escapingback to summary
public Escaping()

Method Detail

collapseWhitespaceback to summary
public static @NotNull String collapseWhitespace(@NotNull CharSequence s, boolean trim)

Collapse regions of multiple white spaces to a single space

Parameters
s:@NotNull CharSequence

sequence to process

trim:boolean

true if the sequence should also be trimmed

Returns:@NotNull String

processed sequence

Annotations
@NotNull
collapseWhitespaceback to summary
public static @NotNull BasedSequence collapseWhitespace(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)
Annotations
@NotNull
encodeback to summary
private static @Nullable String encode(char c)
Annotations
@Nullable
escapeHtmlback to summary
public static String escapeHtml(@NotNull CharSequence s, boolean preserveEntities)
escapeHtmlback to summary
public static @NotNull BasedSequence escapeHtml(@NotNull BasedSequence s, boolean preserveEntities, @NotNull ReplacedTextMapper textMapper)
Annotations
@NotNull
normalizeEndWithEOLback to summary
public static @NotNull String normalizeEndWithEOL(@NotNull CharSequence s)

Normalize eol: embedded \r and \r\n are converted to \n

Append EOL sequence if sequence does not already end in EOL

Parameters
s:@NotNull CharSequence

sequence to convert

Returns:@NotNull String

converted sequence

Annotations
@NotNull
normalizeEndWithEOLback to summary
public static @NotNull BasedSequence normalizeEndWithEOL(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)

Normalize eol: embedded \r and \r\n are converted to \n

Append EOL sequence if sequence does not already end in EOL

Parameters
s:@NotNull BasedSequence

sequence to convert

textMapper:@NotNull ReplacedTextMapper

text mapper to update for the replaced text

Returns:@NotNull BasedSequence

converted sequence

Annotations
@NotNull
normalizeEOLback to summary
public static @NotNull String normalizeEOL(@NotNull CharSequence s)

Normalize eol: embedded \r and \r\n are converted to \n

Parameters
s:@NotNull CharSequence

sequence to convert

Returns:@NotNull String

converted sequence

Annotations
@NotNull
normalizeEOLback to summary
public static @NotNull String normalizeEOL(@NotNull CharSequence s, boolean endWithEOL)

Normalize eol: embedded \r and \r\n are converted to \n

Parameters
s:@NotNull CharSequence

sequence to convert

endWithEOL:boolean

true if an EOL is to be appended to the end of the sequence if not already ending with one.

Returns:@NotNull String

converted sequence

Annotations
@NotNull
normalizeEOLback to summary
public static @NotNull BasedSequence normalizeEOL(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)

Normalize eol: embedded \r and \r\n are converted to \n

Parameters
s:@NotNull BasedSequence

sequence to convert

textMapper:@NotNull ReplacedTextMapper

text mapper to update for the replaced text

Returns:@NotNull BasedSequence

converted sequence

Annotations
@NotNull
normalizeEOLback to summary
public static @NotNull BasedSequence normalizeEOL(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper, boolean endWithEOL)

Normalize eol: embedded \r and \r\n are converted to \n

Append EOL sequence if sequence does not already end in EOL

Parameters
s:@NotNull BasedSequence

sequence to convert

textMapper:@NotNull ReplacedTextMapper

text mapper to update for the replaced text

endWithEOL:boolean

whether an EOL is to be appended to the end of the sequence if it does not already end with one.

Returns:@NotNull BasedSequence

converted sequence

Annotations
@NotNull
normalizeReferenceback to summary
public static @NotNull String normalizeReference(@NotNull CharSequence s, boolean changeCase)

Normalize the link reference id

Parameters
s:@NotNull CharSequence

sequence containing the link reference id

changeCase:boolean

if true then reference will be converted to lowercase

Returns:@NotNull String

normalized link reference id

Annotations
@NotNull
normalizeReferenceCharsback to summary
public static @NotNull String normalizeReferenceChars(@NotNull CharSequence s, boolean changeCase)

Get a normalized the link reference id from reference characters

Will remove leading ![ or [ and trailing ], collapse multiple whitespaces to a space and optionally convert the id to lowercase.

Parameters
s:@NotNull CharSequence

sequence containing the link reference id

changeCase:boolean

if true then reference will be converted to lowercase

Returns:@NotNull String

normalized link reference id

Annotations
@NotNull
obfuscateback to summary
public static @NotNull String obfuscate(@NotNull String email, boolean randomize)

e-mail obfuscation from pegdown

Parameters
email:@NotNull String

e-mail url

randomize:boolean

true to randomize, false for testing

Returns:@NotNull String

obfuscated e-mail url

Annotations
@NotNull
percentDecodeUrlback to summary
public static @NotNull String percentDecodeUrl(@NotNull CharSequence s)
Parameters
s:@NotNull CharSequence

string to encode

Returns:@NotNull String

encoded string

Annotations
@NotNull
percentDecodeUrlback to summary
public static @NotNull BasedSequence percentDecodeUrl(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)
Parameters
s:@NotNull BasedSequence

string to encode

textMapper:@NotNull ReplacedTextMapper

text mapper to update for the replaced text

Returns:@NotNull BasedSequence

encoded string

Annotations
@NotNull
percentEncodeUrlback to summary
public static @NotNull String percentEncodeUrl(@NotNull CharSequence s)
Parameters
s:@NotNull CharSequence

string to encode

Returns:@NotNull String

encoded string

Annotations
@NotNull
percentEncodeUrlback to summary
public static @NotNull BasedSequence percentEncodeUrl(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)
Parameters
s:@NotNull BasedSequence

string to encode

textMapper:@NotNull ReplacedTextMapper

text mapper to update for the replaced text

Returns:@NotNull BasedSequence

encoded string

Annotations
@NotNull
removeAllback to summary
public static @NotNull BasedSequence removeAll(@NotNull BasedSequence s, @NotNull CharSequence remove, @NotNull ReplacedTextMapper textMapper)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull BasedSequence

sequence being changed

remove:@NotNull CharSequence

string to remove

textMapper:@NotNull ReplacedTextMapper

replaced text mapper to update for the changed text

Returns:@NotNull BasedSequence

un-escaped sequence

Annotations
@NotNull
replaceAllback to summary
private static @NotNull String replaceAll(@NotNull Pattern p, @NotNull CharSequence s, @NotNull Escaping.Replacer replacer)
Annotations
@NotNull
replaceAllback to summary
private static @NotNull BasedSequence replaceAll(@NotNull Pattern p, @NotNull BasedSequence s, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)
Annotations
@NotNull
replaceAllback to summary
private static @NotNull BasedSequence replaceAll(@NotNull Pattern p, @NotNull BasedSequence s, int startOffset, int endOffset, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)
Annotations
@NotNull
replaceAllback to summary
private static @NotNull BasedSequence replaceAll(@NotNull Pattern p, @NotNull BasedSequence s, @NotNull List<Range> ranges, @NotNull Escaping.Replacer replacer, @NotNull ReplacedTextMapper textMapper)
Annotations
@NotNull
unescapeback to summary
public static @NotNull BasedSequence unescape(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull BasedSequence

based sequence to un-escape

textMapper:@NotNull ReplacedTextMapper

replaced text mapper to update for the changed text

Returns:@NotNull BasedSequence

un-escaped sequence

Annotations
@NotNull
unescapeHtmlback to summary
public static @NotNull String unescapeHtml(@NotNull CharSequence s)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull CharSequence

string to un-escape

Returns:@NotNull String

un-escaped string

Annotations
@NotNull
unescapeHtmlback to summary
public static @NotNull BasedSequence unescapeHtml(@NotNull BasedSequence s, @NotNull ReplacedTextMapper textMapper)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull BasedSequence

based sequence to un-escape

textMapper:@NotNull ReplacedTextMapper

replaced text mapper to update for the changed text

Returns:@NotNull BasedSequence

un-escaped sequence

Annotations
@NotNull
unescapeHtmlback to summary
public static @NotNull BasedSequence unescapeHtml(@NotNull BasedSequence s, @NotNull List<Range> ranges, @NotNull ReplacedTextMapper textMapper)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull BasedSequence

based sequence to un-escape

textMapper:@NotNull ReplacedTextMapper

replaced text mapper to update for the changed text

Returns:@NotNull BasedSequence

un-escaped sequence

Annotations
@NotNull
unescapeStringback to summary
public static @NotNull String unescapeString(@NotNull CharSequence s)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull CharSequence

string to un-escape

Returns:@NotNull String

un-escaped string

Annotations
@NotNull
unescapeStringback to summary
public static @NotNull String unescapeString(@NotNull CharSequence s, boolean unescapeEntities)

Replace entities and backslash escapes with literal characters.

Parameters
s:@NotNull CharSequence

string to un-escape

unescapeEntities:boolean

true if HTML entities are to be unescaped

Returns:@NotNull String

un-escaped string

Annotations
@NotNull
com.vladsch.flexmark.util.sequence back to summary

pack-priv Interface Escaping.Replacer


Method Summary

Modifier and TypeMethod and Description
public void
public void
replace(@NotNull BasedSequence s, int startIndex, int endIndex, @NotNull ReplacedTextMapper replacedTextMapper)

Method Detail

replaceback to summary
public void replace(@NotNull String s, @NotNull StringBuilder sb)
replaceback to summary
public void replace(@NotNull BasedSequence s, int startIndex, int endIndex, @NotNull ReplacedTextMapper replacedTextMapper)