Created
January 12, 2025 20:36
-
-
Save EncodeTheCode/8a1ad4eec0c6dd5bec8e83a2cf45ecfc to your computer and use it in GitHub Desktop.
Revisions
-
EncodeTheCode created this gist
Jan 12, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #include <iostream> #include <string> #include <algorithm> bool hasPngExtension(const std::string& filename) { size_t dotPos = filename.rfind('.'); if (dotPos == std::string::npos) return false; std::string extension = filename.substr(dotPos + 1); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); return extension == "png"; } int main() { std::cout << std::boolalpha << "File: image.png, Has .png: " << hasPngExtension("image.png") << '\n' << "File: image.PNG, Has .png: " << hasPngExtension("image.PNG") << '\n' << "File: document.pdf, Has .png: " << hasPngExtension("document.pdf") << '\n' << "File: no_extension, Has .png: " << hasPngExtension("no_extension") << '\n'; return 0; }