std.ascii

Reed's standard library. Imported with use std.ascii; not on disk.

Methods

i32.is_digitWhether self is an ASCII digit, 0 through 9.
i32.is_alphaWhether self is an ASCII letter, A-Z or a-z.
i32.is_alnumWhether self is an ASCII letter or digit.
i32.is_spaceWhether self is an ASCII whitespace character.
i32.is_upperWhether self is an ASCII uppercase letter.
i32.is_lowerWhether self is an ASCII lowercase letter.
i32.is_hex_digitWhether self is an ASCII hexadecimal digit: 0-9, a-f, or A-F.
i32.is_punctWhether self is an ASCII punctuation character.
i32.is_printWhether self is a printable ASCII character, space through ~.
i32.is_controlWhether self is an ASCII control character: 0-31 or 127 (delete).
i32.is_asciiWhether self is a 7-bit ASCII byte at all.
i32.to_lowerConverts an ASCII uppercase letter to lowercase, leaving everything else unchanged.
i32.to_upperConverts an ASCII lowercase letter to uppercase, leaving everything else unchanged.
i32.digit_valueThe numeric value of an ASCII digit in any base up to 36.
i32.digit_charThe lowercase ASCII character representing a digit value in 0..=35.
i32.cmp_ignore_caseCompares two ASCII characters ignoring case.

i32.is_digit #

line 24
func i32.is_digit(self: i32) -> i32

Whether self is an ASCII digit, 0 through 9.

Returns
1 for a digit, 0 otherwise
See also
i32.digit_value
Source
func i32.is_digit(self: i32) -> i32 {
  return self >= 48 && self <= 57;
}

i32.is_alpha #

line 32
func i32.is_alpha(self: i32) -> i32

Whether self is an ASCII letter, A-Z or a-z.

Returns
1 for a letter, 0 otherwise
See also
i32.is_alnum
Source
func i32.is_alpha(self: i32) -> i32 {
  return (self >= 65 && self <= 90) || (self >= 97 && self <= 122);
}

i32.is_alnum #

line 39
func i32.is_alnum(self: i32) -> i32

Whether self is an ASCII letter or digit.

Returns
1 for a letter or digit, 0 otherwise
Source
func i32.is_alnum(self: i32) -> i32 {
  return self.is_alpha() || self.is_digit();
}

i32.is_space #

line 49
func i32.is_space(self: i32) -> i32

Whether self is an ASCII whitespace character.

The set is space, tab, newline, carriage return, form feed, and vertical tab -- the same six characters C's isspace recognizes.

Returns
1 for whitespace, 0 otherwise
Source
func i32.is_space(self: i32) -> i32 {
  return self == 32 || (self >= 9 && self <= 13);
}

i32.is_upper #

line 57
func i32.is_upper(self: i32) -> i32

Whether self is an ASCII uppercase letter.

Returns
1 for A-Z, 0 otherwise
See also
i32.to_lower
Source
func i32.is_upper(self: i32) -> i32 {
  return self >= 65 && self <= 90;
}

i32.is_lower #

line 65
func i32.is_lower(self: i32) -> i32

Whether self is an ASCII lowercase letter.

Returns
1 for a-z, 0 otherwise
See also
i32.to_upper
Source
func i32.is_lower(self: i32) -> i32 {
  return self >= 97 && self <= 122;
}

i32.is_hex_digit #

line 73
func i32.is_hex_digit(self: i32) -> i32

Whether self is an ASCII hexadecimal digit: 0-9, a-f, or A-F.

Returns
1 for a hex digit, 0 otherwise
See also
i32.digit_value
Source
func i32.is_hex_digit(self: i32) -> i32 {
  return self.is_digit() || (self >= 97 && self <= 102) || (self >= 65 && self <= 70);
}

i32.is_punct #

line 82
func i32.is_punct(self: i32) -> i32

Whether self is an ASCII punctuation character.

Every printable non-alphanumeric, non-space character in !..~.

Returns
1 for punctuation, 0 otherwise
Source
func i32.is_punct(self: i32) -> i32 {
  return self >= 33 && self <= 126 && !self.is_alnum();
}

i32.is_print #

line 90
func i32.is_print(self: i32) -> i32

Whether self is a printable ASCII character, space through ~.

Returns
1 when printable, 0 otherwise
See also
i32.is_control
Source
func i32.is_print(self: i32) -> i32 {
  return self >= 32 && self <= 126;
}

i32.is_control #

line 98
func i32.is_control(self: i32) -> i32

Whether self is an ASCII control character: 0-31 or 127 (delete).

Returns
1 for a control character, 0 otherwise
See also
i32.is_print
Source
func i32.is_control(self: i32) -> i32 {
  return (self >= 0 && self <= 31) || self == 127;
}

i32.is_ascii #

line 105
func i32.is_ascii(self: i32) -> i32

Whether self is a 7-bit ASCII byte at all.

Returns
1 for 0..=127, 0 otherwise
Source
func i32.is_ascii(self: i32) -> i32 {
  return self >= 0 && self <= 127;
}

i32.to_lower #

line 115
func i32.to_lower(self: i32) -> i32

Converts an ASCII uppercase letter to lowercase, leaving everything else unchanged.

Bytes above 127 pass through untouched: see this module's scope note.

Returns
the lowercase form, or self
See also
i32.to_upper
Source
func i32.to_lower(self: i32) -> i32 {
  return self.is_upper() ? self + 32 : self;
}

i32.to_upper #

line 123
func i32.to_upper(self: i32) -> i32

Converts an ASCII lowercase letter to uppercase, leaving everything else unchanged.

Returns
the uppercase form, or self
See also
i32.to_lower
Source
func i32.to_upper(self: i32) -> i32 {
  return self.is_lower() ? self - 32 : self;
}

i32.digit_value #

line 135
func i32.digit_value(self: i32) -> i32

The numeric value of an ASCII digit in any base up to 36.

Accepts 0-9 and both cases of a-z. Returns -1 -- not 0 -- for anything that is not a digit, since 0 is a perfectly good digit value and the two must be distinguishable by a caller parsing a number.

Returns
the digit's value in 0..=35, or -1 when not a digit
See also
i32.digit_char
Source
func i32.digit_value(self: i32) -> i32 {
  if (self.is_digit()) { return self - 48; }
  if (self >= 97 && self <= 122) { return self - 87; }
  if (self >= 65 && self <= 90) { return self - 55; }
  return -1;
}

i32.digit_char #

line 149
func i32.digit_char(self: i32) -> i32

The lowercase ASCII character representing a digit value in 0..=35.

The inverse of digit_value. Returns -1 for a value outside the range, matching that function's convention for "not representable".

Returns
the character, or -1 when out of range
See also
i32.digit_value
Source
func i32.digit_char(self: i32) -> i32 {
  if (self < 0 || self > 35) { return -1; }
  return self < 10 ? self + 48 : self + 87;
}

i32.cmp_ignore_case #

line 159
func i32.cmp_ignore_case(self: i32, rhs: i32) -> i32

Compares two ASCII characters ignoring case.

Parameters
rhs — the character to compare against
Returns
a negative value, zero, or a positive value as self orders before, equal to, or after rhs
Source
func i32.cmp_ignore_case(self: i32, rhs: i32) -> i32 {
  return self.to_lower() - rhs.to_lower();
}