diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-02-21 22:35:50 +0100 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2018-03-05 16:23:55 +0100 |
commit | bec3e806831290f11c8b46a01dc2295ffc307ca4 (patch) | |
tree | b7f539162aa7f30b24dbe3fdd8b75838a70e97cc /core/membuffer.c | |
parent | 9a8a0afa29776c195c6a6acbb77b5d70cecea0c9 (diff) | |
download | subsurface-bec3e806831290f11c8b46a01dc2295ffc307ca4.tar.gz |
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>
Diffstat (limited to 'core/membuffer.c')
-rw-r--r-- | core/membuffer.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/membuffer.c b/core/membuffer.c index 18a0203fc..1d486b3a6 100644 --- a/core/membuffer.c +++ b/core/membuffer.c @@ -52,7 +52,7 @@ static void oom(void) exit(1); } -static void make_room(struct membuffer *b, unsigned int size) +void make_room(struct membuffer *b, unsigned int size) { unsigned int needed = b->len + size; if (needed > b->alloc) { @@ -141,6 +141,15 @@ void put_format(struct membuffer *b, const char *fmt, ...) va_end(args); } +void put_format_loc(struct membuffer *b, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + put_vformat_loc(b, fmt, args); + va_end(args); +} + void put_milli(struct membuffer *b, const char *pre, int value, const char *post) { int i; |