diff --git a/src/base/cptr.c b/src/base/cptr.c index 0086edd..f098fdc 100644 --- a/src/base/cptr.c +++ b/src/base/cptr.c @@ -48,6 +48,19 @@ bool cptr_endsWith(char* ptr, char* fragment){ return true; } +uint32 cptr_indexOf(char* ptr, char* fragment){ + char sc=*ptr; + for(int si=0, fi=0; sc!=0; si++){ + sc=ptr[si]; + if(sc==fragment[fi]){ + fi++; + if(fragment[fi]==0) + return si-fi+1; + } + } + return -1; +} + void memcopy(void* from, void* to, uint32 size){ if(from==NULL || to==NULL) throw(ERR_NULLPTR); diff --git a/src/base/cptr.h b/src/base/cptr.h index bcf3252..255ee0a 100644 --- a/src/base/cptr.h +++ b/src/base/cptr.h @@ -22,6 +22,17 @@ bool cptr_startsWith(char* ptr, char* fragment); bool cptr_endsWith(char* ptr, char* fragment); +/// @brief search for in +/// @return index of first inclusion or -1 if not found +uint32 cptr_indexOf(char* ptr, char* fragment); + +static inline bool cptr_contains(char* ptr, char* fragment){ + // if(cptr_indexOf(ptr, fragment)==-1) + // return false; + // return true; + return cptr_indexOf(ptr, fragment) +1; +} + void memcopy(void* from, void* to, uint32 size); char* __cptr_concat(uint16 n, ...);