std::string filename_formatter( const std::string& format, FilenameInfo& info, bool replaceFrame) { const std::string& filename = info.filename(); std::string path = base::get_file_path(filename); if (path.empty()) path = "."; std::string output = format; base::replace_string(output, "{fullname}", filename); base::replace_string(output, "{path}", path); base::replace_string(output, "{name}", base::get_file_name(filename)); base::replace_string(output, "{title}", base::get_file_title(filename)); base::replace_string(output, "{extension}", base::get_file_extension(filename)); base::replace_string(output, "{layer}", info.layerName()); if (replaceFrame) { base::replace_string(output, "{tag}", info.innerTagName()); base::replace_string(output, "{innertag}", info.innerTagName()); base::replace_string(output, "{outertag}", info.outerTagName()); replace_frame("{frame", info.frame(), output); replace_frame("{tagframe", info.tagFrame(), output); } return output; }
std::string filename_formatter( const std::string& format, FilenameInfo& info, bool replaceFrame) { const std::string& filename = info.filename(); std::string path = base::get_file_path(filename); if (path.empty()) path = "."; std::string output = format; base::replace_string(output, "{fullname}", filename); base::replace_string(output, "{path}", path); base::replace_string(output, "{name}", base::get_file_name(filename)); base::replace_string(output, "{title}", base::get_file_title(filename)); base::replace_string(output, "{extension}", base::get_file_extension(filename)); base::replace_string(output, "{layer}", info.layerName()); base::replace_string(output, "{tag}", info.innerTagName()); base::replace_string(output, "{innertag}", info.innerTagName()); base::replace_string(output, "{outertag}", info.outerTagName()); if (replaceFrame) { size_t i = output.find("{frame"); if (i != std::string::npos) { size_t j = output.find("}", i+6); if (j != std::string::npos) { std::string from = output.substr(i, j - i + 1); if (info.frame() >= 0) { std::vector<char> to(32); int offset = std::strtol(from.c_str()+6, NULL, 10); std::sprintf(&to[0], "%0*d", (int(j)-int(i+6)), info.frame() + offset); base::replace_string(output, from, &to[0]); } else base::replace_string(output, from, ""); } } } return output; }