Function stem [src]

Returns the last component of this path without its extension (if any): "hello/world/lib.tar.gz" ⇒ "lib.tar" "hello/world/lib.tar" ⇒ "lib" "hello/world/lib" ⇒ "lib"

Prototype

pub fn stem(path: []const u8) []const u8

Parameters

path: []const u8

Example

test stem { try testStem("hello/world/lib.tar.gz", "lib.tar"); try testStem("hello/world/lib.tar", "lib"); try testStem("hello/world/lib", "lib"); try testStem("hello/lib/", "lib"); try testStem("hello...", "hello.."); try testStem("hello.", "hello"); try testStem("/hello.", "hello"); try testStem(".gitignore", ".gitignore"); try testStem(".image.png", ".image"); try testStem("file.ext", "file"); try testStem("file.ext.", "file.ext"); try testStem("a.b.c", "a.b"); try testStem("a.b.c/", "a.b"); try testStem(".a", ".a"); try testStem("///", ""); try testStem("..", "."); try testStem(".", "."); try testStem(" ", " "); try testStem("", ""); }

Source

pub fn stem(path: []const u8) []const u8 { const filename = basename(path); const index = mem.lastIndexOfScalar(u8, filename, '.') orelse return filename[0..]; if (index == 0) return path; return filename[0..index]; }