to_string :: (c: *u8, count := 1) -> string #expand { return string.{ data = c, count = count }; } Index_Mode :: enum { from_left; from_right; } find_index :: (b: []u8, c: u8, $mode := Index_Mode.from_left) -> bool, int { #if #complete mode == { case .from_left; for b if it == c { return true, it_index; } case .from_right; i := b.count - 1; while i >= 0 { if b[i] == c { return true, i; } i -= 1; } } return false, -1; } find_index :: inline (s: string, c: u8, $mode := Index_Mode.from_left) -> bool, int { ok, idx := find_index(s.([]u8), c, mode); return ok, idx; } #scope_file; // ---------------------------------------------------------- // TESTS // ---------------------------------------------------------- #if #exists(RUN_TESTS) #run { test :: #import "jc/meta/test"; }