<commit_before>#pragma once

#include <ctime>
#include <functional>
#include <limits>
#include <locale>
#include <memory>
#include <sstream>
#include <vector>
#include <ostream>

#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/range.hpp>
#include <boost/version.hpp>
#include <boost/utility.hpp>

namespace blackhole {
namespace detail {
namespace datetime {

template<typename Char, class Traits = std::char_traits<Char>>
class basic_oformatbuf : public std::basic_streambuf<Char, Traits> {
    typedef std::basic_streambuf<Char, Traits> base_type;

    fmt::MemoryWriter& wr;

public:
    typedef typename base_type::char_type char_type;
    typedef typename base_type::traits_type traits_type;
    typedef typename base_type::int_type int_type;
    typedef typename base_type::pos_type pos_type;
    typedef typename base_type::off_type off_type;

public:
    basic_oformatbuf(fmt::MemoryWriter& wr) :
        wr(wr)
    {
        base_type::setp(nullptr, nullptr);
    }

    int_type overflow(int_type ch) {
        if (!traits_type::eq_int_type(ch, traits_type::eof())) {
            wr << traits_type::to_char_type(ch);
            return ch;
        }

        return traits_type::not_eof(ch);
    }
};

class stream_type : public std::basic_ostream<char> {
    fmt::MemoryWriter& wr;
    basic_oformatbuf<char> streambuf;

public:
    stream_type(fmt::MemoryWriter& wr) :
        std::basic_ostream<char>(&streambuf),
        wr(wr),
        streambuf(wr)
    {}

    template<typename T>
    auto operator<<(const T& value) -> stream_type& {
        wr << value;
        return *this;
    }
};

struct context_t {
    stream_type wr;
    std::tm tm;
    std::uint64_t usec;

    context_t(fmt::MemoryWriter& wr, std::tm tm, std::uint64_t usec):
        wr(wr),
        tm(tm),
        usec(usec)
    {}
};

// TODO: Measure and replace with cppformat functions.
inline void fill(stream_type& wr, int value, uint length, char filler = '0') {
    char buffer[std::numeric_limits<uint32_t>::digits10 + 2];
    uint digits = 0;
    do {
        buffer[digits] = (value % 10) + '0';
        value /= 10;
        digits++;
    } while (value);

    BOOST_ASSERT(length >= digits);
    const uint gap = length - digits;
    for (uint i = 0; i < gap; ++i) {<commit_msg>docs(datetime): remove comment, it's faster<commit_after>#pragma once

#include <ctime>
#include <functional>
#include <limits>
#include <locale>
#include <memory>
#include <sstream>
#include <vector>
#include <ostream>

#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/range.hpp>
#include <boost/version.hpp>
#include <boost/utility.hpp>

namespace blackhole {
namespace detail {
namespace datetime {

template<typename Char, class Traits = std::char_traits<Char>>
class basic_oformatbuf : public std::basic_streambuf<Char, Traits> {
    typedef std::basic_streambuf<Char, Traits> base_type;

    fmt::MemoryWriter& wr;

public:
    typedef typename base_type::char_type char_type;
    typedef typename base_type::traits_type traits_type;
    typedef typename base_type::int_type int_type;
    typedef typename base_type::pos_type pos_type;
    typedef typename base_type::off_type off_type;

public:
    basic_oformatbuf(fmt::MemoryWriter& wr) :
        wr(wr)
    {
        base_type::setp(nullptr, nullptr);
    }

    int_type overflow(int_type ch) {
        if (!traits_type::eq_int_type(ch, traits_type::eof())) {
            wr << traits_type::to_char_type(ch);
            return ch;
        }

        return traits_type::not_eof(ch);
    }
};

class stream_type : public std::basic_ostream<char> {
    fmt::MemoryWriter& wr;
    basic_oformatbuf<char> streambuf;

public:
    stream_type(fmt::MemoryWriter& wr) :
        std::basic_ostream<char>(&streambuf),
        wr(wr),
        streambuf(wr)
    {}

    template<typename T>
    auto operator<<(const T& value) -> stream_type& {
        wr << value;
        return *this;
    }
};

struct context_t {
    stream_type wr;
    std::tm tm;
    std::uint64_t usec;

    context_t(fmt::MemoryWriter& wr, std::tm tm, std::uint64_t usec):
        wr(wr),
        tm(tm),
        usec(usec)
    {}
};

inline void fill(stream_type& wr, int value, uint length, char filler = '0') {
    char buffer[std::numeric_limits<uint32_t>::digits10 + 2];
    uint digits = 0;
    do {
        buffer[digits] = (value % 10) + '0';
        value /= 10;
        digits++;
    } while (value);

    BOOST_ASSERT(length >= digits);
    const uint gap = length - digits;
    for (uint i = 0; i < gap; ++i) {
{'fraction_non_alphanumeric': 0.1303395399780942, 'fraction_numerical': 0.007447973713033954, 'mean_word_length': 3.332068311195446, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 51, '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': '7133993', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1526, 'n_words': 355}