mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(string): add SStrCopy
This commit is contained in:
parent
0861ddf3ba
commit
4e9f05c178
2 changed files with 43 additions and 0 deletions
35
storm/String.cpp
Normal file
35
storm/String.cpp
Normal 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);
|
||||||
|
}
|
||||||
8
storm/String.hpp
Normal file
8
storm/String.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef STORM_STRING_HPP
|
||||||
|
#define STORM_STRING_HPP
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
size_t SStrCopy(char* dest, const char* source, size_t destsize);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue