93 lines
1.2 KiB
C++
93 lines
1.2 KiB
C++
|
|
#include "string.hpp"
|
|
#include "main.hpp"
|
|
|
|
int
|
|
StringLength(char* s)
|
|
{
|
|
return strlen(s);
|
|
}
|
|
|
|
char*
|
|
StringCopy(char* dst, char* src)
|
|
{
|
|
return strcpy(dst, src);
|
|
}
|
|
|
|
char*
|
|
StringAlloc(int size)
|
|
{
|
|
char* s = (char*) malloc(size + 1);
|
|
ThrowIf(s == NULL, "Could not allocate string memory");
|
|
*s = '\0';
|
|
return s;
|
|
}
|
|
|
|
char*
|
|
StringDuplicate(char* s)
|
|
{
|
|
return StringCopy(StringAlloc(StringLength(s)), s);
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
strend(char* s)
|
|
{
|
|
return strchr(s, '\0');
|
|
}
|
|
|
|
char*
|
|
strmove(char* dst, char* src)
|
|
{
|
|
return (char*) memmove(dst, src, strlen(src) + 1);
|
|
}
|
|
|
|
char*
|
|
strtrimleft(char* s)
|
|
{
|
|
while (isspace(*s)) strmove(s, s + 1);
|
|
return s;
|
|
}
|
|
|
|
char*
|
|
strtrimright(char* s)
|
|
{
|
|
char* e = strend(s);
|
|
while (--e > s && isspace(*e)) *e = '\0';
|
|
return s;
|
|
}
|
|
|
|
char*
|
|
strtrim(char* s)
|
|
{
|
|
return strtrimleft(strtrimright(s));
|
|
}
|
|
|
|
char*
|
|
strsize(char* s)
|
|
{
|
|
return (char*) realloc(s, strlen(s) + 1);
|
|
}
|
|
|
|
char*
|
|
strins(char* s, int n)
|
|
{
|
|
strmove(s + n, s);
|
|
return s;
|
|
}
|
|
|
|
char*
|
|
strrem(char* s, int n)
|
|
{
|
|
return strmove(s, s + n);
|
|
}
|
|
|
|
|
|
char*
|
|
strrcat(char* dst, char* src)
|
|
{
|
|
int n = strlen(src);
|
|
return (char*) memmove(strins(dst, n), src, n);
|
|
}
|
|
|