Skip to content

Instantly share code, notes, and snippets.

@takashi1975
Last active October 24, 2015 05:02
Show Gist options
  • Select an option

  • Save takashi1975/fbec570dbf82865fa5c0 to your computer and use it in GitHub Desktop.

Select an option

Save takashi1975/fbec570dbf82865fa5c0 to your computer and use it in GitHub Desktop.
C++ 文字列変換
// 文字列変換
// 拡張子を変換 ... を想定
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;
}
@takashi1975

Copy link
Copy Markdown
Author

...あまり意味ないかもですが...
Cocos2d-x テクスチャファイルの解放で使えるかな...と思って... ^^;

std::string fileName = "xxx.plist";
std::string imageName = replaceExtension(fileName, ".plist", ".pvr.ccz");

SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(fileName);
Director::getInstance()->getTextureCache()->removeTextureForKey(imageName);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment