[sword-cvs] sword/src/utilfuns swbuf.cpp,NONE,1.1 Makefile.am,1.4,1.5
sword@www.crosswire.org
sword@www.crosswire.org
Wed, 19 Feb 2003 20:12:40 -0700
- Previous message: [sword-cvs] sword/lib Makefile.in,1.30,1.31
- Next message: [sword-cvs] sword/tests swbuftest.cpp,NONE,1.1 Makefile.am,1.10,1.11 Makefile.in,1.19,1.20 filtertest.cpp,1.15,1.16
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /usr/local/cvsroot/sword/src/utilfuns
In directory www:/tmp/cvs-serv14731/src/utilfuns
Modified Files:
Makefile.am
Added Files:
swbuf.cpp
Log Message:
Added utilfuns/swbuf.cpp and tests/swbuftest
Fixed make system to include osisrtf and osisplain
--- NEW FILE: swbuf.cpp ---
/******************************************************************************
* swbuf.cpp - code for SWBuf used as a transport and utility for data buffers
*
* $Id: swbuf.cpp,v 1.1 2003/02/20 03:12:37 scribe Exp $
*
* Copyright 2003 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#include <swbuf.h>
#include <string.h>
#include <stdlib.h>
SWORD_NAMESPACE_START
char *SWBuf::nullStr = "";
/******************************************************************************
* SWBuf Constructor - Creates an empty SWBuf object or an SWBuf initialized
* to a value from a const char *
*
*/
SWBuf::SWBuf(const char *initVal) {
if (initVal) {
allocSize = strlen(initVal)+1;
buf = (char *)calloc(allocSize + 5, 1);
memcpy(buf, initVal, allocSize);
end = buf + allocSize - 1;
allocSize += 5;
}
else {
allocSize = 15;
buf = (char *)calloc(allocSize, 1);
end = buf;
}
}
SWBuf::SWBuf(const SWBuf &other) {
allocSize = other.length()+1;
buf = (char *)calloc(allocSize + 5, 1);
memcpy(buf, other.buf, allocSize);
end = buf + allocSize - 1;
allocSize += 5;
}
SWBuf::SWBuf(char initVal) {
allocSize = 15;
buf = (char *)calloc(allocSize, 1);
*buf = initVal;
end = buf+1;
}
/******************************************************************************
* SWBuf Destructor - Cleans up instance of SWBuf
*/
SWBuf::~SWBuf() {
free(buf);
}
/******************************************************************************
* SWBuf::set - sets this buf to a new value
*/
void SWBuf::set(const char *newVal) {
unsigned int len = strlen(newVal) + 1;
assureSize(len);
memcpy(buf, newVal, len);
end = buf + (len-1);
}
/******************************************************************************
* SWBuf::set - sets this buf to a new value
*/
void SWBuf::set(const SWBuf &newVal) {
unsigned int len = newVal.length() + 1;
assureSize(len);
memcpy(buf, newVal.c_str(), len);
end = buf + (len-1);
}
/******************************************************************************
* SWBuf::append - appends a value to the current value of this SWBuf
*/
void SWBuf::append(const char *str) {
unsigned int len = strlen(str) + 1;
assureSize((end-buf)+len);
memcpy(end, str, len);
end += (len-1);
}
/******************************************************************************
* SWBuf::append - appends a value to the current value of this SWBuf
*/
void SWBuf::append(const SWBuf &str) {
unsigned int len = str.length() + 1;
assureSize((end-buf)+len);
memcpy(end, str.c_str(), len);
end += (len-1);
}
/******************************************************************************
* SWBuf::append - appends a value to the current value of this SWBuf
*/
void SWBuf::append(char ch) {
assureSize((end-buf)+1);
*end = ch;
end++;
*end = 0;
}
SWBuf SWBuf::operator +(const SWBuf &other) {
SWBuf retVal = buf;
retVal += other;
return retVal;
}
void SWBuf::assureSize(unsigned int size) {
if (size > allocSize) {
allocSize = size + 5;
end = (char *)(end - buf);
buf = (char *)realloc(buf, allocSize);
end = (buf + (unsigned int)end);
}
}
SWORD_NAMESPACE_END
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/sword/src/utilfuns/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile.am 30 Sep 2002 22:38:43 -0000 1.4
--- Makefile.am 20 Feb 2003 03:12:37 -0000 1.5
***************
*** 6,9 ****
--- 6,10 ----
libsword_la_SOURCES += $(utilfunsdir)/swunicod.cpp
libsword_la_SOURCES += $(utilfunsdir)/swversion.cpp
+ libsword_la_SOURCES += $(utilfunsdir)/swbuf.cpp
if MINGW
- Previous message: [sword-cvs] sword/lib Makefile.in,1.30,1.31
- Next message: [sword-cvs] sword/tests swbuftest.cpp,NONE,1.1 Makefile.am,1.10,1.11 Makefile.in,1.19,1.20 filtertest.cpp,1.15,1.16
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]