Last active
October 24, 2015 05:02
-
-
Save takashi1975/fbec570dbf82865fa5c0 to your computer and use it in GitHub Desktop.
C++ 文字列変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 文字列変換 | |
| // 拡張子を変換 ... を想定 | |
| std::string replaceExtension(std::string fileName, | |
| const std::string fromExt, | |
| const std::string toExt) | |
| { | |
| //Ex. | |
| //std::string fileName = "samplefile.plist"; //-> "samplefile.pvr.ccz"; | |
| //const std::string fromExt = ".plist"; | |
| //const std::string toExt = ".pvr.ccz"; | |
| //最後尾を検索 | |
| const std::string ::size_type pos = fileName.find_last_of(fromExt); | |
| if (pos != std::string::npos) | |
| { | |
| //変換開始位置 | |
| const auto index = (pos + 1) - fromExt.size(); | |
| //文字列変換 | |
| fileName.replace(index, fromExt.size(), toExt); | |
| } | |
| return fileName; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...あまり意味ないかもですが...
Cocos2d-x テクスチャファイルの解放で使えるかな...と思って... ^^;
std::string fileName = "xxx.plist";
std::string imageName = replaceExtension(fileName, ".plist", ".pvr.ccz");
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(fileName);
Director::getInstance()->getTextureCache()->removeTextureForKey(imageName);