X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/bf870a1dde437a48ae40d092a14e164c861ea102..c4d08ac5260bb26db10bcfd9dc6fd2db60efebe9:/lunaix-os/libs/klibc/string/trim.c?ds=inline diff --git a/lunaix-os/libs/klibc/string/trim.c b/lunaix-os/libs/klibc/string/trim.c new file mode 100644 index 0000000..82f29bd --- /dev/null +++ b/lunaix-os/libs/klibc/string/trim.c @@ -0,0 +1,29 @@ +#include + +#define WS_CHAR(c) \ + (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\v' || c == '\r') + +void +strrtrim(char* str) +{ + size_t l = strlen(str); + while (l < (size_t)-1) { + char c = str[l]; + if (!c || WS_CHAR(c)) { + l--; + continue; + } + break; + } + str[l + 1] = '\0'; +} + +void* +strltrim_safe(char* str) +{ + size_t l = 0; + char c = 0; + while ((c = str[l++]) && WS_CHAR(c)) + ; + return strcpy(str, str + l); +} \ No newline at end of file