<commit_before>#include "table.hpp"

#include <algorithm>
#include <cassert>
#include <sstream>

using autotab::table;

static size_t num_columns(std::string str)
{
    if(str.size() == 0)
        return 0;
    return std::count(str.begin(), str.end(), '\t') + 1;
}

static std::vector<std::string> split_columns(std::string str)
{
    std::stringstream strs(str);
    std::string column;
    std::vector<std::string> columns;

    while(std::getline(strs, column, '\t'))
    {
        columns.push_back(column);
    }

    return columns;
}

static size_t string_len(const std::string & str)
{
    return str.length();
}

static std::vector<size_t> get_stringlengths(const std::vector<std::string> &vec)
{
    std::vector<size_t> out(vec.size());
    
    std::transform(vec.begin(), vec.end(), out.begin(),
                          string_len);

    return out;
}

static std::vector<size_t> get_column_widths(const size_t num_columns, 
                               const std::vector< std::vector<std::string> > &t)<commit_msg>replaced std::getline with custom implementation<commit_after>#include "table.hpp"

#include <algorithm>
#include <cassert>
#include <sstream>

using autotab::table;

static size_t num_columns(std::string str)
{
    return std::count(str.begin(), str.end(), '\t') + 1;
}

static std::vector<std::string> split_columns(std::string str)
{
    std::vector<std::string> columns;

    size_t pos;

    while((pos = str.find_first_of('\t')) != str.npos)
    {
        // split string
        std::string cell = str.substr(0, pos);
        str = str.substr(pos+1);

        columns.push_back(cell);
    }

    // also add the last cell
    columns.push_back(str);

    return columns;
}

static size_t string_len(const std::string & str)
{
    return str.length();
}

static std::vector<size_t> get_stringlengths(const std::vector<std::string> &vec)
{
    std::vector<size_t> out(vec.size());
    
    std::transform(vec.begin(), vec.end(), out.begin(),
                          string_len);

    return out;
}

static std::vector<size_t> get_column_widths(const size_t num_columns, 
                               const std::vector< std::vector<std::string> > &t)
{'fraction_non_alphanumeric': 0.15799086757990868, 'fraction_numerical': 0.0027397260273972603, 'mean_word_length': 3.270955165692008, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6452779', 'n_tokens_mistral': 749, 'n_tokens_neox': 732, 'n_words': 147}