This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] [TAKE 3] Add str_replace() To Tapsets


On Friday 19 Jun 2009 12:21:22 am Josh Stone wrote:
> On 06/18/2009 07:50 AM, Frank Ch. Eigler wrote:
> >> +function str_replace:string (prnt_str:string, srch_str:string,
> >> rplc_str:string) +%{
> >> +[...]
> >> +	if(strlen_srch_str == 0) {
> >> +		CONTEXT->last_error = "Invalid Search String";
> >> +		return;
> >> +	}
> >
> > FWIW, I wouldn't bother with signalling an error for this.  Just
> > define a fallback policy, such as returning the original prnt_str,
> > or perhaps an empty one.
>
> I was the one that suggested making it an error, but I don't feel
> strongly about that.  I would prefer returning the original string over
> an empty one.
>
> To compare what other programs do: s/pat/sub/ in vim and sed will reuse
> the previous pattern if given an empty pattern, but I don't think we
> should try to keep that state.  Perl's s/pat/sub/, awk's gsub(), and
> Python's str.replace() all will match alternating characters, so
> str_replace("abc", "", "x") would return "xaxbxcx".
>
>
> Josh

So, instead of using the error, i return the original string? If this is the 
case then in the testcase we dont need to handle errors as we will have none.
I will make these changes and send a patch.
-- 
Regards,
Varun Chandramohan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]