mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
string code docs
This commit is contained in:
@@ -3,9 +3,22 @@ package strings
|
||||
|
||||
import "core:unicode/utf8"
|
||||
|
||||
/*
|
||||
Ascii_Set is designed to store ASCII characters efficiently as a bit-array
|
||||
Each bit in the array corresponds to a specific ASCII character, where the value of the bit (0 or 1)
|
||||
indicates if the character is present in the set or not.
|
||||
*/
|
||||
Ascii_Set :: distinct [8]u32
|
||||
/*
|
||||
Creates an Ascii_Set with unique characters from the input string.
|
||||
|
||||
// create an ascii set of all unique characters in the string
|
||||
Inputs:
|
||||
- chars: A string containing characters to include in the Ascii_Set.
|
||||
|
||||
Returns:
|
||||
- as: An Ascii_Set with unique characters from the input string.
|
||||
- ok: false if any character in the input string is not a valid ASCII character.
|
||||
*/
|
||||
ascii_set_make :: proc(chars: string) -> (as: Ascii_Set, ok: bool) #no_bounds_check {
|
||||
for i in 0..<len(chars) {
|
||||
c := chars[i]
|
||||
@@ -17,8 +30,15 @@ ascii_set_make :: proc(chars: string) -> (as: Ascii_Set, ok: bool) #no_bounds_ch
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
/*
|
||||
Determines if a given char is contained within an Ascii_Set.
|
||||
|
||||
// returns true when the `c` byte is contained in the `as` ascii set
|
||||
Inputs:
|
||||
- as: The Ascii_Set to search.
|
||||
- c: The char to check for in the Ascii_Set.
|
||||
|
||||
Returns: A boolean indicating if the byte is contained in the Ascii_Set (true) or not (false).
|
||||
*/
|
||||
ascii_set_contains :: proc(as: Ascii_Set, c: byte) -> bool #no_bounds_check {
|
||||
return as[c>>5] & (1<<(c&31)) != 0
|
||||
}
|
||||
Reference in New Issue
Block a user