void AnyOption::processLine( char *theline, int length ) { bool found = false; char *pline = (char*) malloc( (length+1)*sizeof(char) ); for( int i = 0 ; i < length ; i ++ ) pline[i]= *(theline++); pline[length] = nullterminate; char *cursor = pline ; /* preserve the ptr */ if( *cursor == delimiter || *(cursor+length-1) == delimiter ){ justValue( pline );/* line with start/end delimiter */ }else{ for( int i = 1 ; i < length-1 && !found ; i++){/* delimiter */ if( *cursor == delimiter ){ *(cursor-1) = nullterminate; /* two strings */ found = true; valuePairs( pline , cursor+1 ); } cursor++; } cursor++; if( !found ) /* not a pair */ justValue( pline ); } free (pline); }
void AnyOption::processLine( char *theline, int length ) { if ((NULL == theline) || (0 == length)) return; bool found = false; char *pline = (char*) malloc( (length+1)*sizeof(char) ); for( int i = 0 ; i < length ; i ++ ) pline[i]= *(theline++); pline[length] = nullterminate; char *cursor = pline ; // preserve the ptr as pline, while we use cursor if( *cursor == delimiter || *(cursor+length-1) == delimiter ){ justValue( pline );/* line with start/end delimiter */ } else{ bool bFirstTime = true; for( int i = 1 ; i < length-1 && !found ; i++){// delimiter if( *cursor == delimiter ) { if (!bFirstTime) *(cursor-1) = nullterminate; // two strings else { *cursor = nullterminate; // cursor-1 could be OUTSIDE the allocation area... bFirstTime = false; } found = true; valuePairs( pline , cursor+1 ); } cursor++; } // for cursor++; if( !found ) /* not a pair */ justValue( pline ); } free (pline); }