CleverRaven/Cataclysm-DDA — pull request #6420 by BevapDin (2014-03-04 16:41:05+00:00)
Title: [WIP] update string formatting code

[WIP] update string formatting code

There were some string formatting issues lately. The extended magazines contains a `%` in its description. If this is interpreted as format specifier (in `printf` like functions) it might cause a crash (see 6407).

Many printing functions are used wrong. For example `fold_and_print` expect a
format string (like "There is a %s") and further arguments. But sometimes those function get an already formatted string, which might possibly contain format specifier. But without further arguments this leads to a crash.

-----

This PR tries to solve these problems. I checked most calls to `fold_and_print` and similar functions (`query*`, `popup*`, ...) and mad sure they use the right format string.

As some functions use an already formatted string (e.g. coming from item info), I added wrapper functions `fold_and_print` that don't do the formatting and print everything directly.

I also changed some direct calls to `printf` like function to use the `string_format` function instead. That function should now be able to handle strings of any length.

The `string_format` function has been tested under linux and on a old VisualStudio. But I'm not sure about other environments.

Can someone look at mongroupdef.cpp, line 11? Is this still needed? Because `printf` is not used in that file.

---

The "wrong" usage of those printing functions can be seen by adding `%s%s%s%s%s%s%s%s` to the names and descriptions of items/furniture/terrain/vehicle parts/monsters. Encounter them, look at them and see what happens.

TODO:
----

- some files still have calls to `printf` like functions in it (computer.cpp, ...). Replace them.

- there are some pointless calls to `c_str()` when a `std::string` is already good enough. When the compiler automatically creates a `std::string` from the result of `c_str()`, why not use the string directly?

- there are other calls to `mwprintz` and similar that are wrong.