2022-03-21 21:54:48 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2023-05-07 20:23:12 -04:00
|
|
|
#include <cstdint>
|
2022-03-21 21:54:48 -04:00
|
|
|
|
|
|
|
class OutputFormatter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const uint32_t tabSize;
|
|
|
|
const uint32_t lineLimit;
|
|
|
|
|
|
|
|
uint32_t col;
|
|
|
|
uint32_t nest;
|
|
|
|
uint32_t nestIndent[8];
|
|
|
|
uint32_t currentIndent;
|
|
|
|
uint32_t wordNests;
|
|
|
|
|
|
|
|
char word[128];
|
|
|
|
char space[128];
|
|
|
|
char* wordP;
|
|
|
|
char* spaceP;
|
|
|
|
|
|
|
|
std::string str;
|
|
|
|
|
|
|
|
void Flush();
|
|
|
|
|
2022-05-11 13:18:24 -04:00
|
|
|
static thread_local OutputFormatter* Instance;
|
2022-03-21 21:54:48 -04:00
|
|
|
static int WriteStatic(const char* buf, int count);
|
|
|
|
|
|
|
|
public:
|
|
|
|
OutputFormatter(uint32_t tabSize = 4, uint32_t indentation = 4, uint32_t lineLimit = 120);
|
|
|
|
|
|
|
|
int (*StaticWriter())(const char* buf, int count); // Must be `int` due to libgfxd
|
|
|
|
|
|
|
|
int Write(const char* buf, int count);
|
|
|
|
int Write(const std::string& buf);
|
|
|
|
|
|
|
|
std::string GetOutput();
|
|
|
|
};
|