maid-lang 1.1.0

Maid Programming Language
Documentation
# file format.maid: basic implementation of string formatting

# format a string with the specified argument
# returns a new string with the formatted argument inside
func format(str, value) {
    if type(str) != "string" {
        uhoh("expected type string in 'format'");
    }

    obj result = "";

    walk i = 0 through length(str) {
        obj char = charat(str, i);

        if char == "{" {
            if i + 1 < length(str) { # not at end of string
                obj closing = charat(str, i + 1);

                if closing == "}" {
                    obj result = join(result, tostring(value));
                } otherwise {
                    uhoh("'format' expects string with closing brackets '{}'");
                }
            } otherwise {
                uhoh("'format' expects string with closing brackets '{}'");
            }
        } otherwise {
            if char == "}" {
                next;
            }

            obj result = join(result, char);
        }
    }

    give result;
}