From: sub.mohanty@samsung.com Date: Tue, 2 Jul 2019 13:09:50 +0000 (+0900) Subject: rlottie/exampe: add correct implementation of basename() X-Git-Tag: submit/tizen/20190718.020831~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=083ad2bb418e552cdf28a96e59c9d17abe52a3e5;p=platform%2Fcore%2Fuifw%2Flottie-player.git rlottie/exampe: add correct implementation of basename() --- diff --git a/example/lottie2gif.cpp b/example/lottie2gif.cpp index af2c901..5dc74bb 100644 --- a/example/lottie2gif.cpp +++ b/example/lottie2gif.cpp @@ -84,7 +84,7 @@ public: auto buffer = std::unique_ptr(new uint32_t[w * h]); size_t frameCount = player->totalFrame(); - GifBuilder builder(baseName.data(), w, h, bgColor); + GifBuilder builder(gifName.data(), w, h, bgColor); for (size_t i = 0; i < frameCount ; i++) { rlottie::Surface surface(buffer.get(), w, h, w * 4); player->renderSync(i, surface); @@ -108,24 +108,25 @@ public: if (!fileName || !jsonFile(fileName) ) return help(); - baseName = absoloutePath; -#ifdef _WIN32 - char *base = strrchr(baseName.data(), '\\'); - if (base) - { - base++; - base = strrchr(baseName.data(), '\\'); - if (base) base++; - else return 1; - } -#else - char *base = basename(baseName.data()); -#endif - snprintf(baseName.data(), baseName.size(), "%s.gif",base); + gifName = basename(fileName); + gifName.append(".gif"); return 0; } 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; + } bool jsonFile(const char *filename) { const char *dot = strrchr(filename, '.'); @@ -134,7 +135,7 @@ private: } int result() { - std::cout<<"Generated GIF file : "< absoloutePath; - std::array baseName; + std::string gifName; }; int