Top Fields Constructors Methods
org.jcodings

public abstract Class Encoding

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
org.jcodings.AbstractEncoding
Imports
java.nio.charset.Charset, org.jcodings.ascii.AsciiTables, org.jcodings.constants.CharacterType, org.jcodings.exception.EncodingException, .EncodingError, .ErrorMessages, .InternalException, org.jcodings.util.BytesHash

Field Summary

Modifier and TypeField and Description
public static final int
private Charset
private static int
private int
private int
private boolean
private boolean
private final boolean
private final boolean
protected boolean
protected boolean
protected final int
protected final int
private byte[]
public static final byte
private String

Constructor Summary

AccessConstructor and Description
protected
Encoding(String name, int minLength, int maxLength)

Method Summary

Modifier and TypeMethod and Description
public abstract void
applyAllCaseFold(int
case fold flag
flag
,
ApplyAllCaseFoldFunction
case folding functor (look at: ApplyCaseFold)
fun
,
Object
case folding functor argument (look at: ApplyCaseFoldArg) Oniguruma equivalent: apply_all_case_fold
arg
)

Expand case folds given a character class (used for case insensitive matching)

public static byte
asciiToLower(int c)

public static byte
asciiToUpper(int c)

public abstract CaseFoldCodeItem[]
caseFoldCodesByString(int flag, byte[] bytes, int p, int end)

Expand AST string nodes into their folded alternatives (look at: Analyser.expandCaseFoldString) Oniguruma equivalent: get_case_fold_codes_by_str

public abstract int
caseMap(IntHolder flagP, byte[] bytes, IntHolder pp, int end, byte[] to, int toP, int toEnd)

Oniguruma equivalent: case_map

public abstract int

Returns:

character length for the given code point Oniguruma equivalent: code_to_mbc
codeToMbc
(int code, byte[] bytes, int p)

Extracts code point into it's multibyte representation

public abstract int
codeToMbcLength(int code)

Returns character length given a code point Oniguruma equivalent: code_to_mbclen

public abstract int[]
ctypeCodeRange(int ctype, IntHolder sbOut)

Returns code range for a given character type Oniguruma equivalent: get_ctype_code_range

public static int
digitVal(int code)

public final boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Charset
getCharset()

If this encoding is capable of being represented by a Java Charset then provide it.

public String

Returns:

the name of the equivalent Java Charset for this encoding
getCharsetName
()

The name of the equivalent Java Charset for this encoding.

public final int
public final byte[]
public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public final boolean
isAlnum(int code)

public final boolean
isAlpha(int code)

public static boolean
isAscii(int code)

public static boolean
isAscii(byte b)

public final boolean
public final boolean
isBlank(int code)

public final boolean
isCntrl(int code)

public abstract boolean
isCodeCType(int
a code point of a character
code
,
int
a character type to check against Oniguruma equivalent: is_code_ctype
ctype
)

Perform a check whether given code is of given character type (e.g. used by isWord(someByte) and similar methods)

public final boolean
isDigit(int code)

public final boolean
public final boolean
public final boolean
isGraph(int code)

public final boolean
isLower(int code)

public static boolean
isMbcAscii(byte b)

public boolean
isMbcCrnl(byte[] bytes, int p, int end)

public final boolean
isMbcHead(byte[] bytes, int p, int end)

public final boolean
isMbcWord(byte[] bytes, int p, int end)

public abstract boolean
isNewLine(byte[] bytes, int p, int end)

Returns true if bytes[p] is a head of a new line character Oniguruma equivalent: is_mbc_newline

public final boolean
isNewLine(int code)

public final boolean
isPrint(int code)

public final boolean
isPunct(int code)

public abstract boolean
isReverseMatchAllowed(byte[] bytes, int p, int end)

Returns true if it's safe to use reversal Boyer-Moore search fail fast algorithm Oniguruma equivalent: is_allowed_reverse_match

public final boolean
isSbWord(int code)

public final boolean
public final boolean
isSpace(int code)

public final boolean
public final boolean
isUpper(int code)

public final boolean
public final boolean
isWord(int code)

public static boolean
isWordGraphPrint(int ctype)

public final boolean
isXDigit(int code)

public abstract int
leftAdjustCharHead(byte[]
byte stream
bytes
,
int
position
p
,
int
stop
s
,
int
end
end
)

Seeks the previous character head in a stream Oniguruma equivalent: left_adjust_char_head

public abstract int
length(byte
Character head Oniguruma equivalent: mbc_enc_len To be deprecated very soon (use length(byte[]bytes, int p, int end) version)
c
)

Returns character length given character head returns 1 for singlebyte encodings or performs direct length table lookup for multibyte ones.

public abstract int

Returns:

0 Never > 0 Valid character, length returned -1 Illegal/malformed character < -1 (-1 - n) Number of missing bytes for character in p...end range Oniguruma equivalent: mbc_enc_len modified for 1.9 purposes,
length
(byte[] bytes, int p, int end)

Returns character length given stream, character position and stream end returns 1 for singlebyte encodings or performs sanity validations for multibyte ones and returns the character length, missing characters in the stream otherwise

public static Encoding
load(String name)

public static Encoding
load(String name, String pkg)

public final int
maxLength()

Returns maximum character byte length that can appear in an encoding Oniguruma equivalent: max_enc_len

public final int
maxLengthDistance()

Deprecated
public abstract int
mbcCaseFold(int
case fold flag
flag
,
byte[] bytes, IntHolder
an IntHolder that points at character head
pp
,
int end, byte[]
a buffer where to extract case folded character Oniguruma equivalent: mbc_case_fold
to
)

Performs case folding for a character at bytes[pp.value]

public final int
mbcodeStartPosition()

Deprecated
public abstract int
mbcToCode(byte[] bytes, int p, int end)

Returns code point for a character Oniguruma equivalent: mbc_to_code

public final int
minLength()

Returns minimum character byte length that can appear in an encoding Oniguruma equivalent: min_enc_len

public static int
odigitVal(int code)

public final int
prevCharHead(byte[] bytes, int p, int s, int end)

public abstract int
propertyNameToCType(byte[] bytes, int p, int end)

Returns character type given character type name (used when e.g. \p{Alpha}) Oniguruma equivalent: property_name_to_ctype

pack-priv Encoding
replicate(byte[] name)

public final int
rightAdjustCharHead(byte[] bytes, int p, int s, int end)

public final int
rightAdjustCharHeadWithPrev(byte[] bytes, int p, int s, int end, IntHolder prev)

protected final void
protected final void
protected final void
setName(byte[] name)

public final int
step(byte[] bytes, int p, int end, int n)

public final int
stepBack(byte[] bytes, int p, int s, int end, int n)

public final int
strByteLengthNull(byte[] bytes, int p, int end)

public abstract int
strCodeAt(byte[] bytes, int p, int end, int index)

public abstract int
strLength(byte[] bytes, int p, int end)

public final int
strLengthNull(byte[] bytes, int p, int end)

public final int
strNCmp(byte[] bytes, int p, int end, byte[] ascii, int asciiP, int n)

public byte[]

Returns:

lower case table
toLowerCaseTable
()

Returns lower case table if it's safe to use it directly, otherwise null Used for fast case insensitive matching for some singlebyte encodings

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final int
xdigitVal(int code)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CHAR_INVALIDback to summary
public static final int CHAR_INVALID
charsetback to summary
private Charset charset
countback to summary
private static int count
hashCodeback to summary
private int hashCode
indexback to summary
private int index
isAsciiCompatibleback to summary
private boolean isAsciiCompatible
isDummyback to summary
private boolean isDummy
isFixedWidthback to summary
private final boolean isFixedWidth
isSingleByteback to summary
private final boolean isSingleByte
isUnicodeback to summary
protected boolean isUnicode
isUTF8back to summary
protected boolean isUTF8
maxLengthback to summary
protected final int maxLength
minLengthback to summary
protected final int minLength
nameback to summary
private byte[] name
NEW_LINEback to summary
public static final byte NEW_LINE
stringNameback to summary
private String stringName

Constructor Detail

Encodingback to summary
protected Encoding(String name, int minLength, int maxLength)

Method Detail

applyAllCaseFoldback to summary
public abstract void applyAllCaseFold(int flag, ApplyAllCaseFoldFunction fun, Object arg)

Expand case folds given a character class (used for case insensitive matching)

Parameters
flag:int

case fold flag

fun:ApplyAllCaseFoldFunction

case folding functor (look at: ApplyCaseFold)

arg:Object

case folding functor argument (look at: ApplyCaseFoldArg) Oniguruma equivalent: apply_all_case_fold

asciiToLowerback to summary
public static byte asciiToLower(int c)
asciiToUpperback to summary
public static byte asciiToUpper(int c)
caseFoldCodesByStringback to summary
public abstract CaseFoldCodeItem[] caseFoldCodesByString(int flag, byte[] bytes, int p, int end)

Expand AST string nodes into their folded alternatives (look at: Analyser.expandCaseFoldString) Oniguruma equivalent: get_case_fold_codes_by_str

caseMapback to summary
public abstract int caseMap(IntHolder flagP, byte[] bytes, IntHolder pp, int end, byte[] to, int toP, int toEnd)

Oniguruma equivalent: case_map

codeToMbcback to summary
public abstract int codeToMbc(int code, byte[] bytes, int p)

Extracts code point into it's multibyte representation

Returns:int

character length for the given code point Oniguruma equivalent: code_to_mbc

codeToMbcLengthback to summary
public abstract int codeToMbcLength(int code)

Returns character length given a code point Oniguruma equivalent: code_to_mbclen

ctypeCodeRangeback to summary
public abstract int[] ctypeCodeRange(int ctype, IntHolder sbOut)

Returns code range for a given character type Oniguruma equivalent: get_ctype_code_range

digitValback to summary
public static int digitVal(int code)
equalsback to summary
public final boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCharsetback to summary
public Charset getCharset()

If this encoding is capable of being represented by a Java Charset then provide it. Otherwise this will raise a CharsetNotFound error via the JDK APIs. To reduce cases like jruby/jruby#4716, we always attempt to find a charset here, and default to using the encoding name which is never null. Either the encoding will exist in the JDK or it will fail hard, rather than propagating a null Charset. Encodings with names different than those found in the JDK can override this getCharsetName to provide that name or getCharset to return the right Charset.

getCharsetNameback to summary
public String getCharsetName()

The name of the equivalent Java Charset for this encoding. Defaults to the name of the encoding. Subclasses can override this to provide a different name.

Returns:String

the name of the equivalent Java Charset for this encoding

getIndexback to summary
public final int getIndex()
getNameback to summary
public final byte[] getName()
hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isAlnumback to summary
public final boolean isAlnum(int code)
isAlphaback to summary
public final boolean isAlpha(int code)
isAsciiback to summary
public static boolean isAscii(int code)
isAsciiback to summary
public static boolean isAscii(byte b)
isAsciiCompatibleback to summary
public final boolean isAsciiCompatible()
isBlankback to summary
public final boolean isBlank(int code)
isCntrlback to summary
public final boolean isCntrl(int code)
isCodeCTypeback to summary
public abstract boolean isCodeCType(int code, int ctype)

Perform a check whether given code is of given character type (e.g. used by isWord(someByte) and similar methods)

Parameters
code:int

a code point of a character

ctype:int

a character type to check against Oniguruma equivalent: is_code_ctype

isDigitback to summary
public final boolean isDigit(int code)
isDummyback to summary
public final boolean isDummy()
isFixedWidthback to summary
public final boolean isFixedWidth()
isGraphback to summary
public final boolean isGraph(int code)
isLowerback to summary
public final boolean isLower(int code)
isMbcAsciiback to summary
public static boolean isMbcAscii(byte b)
isMbcCrnlback to summary
public boolean isMbcCrnl(byte[] bytes, int p, int end)
isMbcHeadback to summary
public final boolean isMbcHead(byte[] bytes, int p, int end)
isMbcWordback to summary
public final boolean isMbcWord(byte[] bytes, int p, int end)
isNewLineback to summary
public abstract boolean isNewLine(byte[] bytes, int p, int end)

Returns true if bytes[p] is a head of a new line character Oniguruma equivalent: is_mbc_newline

isNewLineback to summary
public final boolean isNewLine(int code)
isPrintback to summary
public final boolean isPrint(int code)
isPunctback to summary
public final boolean isPunct(int code)
isReverseMatchAllowedback to summary
public abstract boolean isReverseMatchAllowed(byte[] bytes, int p, int end)

Returns true if it's safe to use reversal Boyer-Moore search fail fast algorithm Oniguruma equivalent: is_allowed_reverse_match

isSbWordback to summary
public final boolean isSbWord(int code)
isSingleByteback to summary
public final boolean isSingleByte()
isSpaceback to summary
public final boolean isSpace(int code)
isUnicodeback to summary
public final boolean isUnicode()
isUpperback to summary
public final boolean isUpper(int code)
isUTF8back to summary
public final boolean isUTF8()
isWordback to summary
public final boolean isWord(int code)
isWordGraphPrintback to summary
public static boolean isWordGraphPrint(int ctype)
isXDigitback to summary
public final boolean isXDigit(int code)
leftAdjustCharHeadback to summary
public abstract int leftAdjustCharHead(byte[] bytes, int p, int s, int end)

Seeks the previous character head in a stream Oniguruma equivalent: left_adjust_char_head

Parameters
bytes:byte[]

byte stream

p:int

position

s:int

stop

end:int

end

lengthback to summary
public abstract int length(byte c)

Returns character length given character head returns 1 for singlebyte encodings or performs direct length table lookup for multibyte ones.

Parameters
c:byte

Character head Oniguruma equivalent: mbc_enc_len To be deprecated very soon (use length(byte[]bytes, int p, int end) version)

lengthback to summary
public abstract int length(byte[] bytes, int p, int end)

Returns character length given stream, character position and stream end returns 1 for singlebyte encodings or performs sanity validations for multibyte ones and returns the character length, missing characters in the stream otherwise

Returns:int

0 Never > 0 Valid character, length returned -1 Illegal/malformed character < -1 (-1 - n) Number of missing bytes for character in p...end range Oniguruma equivalent: mbc_enc_len modified for 1.9 purposes,

loadback to summary
public static Encoding load(String name)
loadback to summary
public static Encoding load(String name, String pkg)
maxLengthback to summary
public final int maxLength()

Returns maximum character byte length that can appear in an encoding Oniguruma equivalent: max_enc_len

maxLengthDistanceback to summary
public final int maxLengthDistance()

Deprecated

Annotations
@Deprecated
mbcCaseFoldback to summary
public abstract int mbcCaseFold(int flag, byte[] bytes, IntHolder pp, int end, byte[] to)

Performs case folding for a character at bytes[pp.value]

Parameters
flag:int

case fold flag

pp:IntHolder

an IntHolder that points at character head

to:byte[]

a buffer where to extract case folded character Oniguruma equivalent: mbc_case_fold

mbcodeStartPositionback to summary
public final int mbcodeStartPosition()

Deprecated

Annotations
@Deprecated
mbcToCodeback to summary
public abstract int mbcToCode(byte[] bytes, int p, int end)

Returns code point for a character Oniguruma equivalent: mbc_to_code

minLengthback to summary
public final int minLength()

Returns minimum character byte length that can appear in an encoding Oniguruma equivalent: min_enc_len

odigitValback to summary
public static int odigitVal(int code)
prevCharHeadback to summary
public final int prevCharHead(byte[] bytes, int p, int s, int end)
propertyNameToCTypeback to summary
public abstract int propertyNameToCType(byte[] bytes, int p, int end)

Returns character type given character type name (used when e.g. \p{Alpha}) Oniguruma equivalent: property_name_to_ctype

replicateback to summary
pack-priv Encoding replicate(byte[] name)
rightAdjustCharHeadback to summary
public final int rightAdjustCharHead(byte[] bytes, int p, int s, int end)
rightAdjustCharHeadWithPrevback to summary
public final int rightAdjustCharHeadWithPrev(byte[] bytes, int p, int s, int end, IntHolder prev)
setDummyback to summary
protected final void setDummy()
setNameback to summary
protected final void setName(String name)
setNameback to summary
protected final void setName(byte[] name)
stepback to summary
public final int step(byte[] bytes, int p, int end, int n)
stepBackback to summary
public final int stepBack(byte[] bytes, int p, int s, int end, int n)
strByteLengthNullback to summary
public final int strByteLengthNull(byte[] bytes, int p, int end)
strCodeAtback to summary
public abstract int strCodeAt(byte[] bytes, int p, int end, int index)
strLengthback to summary
public abstract int strLength(byte[] bytes, int p, int end)
strLengthNullback to summary
public final int strLengthNull(byte[] bytes, int p, int end)
strNCmpback to summary
public final int strNCmp(byte[] bytes, int p, int end, byte[] ascii, int asciiP, int n)
toLowerCaseTableback to summary
public byte[] toLowerCaseTable()

Returns lower case table if it's safe to use it directly, otherwise null Used for fast case insensitive matching for some singlebyte encodings

Returns:byte[]

lower case table

toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
xdigitValback to summary
public final int xdigitVal(int code)