sps.c
void printCell(Table *table, Cell *cell, FILE *f) {
    // just to be safe for cases, where there are tons of backslashes
    char buffer[2*strlen(cell->str) + 5];
    strcpy(buffer, cell->str);

    bool needsQuotes = false;
    needsQuotes = needsQuotes || strchr(cell->str, table->delim);
    needsQuotes = needsQuotes || strchr(cell->str, '\"');

    size_t i = 0;
    while (buffer[i] != '\0') {
        if (buffer[i] == '\"') {
            strins(&buffer[i], "\\");
            i++;
        }
        i++;
    }

    if (needsQuotes) {
        // if there is delimiter in the cell
        strins(buffer, "\"");
        strins(&buffer[strlen(buffer)], "\"");
    }
    fprintf(f, "%s", buffer);
}
// prints contents of one cell into a file
prints contents of one cell into a file
prints contents of one cell into a file
void printCell(Table *table, Cell *cell, FILE *f) {
    char buffer[2*strlen(cell->str) + 5];
    strcpy(buffer, cell->str);
    bool needsQuotes = false;
    needsQuotes = needsQuotes || strchr(cell->str, table->delim);
    needsQuotes = needsQuotes || strchr(cell->str, '\"');
    size_t i = 0;
    while (buffer[i] != '\0') {
        if (buffer[i] == '\"') {
            strins(&buffer[i], "\\");
            i++;
        }
        i++;
    }
    if (needsQuotes) {
        strins(buffer, "\"");
        strins(&buffer[strlen(buffer)], "\"");
    }
    fprintf(f, "%s", buffer);
}
void printCell ( Table * table , Cell * cell , FILE * f ) { char buffer [ 2 * strlen ( cell -> str ) + 5 ] ; strcpy ( buffer , cell -> str ) ; bool needsQuotes = false ; needsQuotes = needsQuotes || strchr ( cell -> str , table -> delim ) ; needsQuotes = needsQuotes || strchr ( cell -> str , ' \" ' ) ; size_t i = 0 ; while ( buffer [ i ] != ' \0 ' ) { if ( buffer [ i ] == ' \" ' ) { strins ( & buffer [ i ] , " \\ " ) ; i ++ ; } i ++ ; } if ( needsQuotes ) { strins ( buffer , " \" " ) ; strins ( & buffer [ strlen ( buffer ) ] , " \" " ) ; } fprintf ( f , " " , buffer ) ; }
prints contents of one cell into a file
prints contents of one cell into a file
// just to be safe for cases, where there are tons of backslashes // if there is delimiter in the cell