Update of /cvsroot/monetdb/MonetDB5/src/modules/kernel
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv14381/src/modules/kernel
Modified Files:
batstr.mx
Log Message:
added batstr.replace
fixed hassideeffects: str.replace isn't unsafe (only bat.replace is)
some indent/space fixes
Index: batstr.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/kernel/batstr.mx,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- batstr.mx 23 Dec 2007 11:47:48 -0000 1.56
+++ batstr.mx 27 Dec 2007 17:27:08 -0000 1.57
@@ -155,6 +155,11 @@
command batstr.like(s:bat[:oid,:str],pat:str,esc:str):bat[:oid,:oid]
address STRbatlike
comment "Perform SQL like operation against a string bat";
+
+command batstr.replace(s:bat[:oid,:str],pat:str,s2:str):bat[:oid,:str]
+address STRbatreplace
+comment "Insert a string into another";
+
@+ Implementation
@c
#include "mal_config.h"
@@ -725,4 +730,43 @@
BBPunfix(*ret);
throw(MAL, "batstr.substring" , "bunins failed");
}
+
+batstr_export str STRbatreplace(int *ret, int *l, str *pat, str *s2);
+str STRbatreplace(int *ret, int *l, str *pat, str *s2)
+{
+ BATiter li;
+ BAT *bn, *left;
+ BUN p,q;
+ str v, *vp= &v;
+
+ if( (left= BATdescriptor(*l)) == NULL )
+ throw(MAL, "batstr.replace" , "Cannot access descriptor");
+ bn= BATnew(left->htype,TYPE_str,BATcount(left));
+ if (left->htype== TYPE_void)
+ BATseqbase(bn, left->hseqbase);
+ if (bn == NULL){
+ BBPreleaseref(left->batCacheid);
+ throw(MAL, "batstr.replace", "no space available ");
+ }
+ bn->hsorted= left->hsorted;
+ bn->tsorted=0;
+
+ li = bat_iterator(left);
+ BATloop(left, p, q) {
+ ptr h = BUNhead(li,p);
+ str tl = (str) BUNtail(li,p);
+ STRreplace(vp, &tl, pat, s2);
+ bunfastins(bn, h, *vp);
+ GDKfree(*vp);
+ }
+ finalizeResult(ret,bn,left);
+ return MAL_SUCCEED;
+
+bunins_failed:
+ BBPreleaseref(left->batCacheid);
+ BBPunfix(*ret);
+ throw(MAL, "batstr.replace" , "bunins failed");
+}
+
+
@}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins