From: Andrew Tridgell Date: Mon, 23 Nov 1998 03:36:10 +0000 (+0000) Subject: changed string_sub() to replace " ; and ` in the inserted string with _ X-Git-Tag: samba-2.2.5pre1~5000 X-Git-Url: http://git.samba.org/?p=samba.git;a=commitdiff_plain;h=a3357ab49335106674fe7a7481cd0f146d74fbe5 changed string_sub() to replace " ; and ` in the inserted string with _ use all_string_sub() if you don't want this. --- diff --git a/source/include/proto.h b/source/include/proto.h index 08476bdd8f7..c4baa8f7a50 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -415,7 +415,8 @@ BOOL in_list(char *s,char *list,BOOL casesensitive); BOOL string_init(char **dest,const char *src); void string_free(char **s); BOOL string_set(char **dest,const char *src); -BOOL string_sub(char *s,const char *pattern,const char *insert); +void string_sub(char *s,const char *pattern,const char *insert); +void all_string_sub(char *s,const char *pattern,const char *insert); void split_at_last_component(char *path, char *front, char sep, char *back); /*The following definitions come from lib/util_unistr.c */ diff --git a/source/lib/util_str.c b/source/lib/util_str.c index c943a854cfa..dad0e854770 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -990,6 +990,7 @@ BOOL string_set(char **dest,const char *src) return(string_init(dest,src)); } + /**************************************************************************** substitute a string for a pattern in another string. Make sure there is enough room! @@ -997,31 +998,63 @@ enough room! This routine looks for pattern in s and replaces it with insert. It may do multiple replacements. -return True if a substitution was done. +any of " ; or ` in the insert string are replaced with _ ****************************************************************************/ -BOOL string_sub(char *s,const char *pattern,const char *insert) +void string_sub(char *s,const char *pattern,const char *insert) { - BOOL ret = False; - char *p; - size_t ls,lp,li; + char *p; + size_t ls,lp,li, i; + + if (!insert || !pattern || !s) return; + + ls = strlen(s); + lp = strlen(pattern); + li = strlen(insert); + + if (!*pattern) return; + + while (lp <= ls && (p = strstr(s,pattern))) { + memmove(p+li,p+lp,ls + 1 - (PTR_DIFF(p,s) + lp)); + for (i=0;i