[sword-cvs] sword/src/utilfuns swbuf.cpp,1.14,1.15

sword@www.crosswire.org sword@www.crosswire.org
Sun, 29 Feb 2004 16:26:19 -0700


Update of /cvs/core/sword/src/utilfuns
In directory www:/tmp/cvs-serv31359/src/utilfuns

Modified Files:
	swbuf.cpp 
Log Message:
SWBuf::insert added, tested, works for me. Needed to make the gbfosis filter working (jansorg)

Index: swbuf.cpp
===================================================================
RCS file: /cvs/core/sword/src/utilfuns/swbuf.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- swbuf.cpp	13 Aug 2003 03:56:14 -0000	1.14
+++ swbuf.cpp	29 Feb 2004 23:26:17 -0000	1.15
@@ -160,4 +160,25 @@
 	va_end(argptr);
 }
 
+void SWBuf::insert(const unsigned long pos, const char* str, const signed long max) {
+	const int len = (max > -1) ? max : strlen(str);
+
+	if (!len || (pos > length())) //nothing to do, return
+		return;
+	
+	// pos==length(), so we can call append in this case
+	if (pos == length()) { //append is more efficient
+		append(str, max);
+		return;
+	}
+	
+	assureMore( len );
+	
+	memmove(buf + pos + len, buf + pos, (end - buf) - pos); //make a gap of "len" bytes
+	memcpy(buf+pos, str, len);
+	
+	end += len;
+	*end = 0;
+}
+
 SWORD_NAMESPACE_END