Split a null terminated string using another null terminated string as deliminator
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | SplitCstrOnCstr | (hzArray<hzString>&,const char*,const char*,) |
Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp
Function Logic:
Function body:
hzEcode SplitCstrOnCstr (hzArray<hzString>& ar)const char* input, const char* delim,
{
// Category: Text Processing
//
// Split a null terminated string using another null terminated string as deliminator
//
// Arguments: 1) ar A vector of hzString that is populated by this operation
// 2) input The input null terminated string to be split
// 3) delim The delimiter string
//
// Returns: E_ARGUMENT If either the input or delimiter is not supplied
// E_OK If the input was processed
const char* i ; // Iterator
hzString S ; // Value acceptor
uint32_t nRef = 0; // Reference position
uint32_t nPos = 0; // Position reached so far
uint32_t nLen ; // Delimiter length
ar.Clear() ;
if (!input || !input[0])return E_ARGUMENT ;
if (!delim || !delim[0])return E_ARGUMENT ;
nLen = strlen(delim) ;
for (i = input ;;)
{
if (*i == 0)
{
if (nPos > nRef)
{
// j = S._blank(nPos - nRef) ;
// memcpy(j, input + nRef, nPos - nRef) ;
S.SetValue(input + nRef, nPos - nRef) ;
}
ar.Add(S) ;
break ;
}
if (*i == delim[0])
{
if (CstrCompare(i, delim))
{
if (nPos > nRef)
{
// j = S._blank(nPos - nRef) ;
// memcpy(j, input + nRef, nPos - nRef) ;
S.SetValue(input + nRef, nPos - nRef) ;
}
ar.Add(S) ;
S.Clear() ;
nRef = nPos + nLen ;
i += nLen ;
nPos += nLen ;
continue ;
}
}
i++ ; nPos++ ;
}
return E_OK ;
}