<commit_before>#ifndef CSVWRITER_H
#define CSVWRITER_H
#include <fstream>
#include <iostream>
#include <sstream>
#include <typeinfo>

using namespace std;
class CSVWriter
{
    public:
        CSVWriter(){
            this->firstRow = true;
            this->seperator = ";";
            this->columnNum = -1;
            this->valueCount = 0;
        }
        template<typename T>
        CSVWriter& add(T str){
            if(valueCount > 0)
                this->ss << this->seperator;
            this->ss << str;
            this->valueCount++;
            if(this->columnNum > -1){
                if(this->valueCount == this->columnNum){
                    this->newRow();
                }
            }
            return *this;
        }
        template<typename T>
        friend CSVWriter& operator<<(CSVWriter & csv, const T& t)
        {
            return csv.add(t);
        }

        string toString(){
            return ss.str();
        }

        friend ostream& operator<<(std::ostream& os, CSVWriter & csv){
            return os << csv.toString();
        }

        CSVWriter& newRow(){
            if(this->columnNum > -1 && autoEmptyFields){
                for(int i = valueCount; i < this->columnNum; i++)
                    this->ss << this->seperator;
            }
            if(firstRow){
                 ss << endl;
            }
            else{
                firstRow = false;
            }
            valueCount = 0;
            return *this;
        }
        bool writeToFile(string filename){
            return writeToFile(filename,false);
        }
        bool writeToFile(string filename, bool append){
            ofstream file;
            if(append)
                file.open(filename.c_str(),ios::out | ios::app);
            else
                file.open(filename.c_str(),ios::out | ios::trunc);
            if(!file.is_open())
                return false;
            if(append)
                file << endl;
            file << this->toString();
            file.close();
            return file.good();
        }
        void enableAutoNewRow(int numberOfColumns){
            this->columnNum = numberOfColumns;
        }
        void enableAutoEmptyFileds(bool autoEmptyFields){
            this->autoEmptyFields = autoEmptyFields;
        }
        void disableAutoNewRow(){
            this->columnNum = -1;
        }
        stringstream ss;
    private:
        bool firstRow;
        string seperator;
        int columnNum;
        int valueCount;
        bool autoEmptyFields;
};

#endif // CSVWRITER_H
<commit_msg>Fixed some bugs<commit_after>#ifndef CSVWRITER_H
#define CSVWRITER_H
#include <fstream>
#include <iostream>
#include <sstream>
#include <typeinfo>

using namespace std;
class CSVWriter
{
    public:
        CSVWriter(){
            this->firstRow = true;
            this->seperator = ";";
            this->columnNum = -1;
            this->valueCount = 0;
        }
        template<typename T>
        CSVWriter& add(T str){
            if(this->columnNum > -1){
                if(this->valueCount == this->columnNum ){
                    this->newRow();
                }
            }
            if(valueCount > 0)
                this->ss << this->seperator;
            this->ss << str;
            this->valueCount++;

            return *this;
        }
        template<typename T>
        friend CSVWriter& operator<<(CSVWriter & csv, const T& t)
        {
            return csv.add(t);
        }

        string toString(){
            return ss.str();
        }

        friend ostream& operator<<(std::ostream& os, CSVWriter & csv){
            return os << csv.toString();
        }

        CSVWriter& newRow(){
            if(this->ss.gcount() == 0){
                 ss << endl;
            }
            valueCount = 0;
            return *this;
        }
        bool writeToFile(string filename){
            return writeToFile(filename,false);
        }
        bool writeToFile(string filename, bool append){
            ofstream file;
            if(append)
                file.open(filename.c_str(),ios::out | ios::app);
            else
                file.open(filename.c_str(),ios::out | ios::trunc);
            if(!file.is_open())
                return false;
            if(append)
                file << endl;
            file << this->toString();
            file.close();
            return file.good();
        }
        void enableAutoNewRow(int numberOfColumns){
            this->columnNum = numberOfColumns;
        }
        void disableAutoNewRow(){
            this->columnNum = -1;
        }
        stringstream ss;
    private:
        bool firstRow;
        string seperator;
        int columnNum;
        int valueCount;
};

#endif // CSVWRITER_H

{'fraction_non_alphanumeric': 0.11411348991893577, 'fraction_numerical': 0.002909997921430056, 'mean_word_length': 1.3588235294117648, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3994352', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1297, 'n_words': 282}