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

uucore: add sprintf() function #4185

Merged
merged 1 commit into from
Dec 3, 2022
Merged

Conversation

jfinkels
Copy link
Collaborator

Add an sprintf() function (and printf() function) to uucore::memo. The sprintf() function behaves roughly like the standard Rust format!(), but follows our implementation of the GNU printf formatting logic instead. The printf() function is a convenience function that wraps the Memo::run_all() function in order to provide a more user-friendly name (or at least more familiar to C programmers).

This pull request was inspired by this comment requesting the use of %g to format a number in dd: #4169 (comment)

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

/// any subst. arguments along the way.
/// 2. feeds remaining arguments into function
/// that prints tokens.
struct Memo {
Copy link
Member

@tertsdiepraam tertsdiepraam Nov 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess unrelated to this particular PR, but I don't understand why this is called Memo? Is it like a memoization of the token string?

The same goes for the fact that printf and sprintf are exposed via the memo module at the moment, instead of something (imo) more appropriate like uucore::format or uucore::print

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why it is called Memo, I assumed it had something to do with memoization as well. I wasn't really familiar with what this Memo struct was supposed to do when I moved it from the printf crate to the uucore crate, so I just named this module uucore::memo, but yes it should have been something like uucore::printf or something like that.

Add an `sprintf()` function (and `printf()` function) to
`uucore::memo`.  The `sprintf()` function behaves roughly like the
standard Rust `format!()`, but follows our implementation of the GNU
`printf` formatting logic instead.
@sylvestre sylvestre merged commit 3880b46 into uutils:main Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants