2021-03-14 15:40:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-25 01:36:10 +00:00
|
|
|
#include <cstdint>
|
2021-03-14 15:40:25 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2021-03-20 16:02:12 +00:00
|
|
|
#include <vector>
|
2021-03-14 15:40:25 +00:00
|
|
|
|
|
|
|
class OutputFormatter
|
|
|
|
{
|
|
|
|
private:
|
2021-04-30 21:23:22 +00:00
|
|
|
const uint32_t tabSize;
|
|
|
|
const uint32_t lineLimit;
|
2021-03-14 15:40:25 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
uint32_t col;
|
|
|
|
uint32_t nest;
|
|
|
|
uint32_t nestIndent[8];
|
|
|
|
uint32_t currentIndent;
|
|
|
|
uint32_t wordNests;
|
2021-03-14 15:40:25 +00:00
|
|
|
|
|
|
|
char word[128];
|
|
|
|
char space[128];
|
2021-04-30 21:23:22 +00:00
|
|
|
char* wordP;
|
|
|
|
char* spaceP;
|
2021-03-14 15:40:25 +00:00
|
|
|
|
|
|
|
std::string str;
|
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
void Flush();
|
2021-03-14 15:40:25 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
static OutputFormatter* Instance;
|
|
|
|
static int WriteStatic(const char* buf, int count);
|
2021-03-14 15:40:25 +00:00
|
|
|
|
|
|
|
public:
|
2021-10-17 11:32:09 +00:00
|
|
|
OutputFormatter(uint32_t tabSize = 4, uint32_t indentation = 4, uint32_t lineLimit = 120);
|
2021-03-14 15:40:25 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
int (*StaticWriter())(const char* buf, int count); // Must be `int` due to libgfxd
|
2021-03-14 15:40:25 +00:00
|
|
|
|
2021-04-30 21:23:22 +00:00
|
|
|
int Write(const char* buf, int count);
|
|
|
|
int Write(const std::string& buf);
|
|
|
|
|
|
|
|
std::string GetOutput();
|
2021-10-17 11:32:09 +00:00
|
|
|
};
|