fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. std::string Rename(const std::string& name){
  6. std::string newName(name);
  7. static const std::string oldSuffix = "nef";
  8. static const std::string newSuffix = "bmp";
  9. auto dotPos = newName.rfind('.');
  10. if (dotPos == newName.size() - oldSuffix.size() - 1){
  11. auto suffix = newName.substr(dotPos + 1);
  12. std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
  13. if (suffix == oldSuffix)
  14. newName.replace(dotPos + 1, std::string::npos, newSuffix);
  15. }
  16. return newName;
  17. }
  18.  
  19. int main() {
  20. std::cout << Rename("abc.net.nef") << std::endl;
  21. std::cout << Rename("abc.nEF") << std::endl;
  22. std::cout << Rename("def.not-nef") << std::endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
abc.net.bmp
abc.bmp
def.not-nef