#include "daScript/misc/platform.h"
#include "daScript/misc/string_writer.h"
#include "misc/include_fmt.h"
namespace das {
DAS_API StringWriterTag HEX;
DAS_API StringWriterTag DEC;
DAS_API StringWriterTag FIXEDFP;
DAS_API StringWriterTag SCIENTIFIC;
mutex TextPrinter::pmut;
// string writer
template
StringWriter & StringWriter::format(const char * format, TT value) {
char buf[128];
auto tail = fmt::format_to(buf, fmt::runtime(format), value);
auto realL = tail - buf;
if ( auto at = this->allocate(int(realL)) ) {
memcpy(at, buf, realL);
this->output();
}
return *this;
}
StringWriter & StringWriter::writeStr(const char * st, size_t len) {
this->append(st, int(len));
this->output();
return *this;
}
StringWriter & StringWriter::writeChars(char ch, size_t len) {
if ( auto at = this->allocate(int(len)) ) {
memset(at, ch, len);
this->output();
}
return *this;
}
StringWriter & StringWriter::write(const char * stst) {
if ( stst ) {
return writeStr(stst, strlen(stst));
} else {
return *this;
}
}
StringWriter & StringWriter::operator