Split a null terminated string using a single character as deliminator
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | SplitCstrOnChar | (hzVect<hzString>&,const char*,char,) |
Declared and defined in file: hzTextproc.cpp
Function Logic:
Function body:
hzEcode SplitCstrOnChar (hzVect<hzString>& ar)const char* input, char cDelim,
{
// Category: Text Processing
//
// Split a null terminated string using a single character 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) cDelim The delimiter
//
// 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
ar.Clear() ;
if (!input || !input[0])
return E_ARGUMENT ;
if (!cDelim)
cDelim = CHAR_COMMA ;
for (i = input ;; i++)
{
if (*i == 0|| *i == cDelim)
{
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 + 1;
}
if (*i == 0)
break ;
nPos++ ;
}
return E_OK ;
}