Files
bux-lang/library/std/Fmt.bux
T
dimgigov db9025f3a3 feat: add Std::Fmt — string formatting module
- C runtime: bux_float_to_string() for float64 → String conversion
- String.bux: add String_FromFloat, extern decl for bux_float_to_string
- library/std/Fmt.bux: Fmt_Fmt1, Fmt_Fmt2, Fmt_Fmt3, Fmt_FmtInt, Fmt_FmtInt2,
  Fmt_FmtFloat, Fmt_FmtBool — positional {0}, {1}, {2} placeholders
- Refactor examples to use Fmt:
  factorial.bux, fibonacci.bux, process.bux, os_time.bux
2026-06-05 21:05:00 +03:00

43 lines
1.2 KiB
Plaintext

module Std::Fmt {
/* String formatting with positional placeholders {0}, {1}, {2}...
*
* Usage:
* Fmt_Fmt1("Hello, {0}!", "World")
* Fmt_FmtInt("Count: {0}", 42)
* Fmt_FmtFloat("Pi: {0}", 3.14159)
* Fmt_FmtBool("Active: {0}", true)
* Fmt_Fmt2("Name: {0}, Age: {1}", name, String_FromInt(age))
*/
func Fmt_Fmt1(pattern: String, a: String) -> String {
return String_Format1(pattern, a);
}
func Fmt_Fmt2(pattern: String, a: String, b: String) -> String {
return String_Format2(pattern, a, b);
}
func Fmt_Fmt3(pattern: String, a: String, b: String, c: String) -> String {
return String_Format3(pattern, a, b, c);
}
func Fmt_FmtInt(pattern: String, n: int64) -> String {
return String_Format1(pattern, String_FromInt(n));
}
func Fmt_FmtInt2(pattern: String, n1: int64, n2: int64) -> String {
return String_Format2(pattern, String_FromInt(n1), String_FromInt(n2));
}
func Fmt_FmtFloat(pattern: String, f: float64) -> String {
return String_Format1(pattern, String_FromFloat(f));
}
func Fmt_FmtBool(pattern: String, b: bool) -> String {
if b {
return String_Format1(pattern, "true");
}
return String_Format1(pattern, "false");
}
}