const std = @import("std");

fn formatFunctionName(comptime fn_name: []const u8) []const u8 {
    comptime {
        var base_name = fn_name;
        for (fn_name, 0..) |c, i| {
            if (i > 0 and c == '_' and fn_name[i - 1] == '_') {
                base_name = fn_name[0 .. i - 1];
                break;
            }
        }

        var result: []const u8 = "";
        var capitalize_next = true;

        for (base_name) |c| {
            if (c == '_') {
                result = result ++ " ";
                capitalize_next = true;
            } else if (capitalize_next) {
                result = result ++ &[_]u8{std.ascii.toUpper(c)};
                capitalize_next = false;
            } else {
                result = result + &[_]u8{c};
            }
        }

        return result;
    }
}

pub fn hello_world(comptime action: []const u8) void {
    const fn_name = comptime @src().fn_name;
    const formatted = comptime formatFunctionName(fn_name);

    @field(std.debug, action)("{s}\n", .{formatted});
}

pub fn main() void {
    hello_world("print");
}
