CTCase

class CTCase constructor(table: CharSequence)(source)

Utility for converting letters to upper/lower case in a constant-time manner (in terms of work performed).

Both CTCase.uppercase and CTCase.lowercase perform the same number of operations no matter the input (i.e. they do not return early).

NOTE: Only characters where Char.isLetter is true are taken from the provided table.

e.g. (NOT constant-time operation)

fun String.containsChar(char: Char): Boolean {
    for (c in this) {
        if (c == char) return true
    }
    return false
}

e.g. (YES constant-time operation)

fun String.containsChar(char: Char): Boolean {
    var result = false
    for (c in this) {
        result = if (c == char) true else result
    }
    return result
}

Parameters

table

The decoding table (e.g. ABCDEFGHIJKLMNOPQRSTUVWXYZ234567)

Throws

IllegalArgumentException

if table contains a letter that has no corresponding lowercase value.

Constructors

Link copied to clipboard
constructor(table: CharSequence)

Properties

Link copied to clipboard
@JvmField
val lowers: Set<Char>

Lowercase letters corresponding to uppers

Link copied to clipboard
@JvmField
val uppers: Set<Char>

Uppercase letters

Functions

Link copied to clipboard
fun lowercase(char: Char): Char?

If the provided char exists within uppers, its corresponding lowercase value is returned. If nothing is found, null is returned.

Link copied to clipboard
fun uppercase(char: Char): Char?

If the provided char exists within lowers, its corresponding uppercase value is returned. If nothing is found, null is returned.