Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Last active December 23, 2015 10:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Janiczek/6619032 to your computer and use it in GitHub Desktop.
Save Janiczek/6619032 to your computer and use it in GitHub Desktop.
function CheckExtension from PHP 1.0.8
// 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);
}
// my take at readable C
int CheckExtension (char *filename, char *ext)
{
char *s;
return filename
&& strlen(filename)
&& (s = strrchr(filename,'.'))
&& strcmp(s,ext);
}
; high level goodness
(defn check-extension [filename extension]
(= extension
(second (re-matches (re-pattern (str ".*[.](" extension ")"))
filename))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment