<commit_before>#pragma once

#include "Types.h"

#include <opencv2/core/types.hpp>
#include <json11.hpp>
#include <algorithm>
#include <iterator>
#include <cstdio>

namespace yarrar {

template<typename Container, typename Value>
bool contains(const Container& c, const Value& v) 
{
    return std::find(std::begin(c), std::end(c), v) != std::end(c);
}

template<typename... Args>
std::string format(const std::string& format, Args... args)
{
    int neededSize = snprintf(nullptr, 0, format.c_str(), args...);

    // If there was an error return the original string.
    if(neededSize <= 0)
        return format;

    neededSize += 1;
    std::vector<char> buf(static_cast<size_t> (neededSize));
    snprintf(&buf.front(), static_cast<size_t> (neededSize), format.c_str(), args...);
    return std::string(&buf.front());
}

cv::Size getScaledDownResolution(const int width,
                                 const int height,
                                 const int preferredWidth);

void rotate(const cv::Mat& src, cv::Mat& dst, const yarrar::Rotation90& rotation);

json11::Json loadJson(const std::string& filePath);

}<commit_msg>Use std::string straight instead of vector<char> in format().<commit_after>#pragma once

#include "Types.h"

#include <opencv2/core/types.hpp>
#include <json11.hpp>
#include <algorithm>
#include <iterator>
#include <cstdio>

namespace yarrar {

template<typename Container, typename Value>
bool contains(const Container& c, const Value& v) 
{
    return std::find(std::begin(c), std::end(c), v) != std::end(c);
}

template<typename... Args>
std::string format(const std::string& format, Args... args)
{
    int neededSize = snprintf(nullptr, 0, format.c_str(), args...);

    // If there was an error return the original string.
    if(neededSize <= 0)
        return format;

    // Accommodate \0
    neededSize += 1;

    std::string buf;
    buf.resize(static_cast<size_t> (neededSize));
    snprintf(&buf.front(), static_cast<size_t> (neededSize), format.c_str(), args...);
    return buf;
}

cv::Size getScaledDownResolution(const int width,
                                 const int height,
                                 const int preferredWidth);

void rotate(const cv::Mat& src, cv::Mat& dst, const yarrar::Rotation90& rotation);

json11::Json loadJson(const std::string& filePath);

}
{'fraction_non_alphanumeric': 0.14719726144629866, 'fraction_numerical': 0.008985879332477536, 'mean_word_length': 3.5222437137330753, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2594740', 'n_tokens_mistral': 759, 'n_tokens_neox': 734, 'n_words': 198}