mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-27 05:22:07 +00:00
Implement STRFMT and more printf-like format specifiers for string interpolation (#646)
Fixes #570 Fixes #178 Use errors for inapplicable format spec flags instead of -Wstring-format
This commit is contained in:
24
test/asm/strfmt.asm
Normal file
24
test/asm/strfmt.asm
Normal file
@@ -0,0 +1,24 @@
|
||||
VAL EQUS STRFMT("Hello %s! I am %d years old today!", "world", $f)
|
||||
PRINTT "{VAL}\n"
|
||||
|
||||
N = -42
|
||||
PRINTT STRFMT("signed %010d == unsigned %010u\n", N, N)
|
||||
|
||||
N = 112
|
||||
FMT EQUS "X"
|
||||
PRINTT STRFMT("\tdb %#03{s:FMT} %% 26\t; %#03{FMT}\n", N, N % 26)
|
||||
|
||||
TEMPLATE EQUS "\"%s are %s\\n\""
|
||||
PRINTT STRFMT(TEMPLATE, "roses", "red")
|
||||
PRINTT STRFMT(TEMPLATE, "violets", "blue")
|
||||
PRINTT STRFMT(TEMPLATE, "void", 0, "extra")
|
||||
|
||||
PRINTT STRCAT(STRFMT(STRFMT("%%%s.%d%s", "", 9, "f"), _PI), \
|
||||
STRFMT(" ~ %s\n", STRFMT("%s%x", "thr", 238)))
|
||||
|
||||
PRINTT STRFMT("%d eol %", 1)
|
||||
PRINTT "\n"
|
||||
|
||||
PRINTT STRFMT("invalid %w spec\n", 42)
|
||||
|
||||
PRINTT STRFMT("one=%d two=%d three=%d\n", 1)
|
||||
Reference in New Issue
Block a user