feat(string): add SStrCopy

This commit is contained in:
fallenoak 2020-09-08 21:37:30 -05:00
parent 0861ddf3ba
commit 4e9f05c178
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
2 changed files with 43 additions and 0 deletions

35
storm/String.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "String.hpp"
#include "Error.hpp"
size_t SStrCopy(char* dest, const char* source, size_t destsize) {
STORM_ASSERT(dest);
STORM_ASSERT(source);
char* destbuf = dest;
if (destsize == 0x7FFFFFFF) {
while (*source) {
*destbuf = *source;
++destbuf;
++source;
}
} else {
if (*source) {
while (destbuf < &dest[destsize - 1]) {
*destbuf = *source;
++destbuf;
++source;
if (!*source) {
*destbuf = '\0';
return static_cast<size_t>(destbuf - dest);
}
}
}
}
*destbuf = '\0';
return static_cast<size_t>(destbuf - dest);
}