squall/storm/String.cpp

36 lines
769 B
C++
Raw Normal View History

2020-09-08 21:37:30 -05:00
#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);
}