From 2c20ea6f04080f0ffb63ff9740a7fd25cd5625ac Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 17 Oct 2001 12:51:19 +0000 Subject: substitute and remove(string) return the number of changes made. --- include/SString.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include/SString.h') diff --git a/include/SString.h b/include/SString.h index 6ae65806a..e0354f401 100644 --- a/include/SString.h +++ b/include/SString.h @@ -279,17 +279,21 @@ public: bool contains(const char *sFind) { return search(sFind) >= 0; } - void substitute(char chFind, char chReplace) { + int substitute(char chFind, char chReplace) { + int c = 0; char *t = s; while (t) { t = strchr(t, chFind); if (t) { *t = chReplace; t++; + c++; } } + return c; } - void substitute(const char *sFind, const char *sReplace) { + int substitute(const char *sFind, const char *sReplace) { + int c = 0; int lenFind = strlen(sFind); int lenReplace = strlen(sReplace); int posFound = search(sFind); @@ -297,10 +301,12 @@ public: remove(posFound, lenFind); insert(posFound, sReplace, lenReplace); posFound = search(sFind, posFound + lenReplace); + c++; } + return c; } - void remove(const char *sFind) { - substitute(sFind, ""); + int remove(const char *sFind) { + return substitute(sFind, ""); } }; -- cgit v1.2.3