Mon 16 Mar 11:09:06 CET 2026
This commit is contained in:
parent
9a3aa38ba1
commit
f0f82cac09
37
src/str.c
Normal file
37
src/str.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
#include "str.h"
|
||||
|
||||
int string_cmp(char *s1,char *s2, int maxlength) {
|
||||
int i=0;
|
||||
while(*s1 && *s2 && (maxlength==0 || i<maxlength)) { if (*s1!=*s2) return 0; s1++; s2++; i++;}
|
||||
if ((maxlength==0 || i<maxlength) && (*s1 || *s2)) return 0; // only partial match
|
||||
return 1;
|
||||
}
|
||||
|
||||
void string_copy(char *dst,char *src, int length) {
|
||||
int i=0;
|
||||
while(*src && (length==0 || i<length)) { *dst=*src; dst++; src++; i++;}
|
||||
*dst=0;
|
||||
}
|
||||
/*
|
||||
Concat two null-terminated strings dst=dst+src
|
||||
*/
|
||||
void string_concat(char *dst,char *src) {
|
||||
while (*dst) dst++;
|
||||
while (*src) { *dst=*src; dst++; src++; }
|
||||
*dst=0;
|
||||
}
|
||||
|
||||
/*
|
||||
Add predix to destiantion sting dst=src+dst
|
||||
*/
|
||||
void string_rconcat(char *dst,char *prefix) {
|
||||
char *p,*q;
|
||||
int i,pn=string_length(dst),qn=string_length(prefix);
|
||||
for(i=0;i<qn;i++) { dst[i+qn]=dst[i]; dst[i]=prefix[i]; }
|
||||
}
|
||||
|
||||
int string_length(char *s) {
|
||||
char *start=s; while (*s) s++;
|
||||
return (int)(s-start);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user