From 4f68f5240d4b4d68ed003fa6a79da974c8bd5270 Mon Sep 17 00:00:00 2001 From: "sub.mohanty@samsung.com" Date: Sun, 7 Jul 2019 15:27:52 +0900 Subject: [PATCH] example: use std::string api --- example/lottie2gif.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/example/lottie2gif.cpp b/example/lottie2gif.cpp index 5dc74bb..939f63a 100644 --- a/example/lottie2gif.cpp +++ b/example/lottie2gif.cpp @@ -95,18 +95,25 @@ public: int setup(int argc, char **argv) { - if (argc > 1) fileName = argv[1]; + char *path{nullptr}; + + if (argc > 1) path = argv[1]; if (argc > 2) bgColor = strtol(argv[2], NULL, 16); - if (!fileName) return help(); + if (!path) return help(); + + std::array memory; #ifdef _WIN32 - fileName = _fullpath(absoloutePath.data(), fileName, absoloutePath.size()); + path = _fullpath(memory.data(), path, memory.size()); #else - fileName = realpath(fileName, absoloutePath.data()); + path = realpath(path, memory.data()); #endif + if (!path) return help(); + + fileName = std::string(path); - if (!fileName || !jsonFile(fileName) ) return help(); + if (!jsonFile()) return help(); gifName = basename(fileName); gifName.append(".gif"); @@ -116,22 +123,16 @@ public: private: std::string basename(const std::string &str) { - if (str.empty()) return {}; - - auto ptr = str.c_str(); - auto pos = str.size(); - while (--pos) { - if ( ptr[pos] == '/' || ptr[pos] == '\\') { - return str.substr(pos+1); - } - } - return str; + return str.substr(str.find_last_of("/\\") + 1); } - bool jsonFile(const char *filename) { - const char *dot = strrchr(filename, '.'); - if(!dot || dot == filename) return false; - return !strcmp(dot + 1, "json"); + bool jsonFile() { + std::string extn = ".json"; + if ( fileName.size() <= extn.size() || + fileName.substr(fileName.size()- extn.size()) != extn ) + return false; + + return true; } int result() { @@ -145,9 +146,8 @@ private: } private: - char *fileName{nullptr}; int bgColor = 0xffffffff; - std::array absoloutePath; + std::string fileName; std::string gifName; }; -- 2.7.4