mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
ObjWriting: Dump FontIcon assets as csv files
According to the asset names this seems to be their original format. however since i didn't find any examples of that asset in raw form i just tried to come up with a realistic csv style for it
This commit is contained in:
76
src/ObjWriting/Dumping/CsvWriter.cpp
Normal file
76
src/ObjWriting/Dumping/CsvWriter.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "CsvWriter.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
const std::string CsvWriter::LINE_BREAK = "\n";
|
||||
|
||||
CsvWriter::CsvWriter(FileAPI::IFile* file)
|
||||
{
|
||||
m_file = file;
|
||||
m_first_row = true;
|
||||
m_current_column = 0;
|
||||
m_column_count = 0;
|
||||
}
|
||||
|
||||
void CsvWriter::WriteColumn(const std::string& value)
|
||||
{
|
||||
if (m_current_column++ > 0)
|
||||
m_file->Printf(",");
|
||||
|
||||
bool containsSeparator = false;
|
||||
bool containsQuote = false;
|
||||
for (const auto& c : value)
|
||||
{
|
||||
if (c == '"')
|
||||
{
|
||||
containsQuote = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == SEPARATOR)
|
||||
containsSeparator = true;
|
||||
}
|
||||
|
||||
if (containsQuote)
|
||||
{
|
||||
std::ostringstream str;
|
||||
|
||||
for(const auto& c : value)
|
||||
{
|
||||
if (c == '"')
|
||||
str << "\"\"";
|
||||
else
|
||||
str << c;
|
||||
}
|
||||
|
||||
m_file->Printf("\"%s\"", str.str().c_str());
|
||||
}
|
||||
else if (containsSeparator)
|
||||
{
|
||||
m_file->Printf("\"%s\"", value.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_file->Printf("%s", value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void CsvWriter::NextRow()
|
||||
{
|
||||
if (m_first_row)
|
||||
{
|
||||
m_first_row = false;
|
||||
m_column_count = m_current_column;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(m_current_column < m_column_count)
|
||||
{
|
||||
m_file->Printf(",");
|
||||
m_current_column++;
|
||||
}
|
||||
}
|
||||
|
||||
m_file->Printf("\n");
|
||||
m_current_column = 0;
|
||||
}
|
19
src/ObjWriting/Dumping/CsvWriter.h
Normal file
19
src/ObjWriting/Dumping/CsvWriter.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "Utils/FileAPI.h"
|
||||
|
||||
class CsvWriter
|
||||
{
|
||||
static constexpr char SEPARATOR = ',';
|
||||
static const std::string LINE_BREAK;
|
||||
|
||||
FileAPI::IFile* m_file;
|
||||
unsigned m_column_count;
|
||||
unsigned m_current_column;
|
||||
bool m_first_row;
|
||||
|
||||
public:
|
||||
explicit CsvWriter(FileAPI::IFile* file);
|
||||
|
||||
void WriteColumn(const std::string& value);
|
||||
void NextRow();
|
||||
};
|
Reference in New Issue
Block a user