<commit_before>#ifndef MJOLNIR_UTIL_STATIC_STRING_HPP
#define MJOLNIR_UTIL_STATIC_STRING_HPP
#include <mjolnir/util/throw_exception.hpp>
#include <string>
#include <stdexcept>
#include <istream>
#include <ostream>
#include <cstdint>

namespace mjolnir
{

// static_string is a statically sized std::string, inspired by static_vector
// provided by Boost.Container.
// this is the minimal implementation for a specific perpose, so it doesn't have
// all the functionalities that exists in `std::string`. For example, it assumes
// that the character encoding is ascii. Basically, it can contain UTF-8 string
// as byte-array. But in that case, `size()` might not fit to the actual number
// of letters.
template<std::size_t N>
class static_string
{
    // because it contains '\0' delimiter at the end of buffer, the actual
    // free buffer size is N-1. static_string is to manage the size of object,
    // the clarity of the size is considered more important than the usability.
    static constexpr std::size_t capacity_ = N - 1;

    // to make code shorter.
    void check_size() const
    {
        if(this->size_ > this->capacity_)
        {
            throw_exception<std::length_error>("static_string (with capacity ",
                this->capacity_, ") cannot be constructed with string having ",
                this->size_, " length.");
        }
        return ;
    }

  public:

    using char_type              = char;
    using traits_type            = std::char_traits<char>;
    using container_type         = std::array<char, N>;

    using value_type             = typename container_type::value_type;
    using size_type              = typename container_type::size_type;
    using difference_type        = typename container_type::difference_type;
    using pointer                = typename container_type::pointer;
    using const_pointer          = typename container_type::const_pointer;
    using reference              = typename container_type::reference;
    using const_reference        = typename container_type::const_reference;
    using iterator               = typename container_type::iterator;
    using const_iterator         = typename container_type::const_iterator ;
    using reverse_iterator       = typename container_type::reverse_iterator;
    using const_reverse_iterator = typename container_type::const_reverse_iterator;

  public:

    static_string() : size_(0), buffer_{0} {}
    ~static_string() = default;
    static_string(static_string const&) = default;
    static_string(static_string &&)     = default;
    static_string& operator=(static_string const&) = default;
    static_string& operator=(static_string &&)     = default;

    explicit static_string(const char* literal): size_(traits_type::length(literal))
    {<commit_msg>fix: use std::array::fill in static_array<commit_after>#ifndef MJOLNIR_UTIL_STATIC_STRING_HPP
#define MJOLNIR_UTIL_STATIC_STRING_HPP
#include <mjolnir/util/throw_exception.hpp>
#include <string>
#include <stdexcept>
#include <istream>
#include <ostream>
#include <cstdint>

namespace mjolnir
{

// static_string is a statically sized std::string, inspired by static_vector
// provided by Boost.Container.
// this is the minimal implementation for a specific perpose, so it doesn't have
// all the functionalities that exists in `std::string`. For example, it assumes
// that the character encoding is ascii. Basically, it can contain UTF-8 string
// as byte-array. But in that case, `size()` might not fit to the actual number
// of letters.
template<std::size_t N>
class static_string
{
    // because it contains '\0' delimiter at the end of buffer, the actual
    // free buffer size is N-1. static_string is to manage the size of object,
    // the clarity of the size is considered more important than the usability.
    static constexpr std::size_t capacity_ = N - 1;

    // to make code shorter.
    void check_size() const
    {
        if(this->size_ > this->capacity_)
        {
            throw_exception<std::length_error>("static_string (with capacity ",
                this->capacity_, ") cannot be constructed with string having ",
                this->size_, " length.");
        }
        return ;
    }

  public:

    using char_type              = char;
    using traits_type            = std::char_traits<char>;
    using container_type         = std::array<char, N>;

    using value_type             = typename container_type::value_type;
    using size_type              = typename container_type::size_type;
    using difference_type        = typename container_type::difference_type;
    using pointer                = typename container_type::pointer;
    using const_pointer          = typename container_type::const_pointer;
    using reference              = typename container_type::reference;
    using const_reference        = typename container_type::const_reference;
    using iterator               = typename container_type::iterator;
    using const_iterator         = typename container_type::const_iterator ;
    using reverse_iterator       = typename container_type::reverse_iterator;
    using const_reverse_iterator = typename container_type::const_reverse_iterator;

  public:

    static_string() : size_(0) {buffer_.fill('\0');}
    ~static_string() = default;
    static_string(static_string const&) = default;
    static_string(static_string &&)     = default;
    static_string& operator=(static_string const&) = default;
    static_string& operator=(static_string &&)     = default;

    explicit static_string(const char* literal): size_(traits_type::length(literal))
    {
{'fraction_non_alphanumeric': 0.0880313000177841, 'fraction_numerical': 0.002134092121643251, 'mean_word_length': 3.1474926253687316, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, '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': '7224156', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1483, 'n_words': 464}