From 9a39532d953ac2a486635316ffd1970c993753de Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 9 Sep 2005 12:52:23 +0000 Subject: initial implementation of the counted string class completed (but so far only a very feature-less class). code compiles again. --- stringbuf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'stringbuf.c') diff --git a/stringbuf.c b/stringbuf.c index 11a1f5e4..0c5493d0 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -136,6 +136,7 @@ srRetVal rsCStrAppendChar(rsCStrObj *pThis, char c) char* rsCStrConvSzStrAndDestruct(rsCStrObj *pThis) { char* pRetBuf; + int i; sbSTRBCHECKVALIDOBJECT(pThis); @@ -153,6 +154,16 @@ char* rsCStrConvSzStrAndDestruct(rsCStrObj *pThis) *(pThis->pszBuf + pThis->iStrLen) = '\0'; } } + /* we now need to do a sanity check. The string mgiht contain a + * \0 byte. There is no way how a sz string can handle this. For + * the time being, we simply replace it with space - something that + * could definitely be improved (TODO). + * 2005-09-09 rgerhards + */ + for(i = 0 ; i < pThis->iStrLen ; ++i) { + if(*(pThis->pszBuf + i) == '\0') + *(pThis->pszBuf + i) = ' '; + } /* We got it, now free the object ourselfs. Please note * that we can NOT use the rsCStrDestruct function as it would @@ -202,6 +213,15 @@ void rsCStrSetAllocIncrement(rsCStrObj *pThis, int iNewIncrement) pThis->iAllocIncrement = iNewIncrement; } +/* return the length of the current string + * 2005-09-09 rgerhards + */ +int rsCStrLen(rsCStrObj *pThis) +{ + sbSTRBCHECKVALIDOBJECT(pThis); + return(pThis->iStrLen); +} + /* * Local variables: * c-indent-level: 8 -- cgit