qtil
advanced-security/qtil-swift 0.0.3
Search

Class Char

A class representing a single character, backed by an integer code point.

Caution: As a subtype of int, this will behave similarly to c where accidental integer operations can occur. For example, charOf("a") + 1 will yield the integer 98 where a type error may be expected, and charOf("a") + charOf("b") will yield the integer 195 where the string “ab” may be expected. Luckily, charOf("a") + "b" will yield the (likely expected) string “ab”, as CodeQL converts the “integer” representation of the Char to a string using the implementation of toString() in this class, which will yield the string “a” rather than the string “97”. These are all the result of the design choice working around the fact that CodeQL has a limited number of options for representing infinite types, and the fact that there are too many code points for it to be efficient to represent them all exhaustively via a finite disjoint type such as a newtype. If this class were to extend string, then APIs which expect a Char would accept strings with multiple characters without a type error. By extending int, the problem is avoided at the risk of allowing integers in place of an explicit Char type.

To construct a Char, use the charOf(string) predicate or constrain .isStr(string).

Import path

import qtil.strings.Char

Direct supertypes

Predicates

codePoint

Get the code point of this character.

indexIn

Returns all of the offsets (starting at 0) of this character in the provided string. Has no results if the character does not exist in the string.

indexIn

Returns the index of the nth offset of where this character occurs in the provided string, starting the search the provided startAt index. Has no results if the character does not exist in the string.

isAlphabetic

Holds if the character is a letter, i.e. a character in the range A-Z or a-z.

isAscii

Holds if the character is an ascii codepoint, in the range 0-127, rather than a unicode codepoint.

isDigit

Holds if the character is a digit, i.e. a character in the range 0-9.

isLowercase

Holds if the character is not an uppercase letter.

isSpecial

Holds if the character is not a digit or a letter, i.e. a symbol or other special character.

isStr

Holds if the provided str is contains one character, and that character is the same as this.

isUppercase

Holds if the character is not a lowercase letter.

join

Uses this character as a separator to join the provided strings together.

join

Uses this character as a separator to join the provided strings together.

join

Uses this character as a separator to join the provided strings together.

join

Uses this character as a separator to join the provided strings together.

join

Uses this character as a separator to join the provided strings together.

join

Uses this character as a separator to join the provided strings together.

join

Uses this character as a separator to join the provided strings together.

repeat

Repeats this character n times, where n is a non-negative integer.

split

Splits the provided string on occurrences of this character.

split

Holds when the result equals the nth section of the provided string after being split on this character, where n is the idx parameter.

toLowercase

Provides the lowercase version of this character if it is an uppercase letter, otherwise provides itself.

toString

Turn the code point into a string containing the relevant unicode character.

toUppercase

Provides the uppercase version of this character if it is a lowercase letter, otherwise provides itself.

twice
wrap

Places this character at the start and end of the provided string.

Inherited predicates

inst

Convenience method to cast this to the infinite instance type T.

from Type

Charpred

Char

There must be a unicode character corresponding to the code point for this to be a Char.