module watt.text.ascii

Functions for classifying characters in the ASCII range.

Despite the name, you can pass any UTF-8 characters to these functions. It's just that none of them will be considered true. Unicode whitespace won't return true from isWhite, etc.

Code Map

//! Functions for classifying characters in the ASCII range.
module watt.text.ascii;


enum HEX_DIGITS;
enum FULL_HEX_DIGITS;
enum DIGITS;
enum OCTAL_DIGITS;
enum LOWERCASE;
enum LETTERS;
enum UPPERCASE;
enum WHITESPACE;
enum NEWLINE;

//! Is a character alphanumeric?
fn isAlphaNum(c: dchar) bool { }
//! Is a character alphabetical?
fn isAlpha(c: dchar) bool { }
//! Is a character a lowercase alphabetical character?
fn isLower(c: dchar) bool { }
//! Is a character a uppercase alphabetical character?
fn isUpper(c: dchar) bool { }
//! Is a character a digit?
fn isDigit(c: dchar) bool { }
//! Is a character an octal digit?
fn isOctalDigit(c: dchar) bool { }
//! Is a character a hexadecimal digit?
fn isHexDigit(c: dchar) bool { }
//! Is a character whitespace?
fn isWhite(c: dchar) bool { }
//! Is a character a control character?
fn isControl(c: dchar) bool { }
//! Is a character punctuation?
fn isPunctuation(c: dchar) bool { }
//! Is a character a printable ASCII character?
fn isPrintable(c: dchar) bool { }
//! Is a given character an ASCII character?
fn isASCII(c: dchar) bool { }
//! Get the lowerspace letter of an uppercase character.
fn toLower(c: dchar) dchar { }
//! Get the upperspace letter of a lowercase character.
fn toUpper(c: dchar) dchar { }
fn isAlphaNum(c: dchar) bool

Is a character alphanumeric?

Examples

isAlphaNum('a');  // true
isAlphaNum('A');  // true
isAlphaNum('2');  // true
isAlphaNum('あ'); // false
isAlphaNum('!');  // false

Return

true if c is alphanumeric (a-z,A-Z,0-9).

fn isAlpha(c: dchar) bool

Is a character alphabetical?

Examples

isAlpha('a');  // true
isAlpha('G');  // true
isAlpha('2');  // false

Return

true if c is alphabetical (a-z,A-Z).

fn isLower(c: dchar) bool

Is a character a lowercase alphabetical character?

Examples

isLower('a');  // true
isLower('A');  // false

Return

true if c is lowercase alphabetical (a-z).

fn isUpper(c: dchar) bool

Is a character a uppercase alphabetical character?

Examples

isLower('a');  // false
isLower('A');  // true

Return

true if c is uppercase alphabetical (A-Z).

fn isDigit(c: dchar) bool

Is a character a digit?

Examples

isDigit('4');  // true
isDigit('(');  // false

Return

true if c is a digit (0-9).

fn isOctalDigit(c: dchar) bool

Is a character an octal digit?

Examples

isOctalDigit('7');  // true
isOctalDigit('8');  // false

Return

true if c is an octal digit (0-7).

fn isHexDigit(c: dchar) bool

Is a character a hexadecimal digit?

Examples

isHexDigit('1');  // true
isHexDigit('f');  // true
isHexDigit('F');  // true
isHexDigit('g');  // false

Return

true if c is a hex digit (0-9,a-f,A-F).

fn isWhite(c: dchar) bool

Is a character whitespace?

The characters considered whitespace are , \t, \r, \f, \v, and \n.

Return

true if c is whitespace.

fn isControl(c: dchar) bool

Is a character a control character?

A control character is a non printing character. Non ascii characters are not considered, so any value over 127 will not be considered to be a control character.

Return

true if c is a control character.

fn isPunctuation(c: dchar) bool

Is a character punctuation?

Where punctuation is defined as a non control, non whitespace, non alphanumeric character.

Return

true if c is punctuation.

fn isPrintable(c: dchar) bool

Is a character a printable ASCII character?

Return

true if c is a printable character.

fn isASCII(c: dchar) bool

Is a given character an ASCII character?

Examples

isASCII('a');  // true
isASCII('楽');  // false

Return

true if c is an ASCII character.

fn toLower(c: dchar) dchar

Get the lowerspace letter of an uppercase character.

Examples

toLower('A');  // 'a'
toLower('a');  // 'a'
toLower('2');  // '2'

Return

c, or c as a lowercase character if it's an uppercase character.

fn toUpper(c: dchar) dchar

Get the upperspace letter of a lowercase character.

Examples

toLower('A');  // 'A'
toLower('a');  // 'A'
toLower('2');  // '2'

Return

c, or c as an uppercase character if it's a lowercase character.