[sword-cvs] sword/src/utilfuns swbuf.cpp,1.8,1.9 utilxml.cpp,1.7,1.8
sword@www.crosswire.org
sword@www.crosswire.org
Wed, 25 Jun 2003 21:33:34 -0700
Update of /usr/local/cvsroot/sword/src/utilfuns
In directory www:/tmp/cvs-serv9597/src/utilfuns
Modified Files:
swbuf.cpp utilxml.cpp
Log Message:
no message
Index: swbuf.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/utilfuns/swbuf.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** swbuf.cpp 27 Feb 2003 23:57:55 -0000 1.8
--- swbuf.cpp 26 Jun 2003 04:33:31 -0000 1.9
***************
*** 38,54 ****
*/
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;
- }
init();
}
--- 38,43 ----
*/
SWBuf::SWBuf(const char *initVal) {
init();
+ set(initVal);
}
***************
*** 59,68 ****
*/
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;
init();
}
--- 48,53 ----
*/
SWBuf::SWBuf(const SWBuf &other) {
init();
+ set(other);
}
***************
*** 73,85 ****
*/
SWBuf::SWBuf(char initVal) {
allocSize = 15;
buf = (char *)calloc(allocSize, 1);
*buf = initVal;
end = buf+1;
- init();
}
void SWBuf::init() {
fillByte = ' ';
}
--- 58,74 ----
*/
SWBuf::SWBuf(char initVal) {
+ init();
+
allocSize = 15;
buf = (char *)calloc(allocSize, 1);
*buf = initVal;
end = buf+1;
}
void SWBuf::init() {
fillByte = ' ';
+ allocSize = 0;
+ buf = 0;
+ end = 0;
}
***************
*** 88,92 ****
*/
SWBuf::~SWBuf() {
! free(buf);
}
--- 77,82 ----
*/
SWBuf::~SWBuf() {
! if (buf)
! free(buf);
}
***************
*** 95,102 ****
*/
void SWBuf::set(const char *newVal) {
! unsigned int len = strlen(newVal) + 1;
! assureSize(len);
! memcpy(buf, newVal, len);
! end = buf + (len-1);
}
--- 85,99 ----
*/
void SWBuf::set(const char *newVal) {
! if (newVal) {
! unsigned int len = strlen(newVal) + 1;
! assureSize(len);
! memcpy(buf, newVal, len);
! end = buf + (len - 1);
! }
! else {
! assureSize(1);
! end = buf;
! *end = 0;
! }
}
Index: utilxml.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/utilfuns/utilxml.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** utilxml.cpp 25 Jun 2003 22:09:15 -0000 1.7
--- utilxml.cpp 26 Jun 2003 04:33:31 -0000 1.8
***************
*** 115,124 ****
! const char *XMLTag::getAttribute(const char *attribName) const {
if (!parsed)
parse();
MapStringPair::iterator it = attributes.find(attribName);
! return (it == attributes.end()) ? 0 : it->second.c_str();
}
--- 115,157 ----
! const char *XMLTag::getPart(const char *buf, int partNum, char partSplit) const {
! for (; (buf && partNum); partNum--) {
! buf = strchr(buf, partSplit);
! if (buf)
! buf++;
! }
! if (buf) {
! const char *end = strchr(buf, partSplit);
! junkBuf = buf;
! if (end)
! junkBuf.setSize(end - buf);
! return junkBuf.c_str();
! }
! return 0;
! }
!
!
! int XMLTag::getAttributePartCount(const char *attribName, char partSplit) const {
! int count;
! const char *buf = getAttribute(attribName);
! for (count = 0; buf; count++) {
! buf = strchr(buf, partSplit);
! if (buf)
! buf++;
! }
! return count;
! }
!
!
! const char *XMLTag::getAttribute(const char *attribName, int partNum, char partSplit) const {
if (!parsed)
parse();
MapStringPair::iterator it = attributes.find(attribName);
! const char *retVal = (it == attributes.end()) ? 0 : it->second.c_str();
! if ((retVal) && (partNum > -1))
! retVal = getPart(retVal, partNum, partSplit);
!
! return retVal;
}