From fbb56bbdfedacef127668e2a09604979741aeb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 2 Nov 2018 17:38:58 -0700 Subject: [PATCH] Cleanup. --- tools/bin2c/bin2c.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tools/bin2c/bin2c.cpp b/tools/bin2c/bin2c.cpp index 8244d53..6769539 100644 --- a/tools/bin2c/bin2c.cpp +++ b/tools/bin2c/bin2c.cpp @@ -27,14 +27,13 @@ struct TinyStlAllocator }; #define TINYSTL_ALLOCATOR TinyStlAllocator -#include #include namespace stl = tinystl; class Bin2cWriter : public bx::WriterI { public: - Bin2cWriter(bx::WriterI* _writer, const char* _name) + Bin2cWriter(bx::WriterI* _writer, const bx::StringView& _name) : m_writer(_writer) , m_name(_name) { @@ -59,7 +58,13 @@ public: const char* data = &m_buffer[0]; uint32_t size = (uint32_t)m_buffer.size(); - bx::writePrintf(m_writer, "static const uint8_t %s[%d] =\n{\n", m_name.c_str(), size); + bx::writePrintf( + m_writer + , "static const uint8_t %.*s[%d] =\n{\n" + , m_name.getLength() + , m_name.getPtr() + , size + ); if (NULL != data) { @@ -101,7 +106,7 @@ public: } bx::WriterI* m_writer; - stl::string m_name; + bx::StringView m_name; typedef stl::vector Buffer; Buffer m_buffer; }; @@ -123,19 +128,16 @@ void help(const char* _error = NULL) bx::writePrintf(stdOut , "Usage: bin2c -f -o -n \n" - "\n" "Options:\n" " -f Input file path.\n" " -o Output file path.\n" " -n Array name.\n" - "\n" "For additional information, see https://github.com/bkaradzic/bx\n" ); } - int main(int _argc, const char* _argv[]) { bx::CommandLine cmdLine(_argc, _argv); @@ -146,24 +148,24 @@ int main(int _argc, const char* _argv[]) return bx::kExitFailure; } - const char* filePath = cmdLine.findOption('f'); - if (NULL == filePath) + bx::FilePath filePath = cmdLine.findOption('f'); + if (filePath.isEmpty() ) { help("Input file name must be specified."); return bx::kExitFailure; } - const char* outFilePath = cmdLine.findOption('o'); - if (NULL == outFilePath) + bx::FilePath outFilePath = cmdLine.findOption('o'); + if (outFilePath.isEmpty() ) { help("Output file name must be specified."); return bx::kExitFailure; } - const char* name = cmdLine.findOption('n'); - if (NULL == name) + bx::StringView name = cmdLine.findOption('n'); + if (name.isEmpty() ) { - name = "data"; + name.set("data"); } void* data = NULL;