<commit_before>
/*
Author: <NAME> (<EMAIL>)
*/


#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<vector>

using namespace std;

vector<string> split( const string& line ){
    stringstream ss( line );
    vector<string> tokens;
    string token;
    while( !ss.eof() ){
        ss >> token;
        tokens.push_back( token );
    }
    return tokens;
}

void transpose( istream& in, ostream& out ){
    string line;
    vector< vector<string> > entries;
    vector<string> row;
    size_t maxLen = 0;
    while( getline( in, line ) ){
        row = split( line );
        entries.push_back( row );
        if( row.size() > maxLen ) maxLen = row.size();
    }

    //transpose
    for( size_t j = 0 ; j < maxLen ; ++j ){
        for( size_t i = 0 ; i < entries.size() ; ++i ){
            row = entries[i];
            if( j < row.size() ) out << row[j];
            out << " ";
        }
        out << endl;
    }

}

int main( int argc, const char* argv[] ){
    
    for( int i = 1 ; i < argc ; ++i ){
        string arg(argv[i]);
        if( arg == "--help" || arg == "-h" ){
            cerr << "Usage: transpose [FILES] [ < FILE ]" << endl;
            return 0;
        }
    }


    if( argc > 1 ){
        for( int i = 1 ; i < argc ; ++i ){
            ifstream in( argv[i] );
            if( in.is_open() ){
                transpose( in, cout );
                in.close();
            }else{
                cerr << "Unable to open file: " << argv[i] << endl;
            }
        }
    }else{
        transpose( cin, cout );
    }

}<commit_msg>added ability to transpose files in place<commit_after>
/*
Author: <NAME> (<EMAIL>)
*/


#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<vector>

using namespace std;

vector<string> split( const string& line ){
    stringstream ss( line );
    vector<string> tokens;
    string token;
    while( !ss.eof() ){
        token.clear();
        ss >> token;
        if( !token.empty() ){
            tokens.push_back( token );
        }
    }
    return tokens;
}

struct Transpose{

    vector< vector< string > > entries;
    size_t maxRow;

};

istream& operator>> ( istream& in, Transpose& t ){
    t.entries.clear();
    t.maxRow = 0;
    string line;
    vector<string> row;
    while( getline( in, line ) ){
        row = split( line );
        t.entries.push_back( row );
        if( row.size() > t.maxRow ) t.maxRow = row.size();
    }
    return in;
}

ostream& operator<< ( ostream& out, Transpose& t ){
    //transpose
    vector<string> row;
    for( size_t j = 0 ; j < t.maxRow ; ++j ){
        for( size_t i = 0 ; i < t.entries.size() ; ++i ){
            row = t.entries[i];
            if( j < row.size() ){
                out << row[j];
            }
            out << " ";
        }
        out << endl;
    }
    return out;
}

void usage( ostream& out ){
    out << "Usage: transpose [--help/-h] [--in-place/-i] [FILES] [ < FILE ]" << endl;
    out << "-i\t--in-place\tTransposes the files in place" << endl;
    out << "-h\t--help\tDisplays this help statement" << endl;
}

int main( int argc, const char* argv[] ){

    vector<const char*> files;
    bool inplace = false;
    
    for( int i = 1 ; i < argc ; ++i ){
        string arg(argv[i]);
        if( arg == "--help" || arg == "-h" ){
            usage( cerr );
            return 0;
        }else if( arg == "--in-place" || arg == "-i" ){
            inplace = true;
        }else{
            files.push_back( argv[i] );
        }
    }

    Transpose t;
    if( !files.empty() ){
        fstream fin;
        fstream fout;
        for( size_t i = 0 ; i < files.size() ; ++i ){
            fin.open( files[i], ios::in );
            if( fin.is_open() ){
                fin >> t;
                fin.close();
                if( inplace ){
                    fout.open( files[i], ios::out | ios::trunc );
                    if( fout.is_open() ){
                        fout << t;
                        fout.close();
                    }else{
                        cerr << "Unable to open file for writing: " << files[i] << endl;
                    }
                }else{
                    cout << t;
                }
            }else{
                cerr << "Unable to open file for reading: " << files[i] << endl;
            }
        }
    }else{
        cin >> t;
        cout << t;
    }

}
{'fraction_non_alphanumeric': 0.16145833333333334, 'fraction_numerical': 0.002943840579710145, 'mean_word_length': 1.4983031674208145, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 42, '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': '563938', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1425, 'n_words': 389}