mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(string): add SStrPrintf
This commit is contained in:
parent
d9e7f05c15
commit
3e24b01fe1
3 changed files with 55 additions and 0 deletions
|
|
@ -4,6 +4,8 @@
|
|||
#include "storm/string/bjhash.hpp"
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <strings.h>
|
||||
|
||||
|
|
@ -167,6 +169,29 @@ void InitializeFloatDigits() {
|
|||
}
|
||||
}
|
||||
|
||||
size_t ISStrVPrintf(const char* format, va_list va, char* dest, size_t maxchars) {
|
||||
if (!maxchars) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t result;
|
||||
|
||||
if (maxchars == STORM_MAX_STR) {
|
||||
// TODO conditional vsoprintf;
|
||||
result = vsprintf(dest, format, va);
|
||||
} else {
|
||||
// TODO conditional vsnoprintf;
|
||||
result = vsnprintf(dest, maxchars, format, va);
|
||||
|
||||
if (result >= maxchars) {
|
||||
result = maxchars - 1;
|
||||
dest[result] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SStrInitialize() {
|
||||
if (!s_initialized) {
|
||||
InitializeFloatDigits();
|
||||
|
|
@ -347,6 +372,16 @@ uint32_t SStrPack(char* dest, const char* source, uint32_t destsize) {
|
|||
return i - dest;
|
||||
}
|
||||
|
||||
size_t SStrPrintf(char* dest, size_t maxchars, const char* format, ...) {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
|
||||
STORM_ASSERT(dest);
|
||||
STORM_ASSERT(format);
|
||||
|
||||
return ISStrVPrintf(format, va, dest, maxchars);
|
||||
}
|
||||
|
||||
const char* SStrStr(const char* string, const char* search) {
|
||||
STORM_ASSERT(string);
|
||||
STORM_ASSERT(search);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue