1 #include <str_replace.h>
\r
9 str_replace(char** str, const char* what, const char* with)
\r
15 if(!(begin = strstr(*str, what)))
\r
25 pos += strlen(what);
\r
29 if(!(buf = (char*) calloc(strlen(with) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char))))
\r
34 if(pos < strlen(*str))
\r
35 strcpy(buf + strlen(with), *str + pos);
\r
39 if(!(buf = (char*) calloc((begin - *str) + strlen(with) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char))))
\r
42 strncpy(buf, *str, (begin - *str));
\r
43 strcpy(buf + (begin - *str) , with);
\r
46 if(pos < strlen(*str))
\r
47 strcpy(buf + (begin - *str) + strlen(with), *str + pos);
\r
58 str_replace_all(char** str, const char* what, const char* with)
\r
62 while(!(rv = str_replace(str, what, with)));
\r
64 return (errno == ESRCH) ? 0 : -1;
\r