diff options
author | Your Name <you@example.com> | 2020-06-28 04:38:51 +0200 |
---|---|---|
committer | Your Name <you@example.com> | 2020-06-28 04:38:51 +0200 |
commit | b6a9ae621e9b4c1507ba8a6e6550740b8f79abe7 (patch) | |
tree | d14609c53ea11e2c40ea03af2990bb7298ef3ea5 | |
parent | Base: PhysM formatting (diff) | |
download | pOS-b6a9ae621e9b4c1507ba8a6e6550740b8f79abe7.tar.gz pOS-b6a9ae621e9b4c1507ba8a6e6550740b8f79abe7.tar.bz2 pOS-b6a9ae621e9b4c1507ba8a6e6550740b8f79abe7.zip |
stdlib: added strtok()
-rw-r--r-- | src/pOS/arch/x86/libc/string/strtok.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/pOS/arch/x86/libc/string/strtok.cpp b/src/pOS/arch/x86/libc/string/strtok.cpp new file mode 100644 index 0000000..b6fb4b3 --- /dev/null +++ b/src/pOS/arch/x86/libc/string/strtok.cpp @@ -0,0 +1,48 @@ +#include <stdlib.h> +#include <string.h> + +char* strtok(char* str, const char* delim) +{ + static char* lastPos = 0; + static char token[100]; + + if(!str && !lastPos) + return 0; + + if(!delim) + return 0; + + if(str) + lastPos = str; + + int delim_len = strlen(delim); + char* strt_ptr = lastPos; + int count = 0; + + while(*lastPos != '\0') + { + bool is_found = false; + for(int y = 0; y < delim_len; y++) + { + if(*(delim + y) == *lastPos) + is_found = true; + } + lastPos++; + if(is_found) + break; + count++; + } + + if(*lastPos == '\0') + lastPos = NULL; + + if(!count) + return strtok(0, delim); + + for(int x = 0; x < count; x++) + token[x] = *(strt_ptr + x); + token[count] = '\0'; + + return token; +} + |