[sword-cvs] sword/include swbuf.h,1.6,1.7

sword@www.crosswire.org sword@www.crosswire.org
Thu, 27 Feb 2003 12:14:35 -0700


Update of /usr/local/cvsroot/sword/include
In directory www:/tmp/cvs-serv14574/include

Modified Files:
	swbuf.h 
Log Message:
fixes; more to follow


Index: swbuf.h
===================================================================
RCS file: /usr/local/cvsroot/sword/include/swbuf.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** swbuf.h	27 Feb 2003 10:41:18 -0000	1.6
--- swbuf.h	27 Feb 2003 19:14:32 -0000	1.7
***************
*** 39,45 ****
  	static char junkBuf[JUNKBUFSIZE];
  
! 	inline void assureSize(unsigned int size) {
! 		if (size > allocSize) {
! 			allocSize = size + 5;
  			end = (char *)(end - buf);
  			buf = (char *)realloc(buf, allocSize);
--- 39,45 ----
  	static char junkBuf[JUNKBUFSIZE];
  
! 	inline void assureSize(unsigned int newsize) {
! 		if (newsize > allocSize) {
! 			allocSize = newsize + 5;
  			end = (char *)(end - buf);
  			buf = (char *)realloc(buf, allocSize);
***************
*** 49,52 ****
--- 49,55 ----
  	void init();
  
+ 	inline const char *raw_buf() const{		return buf;	}
+ 
+ 
  public:
  	SWBuf(const char *initVal = 0);
***************
*** 59,64 ****
  	virtual ~SWBuf();
  
! 	inline const char *c_str() const { return buf; }
! 	inline char &charAt(unsigned int pos) { return ((pos <= (end - buf)) ? buf[pos] : nullStr[0]); }
  
  	inline unsigned int size() const { return length(); }
--- 62,75 ----
  	virtual ~SWBuf();
  
! 	//return null-terminated strings only!
! 	inline const char *c_str(){
! 		unsigned int size_cache = size();		
! 		if (buf[size_cache - 1] != 0){
! 			assureSize(size_cache + 2);
! 			buf[size_cache] = 0;
! 		}
! 		return buf;
! 	}
! 	inline char &charAt(unsigned int pos) { return ((pos <= (unsigned int)(end - buf)) ? buf[pos] : nullStr[0]); }
  
  	inline unsigned int size() const { return length(); }
***************
*** 70,74 ****
  	void append(const SWBuf &str);
  	inline void append(char ch) {
! 		assureSize((end-buf)+1);
  		*end = ch;
  		end++;
--- 81,85 ----
  	void append(const SWBuf &str);
  	inline void append(char ch) {
! 		assureSize((end-buf)+2);
  		*end = ch;
  		end++;
***************
*** 79,83 ****
  	inline char *getRawData() { return buf; }	// be careful!  Probably setSize needs to be called in conjunction before and maybe after
  
! 	inline operator const char *() const { return c_str(); }
  	inline char &operator[](unsigned int pos) { return charAt(pos); }
  	inline char &operator[](int pos) { return charAt((unsigned int)pos); }
--- 90,94 ----
  	inline char *getRawData() { return buf; }	// be careful!  Probably setSize needs to be called in conjunction before and maybe after
  
! 	inline operator const char *() { return c_str(); }
  	inline char &operator[](unsigned int pos) { return charAt(pos); }
  	inline char &operator[](int pos) { return charAt((unsigned int)pos); }
***************
*** 86,89 ****
--- 97,101 ----
  	inline SWBuf &operator +=(const char *str) { append(str); return *this; }
  	inline SWBuf &operator +=(char ch) { append(ch); return *this; }
+ 	inline SWBuf &operator +=(const SWBuf &str) { append(str); return *this; }
  	inline SWBuf &operator -=(unsigned int len) { setSize(length()-len); return *this; }
  	inline SWBuf &operator --(int) { operator -=(1); return *this; }