1 #include <str_replace.h>
9 str_replace(char** str, const char* what, const char* with)
15 if(!(begin = strstr(*str, what)))
25 /*while(begin[i] != ' ' && begin[i] != '\n' && begin[i] != '\r' && begin[i] != '\0')
35 if(!(buf = (char*) calloc(strlen(with) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char))))
40 if(pos < strlen(*str))
41 strcpy(buf + strlen(with), *str + pos);
45 if(!(buf = (char*) calloc((begin - *str) + strlen(with) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char))))
48 strncpy(buf, *str, (begin - *str));
49 strcpy(buf + (begin - *str) , with);
52 if(pos < strlen(*str))
53 strcpy(buf + (begin - *str) + strlen(with), *str + pos);
64 str_replace_all(char** str, const char* what, const char* with)
68 while(!(rv = str_replace(str, what, with)));
70 return (errno == ESRCH) ? 0 : -1;