-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Feature request: String.format
with specifiers
#5002
Comments
IIUC this seems like a cheatcode that should be implemented in foundry, so transferring this issue, but let me know if I misunderstood |
Nah, I was referring to a pure Solidity implementation of format specifiers, meant to be used in production. Of course, I imagine that this would be difficult to implement. |
Production-level solidity string formatting is out of scope for forge-std since it's a development-focused repo. However, solady is being audited soon and it has a lot of string manipulation utils, so you may be able to get something like this in there then have it audited. I'll leave this open in the foundry repo since this still seems like it could be useful as a cheatcode |
Related: #6891 Could be extended to support |
Is this still needed? If so, I can work on that. |
@leovct yes, that would be a nice addition |
I know it's been a while, I was quite busy at work. I implemented a first tiny version, can you guys check if this is what you're expecting? cc @grandizzy @zerosnacks |
Hey @leovct, not a problem! I think this is in line with what @mds1 is proposing. One concern I have it the amount of functions there would be to sufficiently cover every case, see: https://github.com/foundry-rs/forge-std/blob/master/src/console.sol |
That's also a concern I have, it will require a lot of code to implement such feature. I'm not a rust expert but maybe using macros seems like a better approach to reduce code duplication? |
cc @DaniPopes do you see a clever macro trick we could do here w/ cheatcodes to avoid polluting the concise |
I would prefer a similar approach to |
Console logging supports format specifiers like
%s
and%d
.It would be helpful to have something similar for formatting strings, e.g. equivalent to Java's
String.format
.As per #2313, I gather that the format specifier logic is implemented in Rust, not Solidity. But I went ahead and created this issue because I think it's a highly desirable feature, especially for use cases like NFT SVGs.
The text was updated successfully, but these errors were encountered: