Check if file has a certain file extension (case insensitive) filename extension, like ".laz" or "laz" TRUE if filename has the given extension
| 453 | /// <param name="ext">extension, like ".laz" or "laz"</param> |
| 454 | /// <returns>TRUE if filename has the given extension</returns> |
| 455 | bool HasFileExt(std::string fn, std::string ext) { |
| 456 | if (fn.empty()) return false; |
| 457 | if (ext.empty()) return false; |
| 458 | // if fn does not have a ext: it is maybe just an ext - compare those |
| 459 | if ((fn.length() == ext.length()) || (fn.find_last_of(".") == std::string::npos)) { |
| 460 | return fn.compare(ext) == 0; |
| 461 | } |
| 462 | if (ext[0] != '.') ext = '.' + ext; |
| 463 | to_lower(ext); |
| 464 | to_lower(fn); |
| 465 | return (fn.substr(fn.find_last_of(".")) == ext); |
| 466 | } |
| 467 | |
| 468 | // replace file extension of input_file with new extension (with or without leading '.') |
| 469 | std::string FileExtSet(std::string fn_in, std::string ext_new) { |
no test coverage detected