The 7-bit ASCII character encoding standard.
This is not to be confused with the 8-bit extended ASCII character encoding.
Even though this module concerns itself with 7-bit ASCII, functions use u8
as the type instead of u7
for convenience and compatibility. Characters outside of the 7-bit range are gracefully handled (e.g. by returning false
).
See also: https://en.wikipedia.org/wiki/ASCII#Character_set
Functions
fn allocLowerString(allocator: std.mem.Allocator, ascii_string: []const u8) ![]u8
Allocates a lower case copy of
ascii_string
. Caller owns returned string and …Allocates a lower case copy of
ascii_string
. Caller owns returned string and must free withallocator
.fn allocUpperString(allocator: std.mem.Allocator, ascii_string: []const u8) ![]u8
Allocates an upper case copy of
ascii_string
. Caller owns returned string and…Allocates an upper case copy of
ascii_string
. Caller owns returned string and must free withallocator
.fn eqlIgnoreCase(a: []const u8, b: []const u8) bool
Compares strings
a
andb
case-insensitively and returns whether they are equ…Compares strings
a
andb
case-insensitively and returns whether they are equal.fn indexOfIgnoreCase(haystack: []const u8, needle: []const u8) ?usize
Finds
needle
inhaystack
, ignoring case, starting at index 0.fn indexOfIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []const u8) ?usize
Finds
needle
inhaystack
, ignoring case, starting atstart_index
. Uses Bo…Finds
needle
inhaystack
, ignoring case, starting atstart_index
. Uses Boyer-Moore-Horspool algorithm on large inputs;indexOfIgnoreCasePosLinear
on small inputs.fn indexOfIgnoreCasePosLinear(haystack: []const u8, start_index: usize, needle: []const u8) ?usize
Consider using
indexOfIgnoreCasePos
instead of this, which will automatically …Consider using
indexOfIgnoreCasePos
instead of this, which will automatically use a more sophisticated algorithm on larger inputs.fn isControl(c: u8) bool
Returns whether the character is a control character.
Returns whether the character is a control character.
See also:
control_code
fn isPrint(c: u8) bool
Returns whether the character is printable and has some graphical representation…
Returns whether the character is printable and has some graphical representation, including the space character.
fn lessThanIgnoreCase(lhs: []const u8, rhs: []const u8) bool
Returns whether the lexicographical order of
lhs
is lower thanrhs
.fn lowerString(output: []u8, ascii_string: []const u8) []u8
Writes a lower case copy of
ascii_string
tooutput
. Asserts `output.len >= …Writes a lower case copy of
ascii_string
tooutput
. Assertsoutput.len >= ascii_string.len
.fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order
Returns the lexicographical order of two slices. O(n).
fn toLower(c: u8) u8
Lowercases the character and returns it as-is if already lowercase or not a lett…
Lowercases the character and returns it as-is if already lowercase or not a letter.
fn toUpper(c: u8) u8
Uppercases the character and returns it as-is if already uppercase or not a lett…
Uppercases the character and returns it as-is if already uppercase or not a letter.
fn upperString(output: []u8, ascii_string: []const u8) []u8
Writes an upper case copy of
ascii_string
tooutput
. Asserts `output.len >=…Writes an upper case copy of
ascii_string
tooutput
. Assertsoutput.len >= ascii_string.len
.
Values
whitespace | [6]u8 | Whitespace for general use. This may be used with e.g. |