startsWith() & endsWith()

This commit is contained in:
timerix 2022-08-31 21:44:14 +06:00
parent 982a79a052
commit eca678026f
2 changed files with 17 additions and 0 deletions

View File

@ -34,3 +34,16 @@ char* char_multiply(char c, uint32 n){
rez[n]=c;
return rez;
}
bool cptr_startsWith(char* ptr, char* fragment){
for(char cs=*ptr, cf=*fragment; cf; cs=*++ptr, cf=*++fragment)
if(cs!=cf) return false;
return true;
}
bool cptr_endsWith(char* ptr, char* fragment){
ptr+=cptr_length(ptr)-cptr_length(fragment);
for(char cs=*ptr, cf=*fragment; cf; cs=*++ptr, cf=*++fragment)
if(cs!=cf) return false;
return true;
}

View File

@ -18,6 +18,10 @@ bool cptr_compare(char* key0, char* key1);
// multiplies char n times
char* char_multiply(char c, uint32 n);
bool cptr_startsWith(char* ptr, char* fragment);
bool cptr_endsWith(char* ptr, char* fragment);
#if __cplusplus
}
#endif