aoc-2025/libguf/test/test_utf8.hpp
2025-12-23 21:13:41 +01:00

37 lines
963 B
C++
Executable File

#pragma once
#include <vector>
#include "test.hpp"
extern "C"
{
#include "impls/dbuf_impl.h"
#include "guf_alloc_libc.h"
}
struct UTF8Test : public Test
{
UTF8Test(const std::string& nm) : Test(nm)
{
allocator_ctx.zero_init = false;
guf_alloc_tracker_init(&allocator_ctx.tracker, 5, "UTF8Test_allocator", NULL, NULL);
guf_libc_allocator_init(&allocator, &allocator_ctx);
};
void run() override;
private:
guf_allocator allocator;
guf_libc_alloc_ctx allocator_ctx;
dbuf_char text_buf {};
std::vector<char> text_vec;
bool load_text(const char *fname);
void free_text();
void read_utf8_chars(const char *fname, ptrdiff_t *n_valid, ptrdiff_t *n_invalid);
int count_words(const char *fname, const dbuf_str_view *delims);
int count_words_with_delims(const char *fname, const dbuf_str_view *delims);
void encode_decode_file(const char *fname);
void encode_decode();
};