[sword-svn] r1714 - in trunk: include src/mgr src/utilfuns

scribe at crosswire.org scribe at crosswire.org
Sun Feb 6 17:31:10 MST 2005


Author: scribe
Date: 2005-02-06 17:31:09 -0700 (Sun, 06 Feb 2005)
New Revision: 1714

Modified:
   trunk/include/swbuf.h
   trunk/src/mgr/filemgr.cpp
   trunk/src/mgr/stringmgr.cpp
   trunk/src/utilfuns/swbuf.cpp
Log:
Removed extraneous const qualifiers.
Fixed append to not do a strlen if max is passed
Fixed getLine bug
Fixed delete [] in stringmgr.cpp

Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h	2005-02-06 01:14:11 UTC (rev 1713)
+++ trunk/include/swbuf.h	2005-02-07 00:31:09 UTC (rev 1714)
@@ -186,7 +186,7 @@
 	* @param str Append this.
 	* @param max Append only max chars.
  	*/
-	void append(const char *str, const long max = -1);
+	void append(const char *str, long max = -1);
 
 	/**
 	* SWBuf::append - appends a value to the current value of this SWBuf
@@ -194,14 +194,14 @@
 	* @param str Append this.
 	* @param max Append only max chars.
 	*/
-	inline void append(const SWBuf &str, const long max = -1) { append(str.c_str(), max); }
+	inline void append(const SWBuf &str, long max = -1) { append(str.c_str(), max); }
 
 	/**
 	* SWBuf::append - appends a value to the current value of this SWBuf
 	* If the allocated memory is not enough, it will be resized accordingly.
 	* @param ch Append this.
 	*/
-	inline void append(const char ch) {
+	inline void append(char ch) {
 		assureMore(1);
 		*end++ = ch;
 		*end = 0;
@@ -222,7 +222,7 @@
 	*
 	* @param format The format string. Same syntax as printf, for example.
 	* @param ... Add all arguments here.
- 	*/
+	*/
 	void appendFormatted(const char *format, ...);
 	
 	/** 
@@ -231,14 +231,14 @@
 	* @param str Insert this.
 	* @param max Insert only max chars.
 	*/
-	void insert(const unsigned long pos, const char* str, const signed long max = -1 );
+	void insert(unsigned long pos, const char* str, signed long max = -1 );
 	/** 
 	* SWBuf::insert - inserts the given string at position into this string
 	* @param pos The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s)
 	* @param str Insert this.
 	* @param max Insert only max chars.
 	*/
-	void insert(const unsigned long pos, const SWBuf &str, const signed long max = -1 ) {
+	void insert(unsigned long pos, const SWBuf &str, signed long max = -1 ) {
 		insert(pos, str.c_str(), max);
 	};
 	/** 
@@ -246,7 +246,7 @@
 	* @param pos The position where to insert. pos=0 inserts at the beginning, pos=1 after the first char, etc. Using pos=length() is the same as calling append(s)
 	* @param c Insert this.
 	*/
-	void insert(const unsigned long pos, const char c) {
+	void insert(unsigned long pos, char c) {
 		insert(pos, SWBuf(c));
 	}
 	/** SWBuf::getRawData

Modified: trunk/src/mgr/filemgr.cpp
===================================================================
--- trunk/src/mgr/filemgr.cpp	2005-02-06 01:14:11 UTC (rev 1713)
+++ trunk/src/mgr/filemgr.cpp	2005-02-07 00:31:09 UTC (rev 1714)
@@ -409,8 +409,8 @@
 
 		// find the end
 		int end;
-		for (end = start; ((end < 254) && (chunk[end] != 10)); end++);
-		if (end > 253)
+		for (end = start; ((end < (len-1)) && (chunk[end] != 10)); end++);
+		if (end >= 253)
 			more = true;
 		index += (end + 1);
 

Modified: trunk/src/mgr/stringmgr.cpp
===================================================================
--- trunk/src/mgr/stringmgr.cpp	2005-02-06 01:14:11 UTC (rev 1713)
+++ trunk/src/mgr/stringmgr.cpp	2005-02-07 00:31:09 UTC (rev 1714)
@@ -174,8 +174,8 @@
 		);
 		if (err != U_ZERO_ERROR) {
 			SWLog::getSystemLog()->logError("from: %s", u_errorName(err));
-			delete lowerStr;
-			delete upperStr;
+			delete [] lowerStr;
+			delete [] upperStr;
 			return ret;
 		}
 		
@@ -189,8 +189,8 @@
 		);
 		if (err != U_ZERO_ERROR) {
 			SWLog::getSystemLog()->logError("upperCase: %s", u_errorName(err));
-			delete lowerStr;
-			delete upperStr;
+			delete [] lowerStr;
+			delete [] upperStr;
 			return ret;
 		}
 
@@ -203,8 +203,8 @@
 			&err
 		);
 		
-		delete lowerStr;
-		delete upperStr;
+		delete [] lowerStr;
+		delete [] upperStr;
 		return ret;
 	}
 	

Modified: trunk/src/utilfuns/swbuf.cpp
===================================================================
--- trunk/src/utilfuns/swbuf.cpp	2005-02-06 01:14:11 UTC (rev 1713)
+++ trunk/src/utilfuns/swbuf.cpp	2005-02-07 00:31:09 UTC (rev 1714)
@@ -140,15 +140,14 @@
 * SWBuf::append - appends a value to the current value of this SWBuf
 * 
 */
-void SWBuf::append(const char *str, const long max) {
+void SWBuf::append(const char *str, long max) {
 //	if (!str) //A null string was passed
 //		return;
-	//make sure we only copy strlen(str) bytes if max is larger than strlen(str) is
-	unsigned long str_len = strlen( str );
-	unsigned long len = (max > -1) ? ((max <= str_len) ? max : str_len) : str_len;
-	assureMore(++len);
-	memcpy(end, str, len-1);
-	end += (len-1);
+	if (max < 0)
+		max = strlen(str);
+	assureMore(max+1);
+	for (;((*str)&&(max));max--)
+		*end++ = *str++;
 	*end = 0;
 }
 
@@ -180,11 +179,11 @@
 	va_end(argptr);
 }
 
-void SWBuf::insert(const unsigned long pos, const char* str, const signed long max) {
+void SWBuf::insert(unsigned long pos, const char* str, signed long max) {
 // 	if (!str) //A null string was passed
 // 		return;
 
-	const int len = (max > -1) ? max : strlen(str);
+	int len = (max > -1) ? max : strlen(str);
 
 	if (!len || (pos > length())) //nothing to do, return
 		return;



More information about the sword-cvs mailing list