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 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


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