mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Localization: Make Qt's locale-aware formatting accessible from C
This commit introduces functions: - QString asprintf_loc(const char *cformat, ...); - int snprintf_loc(char *dst, size_t size, const char *cformat, ...); - put_format_loc(struct membuffer *, const char *fmt, ...); and their va_arg equivalents, which use Qt's QString::arg() formatting options to render the strings. The snprintf_loc() function takes care not to truncate multi-byte UTF-8 encodings. Thus, on overflow, the resulting string might be shorter than size-1. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
9a8a0afa29
commit
bec3e80683
4 changed files with 421 additions and 3 deletions
|
|
@ -6,7 +6,13 @@
|
|||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
|
||||
// 1) Types
|
||||
// 1) Types and macros
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define __printf(x, y) __attribute__((__format__(__printf__, x, y)))
|
||||
#else
|
||||
#define __printf(x, y)
|
||||
#endif
|
||||
|
||||
enum inertgas {N2, HE};
|
||||
|
||||
|
|
@ -47,6 +53,9 @@ void init_proxy();
|
|||
QString getUUID();
|
||||
QStringList imageExtensionFilters();
|
||||
char *intdup(int index);
|
||||
__printf(1, 2) QString asprintf_loc(const char *cformat, ...);
|
||||
__printf(1, 0) QString vasprintf_loc(const char *cformat, va_list ap);
|
||||
|
||||
#endif
|
||||
|
||||
// 3) Functions visible to C and C++
|
||||
|
|
@ -81,10 +90,11 @@ void cache_insert(int tissue, int timestep, enum inertgas gas, double value);
|
|||
void print_qt_versions();
|
||||
void lock_planner();
|
||||
void unlock_planner();
|
||||
__printf(3, 4) int snprintf_loc(char *dst, size_t size, const char *cformat, ...);
|
||||
__printf(3, 0) int vsnprintf_loc(char *dst, size_t size, const char *cformat, va_list ap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // QTHELPER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue