This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH 1/2] [TAKE 3] Add str_replace() To Tapsets
- From: Josh Stone <jistone at redhat dot com>
- To: "Frank Ch. Eigler" <fche at redhat dot com>
- Cc: Varun Chandramohan <varunc at linux dot vnet dot ibm dot com>, systemtap at sourceware dot org
- Date: Thu, 18 Jun 2009 11:51:22 -0700
- Subject: Re: [PATCH 1/2] [TAKE 3] Add str_replace() To Tapsets
- References: <20090618152905.e10b4ce1.varunc@linux.vnet.ibm.com> <y0mprd11tqy.fsf@fche.csb>
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