* [PATCH 1/2] Add str_replace() To Tapsets
@ 2009-06-20 4:08 Varun Chandramohan
2009-06-22 21:49 ` Josh Stone
0 siblings, 1 reply; 2+ messages in thread
From: Varun Chandramohan @ 2009-06-20 4:08 UTC (permalink / raw)
To: systemtap; +Cc: Josh Stone, Frank Ch. Eigler
This patch adds a search and replace string functionality to existing tapsets.
The functionality is as follows:
The function takes in a parent string and searches for a substring as specified by the user. If substing not found, the parent string is returned. If substring is found, it is replaced by another string and returned.
NOTE: The function will search and replace all the occurance of substrings in a parent string when matched.
Signed-off-by: Varun Chandramohan <varunc@linux.vnet.ibm.com>
---
tapset/string.stp | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/tapset/string.stp b/tapset/string.stp
index 35ee9fa..bf5b3be 100644
--- a/tapset/string.stp
+++ b/tapset/string.stp
@@ -91,6 +91,39 @@ function tokenize:string(input:string, delim:string)
strncpy (THIS->__retvalue, token, MAXSTRINGLEN);
%}
+/** @addtogroup library
+ * @code str_replace:string (prnt_str:string, srch_str:string, rplc_str:string) @endcode
+ * @param prnt_str The parent string.
+ * @param srch_str The substring which is used to search in the parent string prnt_str.
+ * @param rplc_str The substring which is used to replace the searched string srch_str.
+ * @return Returns the parent string with substrings replaced. Else returns parent string.
+ */
+function str_replace:string (prnt_str:string, srch_str:string, rplc_str:string)
+%{
+ char *ptr = THIS->prnt_str;
+ char *ptr_base = THIS->prnt_str;
+ int strlen_prnt_str = strlen(THIS->prnt_str);
+ int strlen_srch_str = strlen(THIS->srch_str);
+ int strlen_rplc_str = strlen(THIS->rplc_str);
+
+ if(strlen_srch_str == 0) {
+ strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN);
+ return;
+ }
+
+ while((ptr = strstr(ptr, THIS->srch_str)) != NULL) {
+
+ *ptr = '\0';
+ strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN);
+ strlcat(THIS->__retvalue, THIS->rplc_str, MAXSTRINGLEN);
+ ptr = ptr + strlen_srch_str;
+ ptr_base = ptr;
+ }
+
+ strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN);
+ return;
+%}
+
/*
* strtol - Convert a string to a long
* str String to convert
--
1.6.0.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/2] Add str_replace() To Tapsets
2009-06-20 4:08 [PATCH 1/2] Add str_replace() To Tapsets Varun Chandramohan
@ 2009-06-22 21:49 ` Josh Stone
0 siblings, 0 replies; 2+ messages in thread
From: Josh Stone @ 2009-06-22 21:49 UTC (permalink / raw)
To: Varun Chandramohan; +Cc: systemtap, Frank Ch. Eigler
On 06/19/2009 09:07 PM, Varun Chandramohan wrote:
> This patch adds a search and replace string functionality to existing tapsets.
>
> The functionality is as follows:
>
> The function takes in a parent string and searches for a substring as specified by the user. If substing not found, the parent string is returned. If substring is found, it is replaced by another string and returned.
> NOTE: The function will search and replace all the occurance of substrings in a parent string when matched.
>
> Signed-off-by: Varun Chandramohan <varunc@linux.vnet.ibm.com>
> ---
This and your testcase are now committed, thanks!
Josh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-06-22 21:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-20 4:08 [PATCH 1/2] Add str_replace() To Tapsets Varun Chandramohan
2009-06-22 21:49 ` Josh Stone
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).