OnlineCop / kq-fork

Fork of KQ r910. Just for fun.
GNU General Public License v2.0
15 stars 9 forks source link

sprintf() but for std::string instead of char[] #132

Closed OnlineCop closed 2 years ago

OnlineCop commented 2 years ago

Adds a utilities.h file for general-purpose, well, utilities.

Something we may want to discuss is whether the signature should remain as the C-style void sprintf(out_param, in_param, ...) or switch to std::string sprintf(in_param, ...) instead.

The advantage of returning the string would allow us to change:

    // from this:
    sprintf(strbuf, "%3d>", t1.mhp);
    Draw.print_font(double_buffer, b + 96, 56, strbuf, FNORMAL);

    // to this:
    Draw.print_font(double_buffer, b + 96, 56, sprintf("%3d>", t1.mhp), FNORMAL);

I did not do that in this PR because sprintf(strbuf, ...) is used everywhere and I wanted to keep the number of changed files to a minimum until we decided on the above.