rlottie/exampe: add correct implementation of basename()

This commit is contained in:
sub.mohanty@samsung.com
2019-07-02 22:09:50 +09:00
committed by Subhransu
parent 8b5851ca52
commit 1c3098297e

View File

@@ -84,7 +84,7 @@ public:
auto buffer = std::unique_ptr<uint32_t[]>(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 : "<<baseName.data()<<std::endl;
std::cout<<"Generated GIF file : "<<gifName<<std::endl;
return 0;
}
@@ -147,7 +148,7 @@ private:
char *fileName{nullptr};
int bgColor = 0xffffffff;
std::array<char, 5000> absoloutePath;
std::array<char, 5000> baseName;
std::string gifName;
};
int