public class JSONCodec extends AbstractIntegerCodec
Encoder
Constructor and Description |
---|
JSONCodec() |
Modifier and Type | Method and Description |
---|---|
protected int |
charToCodepoint(Character ch) |
protected int |
convertToInt(Integer hexDigit) |
Integer |
decodeCharacter(PushbackSequence<Integer> input)
Returns the decoded version of the next character from the input string and advances the
current character in the
PushbackSequence . |
String |
encodeCharacter(char[] immune,
Character c)
Default implementation that should be overridden in specific codecs.
|
String |
encodeCharacter(char[] immune,
int codePoint)
Default codepoint implementation that should be overridden in specific codecs.
|
decode
containsCharacter, encode, encodeCharacter, getHexForNonAlphanumeric, getHexForNonAlphanumeric, toHex, toHex, toOctal
public String encodeCharacter(char[] immune, Character c)
WARNING!!!! Passing a standard char
rather than Character
to this method will resolve to the
AbstractCodec.encodeCharacter( char[], char )
method, which will throw an IllegalArgumentException
instead.
YOU HAVE BEEN WARNED!!!!
Escape special characters in JSON strings.
encodeCharacter will escape the characters Backspace (\b), Form Feed (\f),
Carriage Return (\r), Line Feed (\n), Tab (\t), Double Quote (") and Backslash (\).
If the character is a control character (U+0000 through U+001f), then it will be
Unicode encoded ( through ). If the character is not special or in the
user supplied immune list, then the character is returned unescaped. If the
character is null then an empty string is returned.
WARNING: This method will silently discard an invalid code point according to
the result of Character.isValidCodePoint( int )
method.
encodeCharacter
in interface Codec<Integer>
encodeCharacter
in class AbstractCodec<Integer>
immune
- character array of whitelist characters which should not be encodedc
- the character to encode if not in the immune listpublic String encodeCharacter(char[] immune, int codePoint) throws IllegalArgumentException
Character.isValidCodePoint( int )
method.encodeCharacter
in interface Codec<Integer>
encodeCharacter
in class AbstractCodec<Integer>
immune
- character array of whitelist characters which should not be encodedcodePoint
- the character codepoint to encode if not in the immune listIllegalArgumentException
public Integer decodeCharacter(PushbackSequence<Integer> input) throws IllegalArgumentException
PushbackSequence
. If the current character is not encoded, this
method MUST reset the PushbackString
.
Decodes special characters in encoded JSON strings.
decodeCharacter will decode the encoded character sequences for popular characters
Backspace (\b), Form Feed (\f), Carriage Return (\r), Line Feed (\n), Tab (\t),
Double Quote ("), Forward slash (/) and Backslash (\). The function will also decode
six-character sequences of - . If the character is not encoded then a
null character is returned.decodeCharacter
in interface Codec<Integer>
decodeCharacter
in class AbstractCodec<Integer>
input
- a character sequence to decodeIllegalArgumentException
- if an invalid character sequence is encounteredprotected int charToCodepoint(Character ch)
protected int convertToInt(Integer hexDigit)
Copyright © 2023 The Open Worldwide Application Security Project (OWASP). All rights reserved.