APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.lang

public final Class CaseFolding

extends Object
Class Inheritance
Imports
java.util.Arrays, .Map, java.util.stream.Collectors, .IntStream

Utility class that handles Unicode case folding properties defined in CasingFolding.txt, including 1:M full case folding.

Field Summary

Modifier and TypeField and Description
private static final int[]
private static final int[][]
private static final long[]
private static final int[]
private static final Map<Integer, Integer>
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

a long value representing the case-folded form of the input code point, encoded as TBD
fold
(int
the Unicode code point to fold
cp
)

Returns the case-folded form of the specified code point according to the Unicode case folding mappings.

public static int[]

Returns:

a int[] containing the all simple case equivalents of characters in the range, excluding those already in the range
getClassRangeClosingCharacters
(int
the starting code point of the character range
start
,
int
the ending code point of the character range
end
)

Returns an expansion set to "close" a given regex Unicode character class range for case-sensitive matching, according to the Simple Loose Matches rule defined in Unicode Technical Standard #18: Unicode Regular Expressions.

private static long
getDefined(int cp)

private static int[][]
hashKeys(int[] keys)

public static boolean

Returns:

true if the given code point has a case folding mapping entry defined in (@code caseFoldingMap}, false otherwise
isDefined
(int
the Unicode code point to test
cp
)

Tests whether the specified code point has a folding mapping entry defined.

public static boolean
isSingleCodePoint(long fold)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CASE_FOLDING_CPSback to summary
private static final int[] CASE_FOLDING_CPS
CASE_FOLDING_HASHESback to summary
private static final int[][] CASE_FOLDING_HASHES
CASE_FOLDING_VALUESback to summary
private static final long[] CASE_FOLDING_VALUES
expanded_case_cpsback to summary
private static final int[] expanded_case_cps
expanded_case_mapback to summary
private static final Map<Integer, Integer> expanded_case_map
HASH_CPback to summary
private static final int HASH_CP
HASH_INDEXback to summary
private static final int HASH_INDEX
HASH_NEXTback to summary
private static final int HASH_NEXT

Constructor Detail

CaseFoldingback to summary
private CaseFolding()

Method Detail

foldback to summary
public static long fold(int cp)

Returns the case-folded form of the specified code point according to the Unicode case folding mappings.

If the code point has no case folding mapping defined, this method returns the original code point. Possible combinations of the returning case-folding form as a long value +---+---------+--------+---------+--------+--------+ | 1:1 mapping | 0000 | 0000 | 000x | xxxx | 0041 => 0061 or 1E921 => 1E943 +---+---------+--------+---------+--------+--------+ | 1:2 mapping | 0002 | 0000 | xxxx | xxxx | FB02 => 0066 006C +---+---------+--------+---------+--------+--------+ | 1:3 mapping | 0003 | xxxx | xxxx | xxxx | FB03 => 0066 0066 0069 +---+---------+--------+---------+--------+--------+

Parameters
cp:int

the Unicode code point to fold

Returns:long

a long value representing the case-folded form of the input code point, encoded as TBD

getClassRangeClosingCharactersback to summary
public static int[] getClassRangeClosingCharacters(int start, int end)

Returns an expansion set to "close" a given regex Unicode character class range for case-sensitive matching, according to the Simple Loose Matches rule defined in Unicode Technical Standard #18: Unicode Regular Expressions.

To conform with Level 1 of UTS #18, specifically RL1.5: Simple Loose Matches, simple case folding must be applied to literals and (optionally) to character classes. When applied to character classes, each character class is expected to be closed under simple case folding. See the standard for the detailed explanation and example of "closed".

RL1.5 states: To meet this requirement, an implementation that supports case-sensitive matching should

  1. Provide at least the simple, default Unicode case-insensitive matching, and
  2. Specify which character properties or constructs are closed under the matching.

In the Pattern implementation, 5 types of constructs maybe case-sensitive when matching: back-refs, string slice (sequences), single, family(char-property) and class range. Single and family may appears independently or within a class.

For loose/case-insensitive matching, the back-refs, slices and singles apply toUpperCase and toLowerCase to both the pattern and the input string. This effectively 'close' the class for matching.

The family/char-properties are not "closed" and should remain unchanged. This is acceptable per RL1.5, if their behavior is clearly specified.

This method addresses that requirement for the "range" construct within in character class by computing the additional characters that should be included to close the range under simple case folding:

For each character in the input range [start, end] (inclusive), if the character has a simple case folding mapping in Unicode's CaseFolding.txt, the mapping is not a round-trip map, and the mapped character is not already in the range, then that mapped character (typically lowercase) is added to the expansion set.

This allows regex character class "range" implementation to use the returned expansion set to support additional case-insensitive matching, without duplicating characters already covered by the existing regex range implementation. The expectation is the matching is done using both the uppercase and lowercase forms of the input character, for example

ch -> inRange(lower, Character.toUpperCase(ch), upper) ||
          inRange(lower, Character.toLower(ch), upper) ||
          additionalClosingCharacters.contains(Character.toUpperCase(ch)) ||
          additionalClosingCharacters.contains(Character.toUpperCase(ch))
Parameters
start:int

the starting code point of the character range

end:int

the ending code point of the character range

Returns:int[]

a int[] containing the all simple case equivalents of characters in the range, excluding those already in the range

External Specification
https://www.unicode.org/reports/tr18/#Simple_Loose_Matches
getDefinedback to summary
private static long getDefined(int cp)
hashKeysback to summary
private static int[][] hashKeys(int[] keys)
isDefinedback to summary
public static boolean isDefined(int cp)

Tests whether the specified code point has a folding mapping entry defined.

Parameters
cp:int

the Unicode code point to test

Returns:boolean

true if the given code point has a case folding mapping entry defined in (@code caseFoldingMap}, false otherwise

isSingleCodePointback to summary
public static boolean isSingleCodePoint(long fold)