mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
cleanup: remove localized snprintf() functions
The last use of these functions was removed in ae299d5e66
.
And that's a good thing, because snprintf-style interfaces
make zero sense in times of variable-length character
encodings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2776a2fe48
commit
398cc2b639
2 changed files with 0 additions and 69 deletions
|
@ -343,60 +343,6 @@ QString vqasprintf_loc(const char *fmt, va_list ap_in)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// Put a formated string respecting the default locale into a C-style array in UTF-8 encoding.
|
||||
// The only complication arises from the fact that we don't want to cut through multi-byte UTF-8 code points.
|
||||
extern "C" int snprintf_loc(char *dst, size_t size, const char *cformat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, cformat);
|
||||
int res = vsnprintf_loc(dst, size, cformat, ap);
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
|
||||
extern "C" int vsnprintf_loc(char *dst, size_t size, const char *cformat, va_list ap)
|
||||
{
|
||||
QByteArray utf8 = vqasprintf_loc(cformat, ap).toUtf8();
|
||||
const char *data = utf8.constData();
|
||||
size_t utf8_size = utf8.size();
|
||||
if (size == 0)
|
||||
return utf8_size;
|
||||
if (size < utf8_size + 1) {
|
||||
memcpy(dst, data, size - 1);
|
||||
if ((data[size - 1] & 0xC0) == 0x80) {
|
||||
// We truncated a multi-byte UTF-8 encoding.
|
||||
--size;
|
||||
// Jump to last copied byte.
|
||||
if (size > 0)
|
||||
--size;
|
||||
while(size > 0 && (dst[size] & 0xC0) == 0x80)
|
||||
--size;
|
||||
dst[size] = 0;
|
||||
} else {
|
||||
dst[size - 1] = 0;
|
||||
}
|
||||
} else {
|
||||
memcpy(dst, data, utf8_size + 1); // QByteArray guarantees a trailing 0
|
||||
}
|
||||
return utf8_size;
|
||||
}
|
||||
|
||||
int asprintf_loc(char **dst, const char *cformat, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, cformat);
|
||||
int res = vasprintf_loc(dst, cformat, ap);
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
|
||||
int vasprintf_loc(char **dst, const char *cformat, va_list ap)
|
||||
{
|
||||
QByteArray utf8 = vqasprintf_loc(cformat, ap).toUtf8();
|
||||
*dst = strdup(utf8.constData());
|
||||
return utf8.size();
|
||||
}
|
||||
|
||||
extern "C" void put_vformat_loc(struct membuffer *b, const char *fmt, va_list args)
|
||||
{
|
||||
QByteArray utf8 = vqasprintf_loc(fmt, args).toUtf8();
|
||||
|
|
|
@ -12,22 +12,7 @@
|
|||
__printf(1, 2) QString qasprintf_loc(const char *cformat, ...);
|
||||
__printf(1, 0) QString vqasprintf_loc(const char *cformat, va_list ap);
|
||||
__printf(1, 2) std::string casprintf_loc(const char *cformat, ...);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__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);
|
||||
__printf(2, 3) int asprintf_loc(char **dst, const char *cformat, ...);
|
||||
__printf(2, 0) int vasprintf_loc(char **dst, const char *cformat, va_list ap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
__printf(1, 2) std::string format_string_std(const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue