2024-05-31 11:26:52 -04:00
|
|
|
package grime
|
2024-03-02 18:19:27 -05:00
|
|
|
|
2024-03-19 08:36:58 -04:00
|
|
|
rune16 :: distinct u16
|
2024-03-02 18:19:27 -05:00
|
|
|
|
2024-03-06 16:47:00 -05:00
|
|
|
// Exposing the alloc_error
|
|
|
|
@(require_results)
|
2024-05-08 02:26:39 -04:00
|
|
|
string_to_runes :: proc ( content : string, allocator := context.allocator) -> (runes : []rune, alloc_error : AllocatorError) #optional_allocator_error {
|
2024-03-06 16:47:00 -05:00
|
|
|
num := str_rune_count(content)
|
2024-03-05 10:19:27 -05:00
|
|
|
|
|
|
|
runes, alloc_error = make([]rune, num, allocator)
|
2024-03-06 16:47:00 -05:00
|
|
|
if runes == nil || alloc_error != AllocatorError.None {
|
|
|
|
return
|
2024-03-05 10:19:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
idx := 0
|
2024-03-06 16:47:00 -05:00
|
|
|
for codepoint in content {
|
2024-03-05 10:19:27 -05:00
|
|
|
runes[idx] = codepoint
|
|
|
|
idx += 1
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2024-03-19 08:36:58 -04:00
|
|
|
|
|
|
|
string_to_runes_array :: proc( content : string, allocator := context.allocator ) -> ( []rune, AllocatorError )
|
|
|
|
{
|
|
|
|
num := cast(u64) str_rune_count(content)
|
|
|
|
|
2024-05-31 17:58:18 -04:00
|
|
|
runes_array, alloc_error := make( Array(rune), num, allocator )
|
2024-03-19 08:36:58 -04:00
|
|
|
if alloc_error != AllocatorError.None {
|
|
|
|
return nil, alloc_error
|
|
|
|
}
|
|
|
|
|
2024-05-14 11:47:44 -04:00
|
|
|
runes := array_to_slice_capacity(runes_array)
|
2024-03-19 08:36:58 -04:00
|
|
|
|
|
|
|
idx := 0
|
|
|
|
for codepoint in content {
|
|
|
|
runes[idx] = codepoint
|
|
|
|
idx += 1
|
|
|
|
}
|
|
|
|
return runes, alloc_error
|
|
|
|
}
|