Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement string formatting syntax in RGBASM #178

Closed
PikalaxALT opened this issue Apr 28, 2017 · 4 comments · Fixed by #646
Closed

Implement string formatting syntax in RGBASM #178

PikalaxALT opened this issue Apr 28, 2017 · 4 comments · Fixed by #646
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM

Comments

@PikalaxALT
Copy link
Contributor

Implement a function, STRFMT(spec, ...) which takes string spec and formats following arguments into the fields specified in spec, similar to std::printf. Minimally, support %s, %d, %f, %x.

VAL1 = STRFMT("Hello %s! I am %d years old today!", "world", $f)
PRINTT "{VAL1}\n"

should yield

Hello world! I am 15 years old today!
@ekimekim
Copy link

This would be the ideal general solution, though right now i'd settle for just some way to format a value as decimal rather than hex.

@AntonioND AntonioND added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM labels Apr 2, 2018
ISSOtm added a commit to ISSOtm/rgbds that referenced this issue Aug 28, 2019
Should partially close gbdev#178 and close gbdev#270.
This allows printing numbers in different bases and without the dollar prefix
This is especially useful in macros because the dollar isnt a valid character
for symbol names, requiring heavy `STRSUB` usage.
ISSOtm added a commit to ISSOtm/rgbds that referenced this issue Aug 28, 2019
Should partially cover gbdev#178 and close gbdev#270.
This allows printing numbers in different bases and without the dollar prefix
This is especially useful in macros because the dollar isnt a valid character
for symbol names, requiring heavy `STRSUB` usage.
ISSOtm added a commit to ISSOtm/rgbds that referenced this issue Aug 29, 2019
Should partially cover gbdev#178 and close gbdev#270.
This allows printing numbers in different bases and without the dollar prefix
This is especially useful in macros because the dollar isnt a valid character
for symbol names, requiring heavy `STRSUB` usage.
@ISSOtm
Copy link
Member

ISSOtm commented Feb 11, 2020

Fact: we will not be passing the string directly to printf because of not trusting user input (say hi to %n) and trying to parse the string for sanitization amounts to, well, parsing it ourselves.

Considering this, what features would be desired? (Zero-padding, minimum lengths, argument reordering perhaps?)

@AntonioND
Copy link
Member

I would keep it simple. No argument reordering. Probably minimum leading zeroes/spaces.

@Rangi42
Copy link
Contributor

Rangi42 commented Jul 6, 2020

Leading zeros/spaces, and d/x/X/b/o to support the same integer bases for which there are literals.

Also maybe trailing spaces with -. So STRFMT("%-4d", N) where N == 42 gives "42__". Or STRFMT("%-10s", Hi) where Hi is "hello" gives "hello_____".

Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 16, 2020
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 16, 2020
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 16, 2020
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 16, 2020
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 29, 2020
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 29, 2020
Rangi42 added a commit to Rangi42/rgbds that referenced this issue Dec 29, 2020
ISSOtm pushed a commit that referenced this issue Dec 29, 2020
…interpolation (#646)

Fixes #570
Fixes #178

Use errors for inapplicable format spec flags instead of -Wstring-format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants