[sword-svn] r3738 - trunk/include
scribe at crosswire.org
scribe at crosswire.org
Sun May 10 10:31:40 MST 2020
Author: scribe
Date: 2020-05-10 10:31:40 -0700 (Sun, 10 May 2020)
New Revision: 3738
Modified:
trunk/include/swbuf.h
Log:
Accept null as replace character in SWBuf::replaceBytes to remove remove target characters
Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h 2020-05-08 19:38:41 UTC (rev 3737)
+++ trunk/include/swbuf.h 2020-05-10 17:31:40 UTC (rev 3738)
@@ -454,11 +454,25 @@
/**
* Replace with a new byte value all occurances in this buffer of any byte value specified in a set
* @param targets a set of bytes, any of which will be replaced
- * @param newByte value to use as replacement.
+ * @param newByte value to use as replacement or 0 to remove matching byte.
*
* Example: replaceBytes("abc", 'z'); // replaces all occurances of 'a', 'b', and 'c' with 'z'
*/
- inline SWBuf &replaceBytes(const char *targets, char newByte) { for (unsigned int i = 0; (i < size()); i++) { if (strchr(targets, buf[i])) buf[i] = newByte; } return *this; }
+ inline SWBuf &replaceBytes(const char *targets, char newByte) {
+ for (unsigned int i = 0; (i < size()); i++) {
+ if (strchr(targets, buf[i])) {
+ if (newByte) buf[i] = newByte;
+ // delete byte
+ else {
+ if (i < (size()-1)) {
+ memmove(buf+i, buf+i+1, length()-i-1);
+ }
+ (*this)-=1;
+ }
+ }
+ }
+ return *this;
+ }
/**
* @return returns true if this buffer starts with the specified prefix
More information about the sword-cvs
mailing list