diff --git a/storm/String.cpp b/storm/String.cpp new file mode 100644 index 0000000..5124580 --- /dev/null +++ b/storm/String.cpp @@ -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(destbuf - dest); + } + } + } + } + + *destbuf = '\0'; + return static_cast(destbuf - dest); +} diff --git a/storm/String.hpp b/storm/String.hpp new file mode 100644 index 0000000..ad90d8b --- /dev/null +++ b/storm/String.hpp @@ -0,0 +1,8 @@ +#ifndef STORM_STRING_HPP +#define STORM_STRING_HPP + +#include + +size_t SStrCopy(char* dest, const char* source, size_t destsize); + +#endif