-
-
Save wagjo/6619991 to your computer and use it in GitHub Desktop.
This file contains 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 characters
// original | |
int CheckExtension (char *filename, char *ext) | |
{ | |
char *s; | |
if (!filename) return(0); | |
if (strlen(filename) == 0) return(0); | |
s = strrchr(filename,'.'); | |
if (!s) return(0); | |
if (!strcmp(s,ext)) return(1); | |
return(0); | |
} |
This file contains 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 characters
// my take at readable C | |
int CheckExtension (char *filename, char *ext) | |
{ | |
char *s; | |
return filename | |
&& strlen(filename) | |
&& (s = strrchr(filename,'.')) | |
&& strcmp(s,ext); | |
} |
This file contains 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 characters
; high level goodness | |
(defn check-extension [filename extension] | |
(= extension | |
(second (re-matches (re-pattern (str ".*[.](" extension ")")) | |
filename)))) |
This file contains 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 characters
(defn check-extension | |
[filename extension] | |
(-> (str ".*[.](" extension ")") | |
re-pattern | |
(re-matches filename) | |
second | |
(= extension))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment