sps.c
size_t parseString(char *dst, char *src, char *delims) {
    int srcIndex = 0, dstIndex = 0;
    bool isQuoted = false;
    bool isEscaped = false;
    bool expectingEnd = false;

    for (; src[srcIndex] != '\0'; srcIndex++) {
        // if escape character
        if ((src[srcIndex] == '\\') && !isEscaped) {
            isEscaped = true;
            continue;
        }
        // only first character can start quoted cell
        if ((src[srcIndex] == '\"') && (srcIndex == 0)) {
            isQuoted = true;
            continue;
        }
        // ending quotation
        if ((src[srcIndex] == '\"') && !isEscaped && isQuoted) {
            isQuoted = false;
            expectingEnd = true;
            continue;
        }
        // if scanned character is delimiter
        if (strchr(delims, src[srcIndex]) && !isEscaped && !isQuoted)
            break;
        // check for \n is after check for escape character
        // it is the only character, that cannot be escaped
        if (src[srcIndex] == '\n')  {
            // it is illegal to escape or quote '\n'
            if (isEscaped || isQuoted)
                return 0;
            break;
        }
        // if the string should have ended, there is something wrong
        if (expectingEnd && src[srcIndex] != ']')
            return 0;
        // if there is nothing special about the characters
        // write it into the buffer
        dst[dstIndex] = src[srcIndex];
        isEscaped = false;
        dstIndex++;
    }
    if (isQuoted)
        return 0;

    dst[dstIndex] = '\0';
    return srcIndex;
}
// gets rid of all the escape characters
// quotation marks etc.
// returns how many characters in original string were parsed
gets rid of all the escape characters
quotation marks etc.
returns how many characters in original string were parsed
gets rid of all the escape characters quotation marks etc . returns how many characters in original string were parsed
size_t parseString(char *dst, char *src, char *delims) {
    int srcIndex = 0, dstIndex = 0;
    bool isQuoted = false;
    bool isEscaped = false;
    bool expectingEnd = false;
    for (; src[srcIndex] != '\0'; srcIndex++) {
        if ((src[srcIndex] == '\\') && !isEscaped) {
            isEscaped = true;
            continue;
        }
        if ((src[srcIndex] == '\"') && (srcIndex == 0)) {
            isQuoted = true;
            continue;
        }
        if ((src[srcIndex] == '\"') && !isEscaped && isQuoted) {
            isQuoted = false;
            expectingEnd = true;
            continue;
        }
        if (strchr(delims, src[srcIndex]) && !isEscaped && !isQuoted)
            break;
        if (src[srcIndex] == '\n')  {
            if (isEscaped || isQuoted)
                return 0;
            break;
        }
        if (expectingEnd && src[srcIndex] != ']')
            return 0;
        dst[dstIndex] = src[srcIndex];
        isEscaped = false;
        dstIndex++;
    }
    if (isQuoted)
        return 0;
    dst[dstIndex] = '\0';
    return srcIndex;
}
size_t parseString ( char * dst , char * src , char * delims ) { int srcIndex = 0 , dstIndex = 0 ; bool isQuoted = false ; bool isEscaped = false ; bool expectingEnd = false ; for ( ; src [ srcIndex ] != ' \0 ' ; srcIndex ++ ) { if ( ( src [ srcIndex ] == ' \\ ' ) && ! isEscaped ) { isEscaped = true ; continue ; } if ( ( src [ srcIndex ] == ' \" ' ) && ( srcIndex == 0 ) ) { isQuoted = true ; continue ; } if ( ( src [ srcIndex ] == ' \" ' ) && ! isEscaped && isQuoted ) { isQuoted = false ; expectingEnd = true ; continue ; } if ( strchr ( delims , src [ srcIndex ] ) && ! isEscaped && ! isQuoted ) break ; if ( src [ srcIndex ] == ' \n ' ) { if ( isEscaped || isQuoted ) return 0 ; break ; } if ( expectingEnd && src [ srcIndex ] != ' ' ) return 0 ; dst [ dstIndex ] = src [ srcIndex ] ; isEscaped = false ; dstIndex ++ ; } if ( isQuoted ) return 0 ; dst [ dstIndex ] = ' \0 ' ; return srcIndex ; }
gets rid of all the escape characters
quotation marks etc.
gets rid of all the escape characters quotation marks etc .
// if escape character // only first character can start quoted cell // ending quotation // if scanned character is delimiter // check for \n is after check for escape character // it is the only character, that cannot be escaped // it is illegal to escape or quote '\n' // if the string should have ended, there is something wrong // if there is nothing special about the characters // write it into the buffer