diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-02-27 19:43:31 +0100 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-02-27 19:43:31 +0100 |
| commit | 88510735e13f8c5cd7bbb2d08ba1cbfd407dca04 (patch) | |
| tree | 26b711143cd31e89d3a2489d2ac6ab562e899eea /exercises/065_builtins2.zig | |
| parent | 8c119bebdc66becac60e7ef035a993e422bd8972 (diff) | |
| parent | 07031c5daac4291e4d23599a944b84e6b434f9c2 (diff) | |
Merge branch 'main' into emphasize-for-loop-range
Diffstat (limited to 'exercises/065_builtins2.zig')
| -rw-r--r-- | exercises/065_builtins2.zig | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/exercises/065_builtins2.zig b/exercises/065_builtins2.zig index 2d13994..4514b0b 100644 --- a/exercises/065_builtins2.zig +++ b/exercises/065_builtins2.zig @@ -137,19 +137,20 @@ pub fn main() void { } // NOTE: This exercise did not originally include the function below. -// But a change after Zig 0.10.0 added the source file name to the -// type. "Narcissus" became "065_builtins2.Narcissus". +// After Zig 0.10.0, `@typeName` began prefixing the returned type name +// with the source file name. For example, "Narcissus" became +// "065_builtins2.Narcissus". // // To fix this, we've added this function to strip the filename from // the front of the type name. (It returns a slice of the type name -// starting at the index + 1 of character ".") +// starting just after the ".") // // We'll be seeing @typeName again in Exercise 070. For now, you can // see that it takes a Type and returns a u8 "string". fn maximumNarcissism(myType: type) []const u8 { - const indexOf = @import("std").mem.indexOf; + const find = @import("std").mem.find; // Turn "065_builtins2.Narcissus" into "Narcissus" const name = @typeName(myType); - return name[indexOf(u8, name, ".").? + 1 ..]; + return name[find(u8, name, ".").? + 1 ..]; } |
