Initial commit
This commit is contained in:
66
application/source/mimeTypes.c
Normal file
66
application/source/mimeTypes.c
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
#include "array.h"
|
||||
|
||||
|
||||
|
||||
class mimeTypes{
|
||||
|
||||
array * extensions = new array();
|
||||
|
||||
array * mimeTypes = new array();
|
||||
|
||||
constructor() {
|
||||
|
||||
this->add("html", "text/html");
|
||||
|
||||
this->add("css", "text/css");
|
||||
|
||||
this->add("ttf", "application/x-font-ttf");
|
||||
|
||||
this->add("png", "image/png");
|
||||
|
||||
this->add("svg", "image/svg+xml");
|
||||
|
||||
}
|
||||
|
||||
void add( char * extension, char * mimeType ) {
|
||||
|
||||
struct array * extensions = this->extensions;
|
||||
|
||||
extensions->add( extension );
|
||||
|
||||
|
||||
struct array * mimeTypes = this->mimeTypes;
|
||||
|
||||
mimeTypes->add( mimeType );
|
||||
|
||||
}
|
||||
|
||||
char * getByExtension( char * extension ) {
|
||||
|
||||
struct array * extensions = this->extensions;
|
||||
|
||||
struct array * mimeTypes = this->mimeTypes;
|
||||
|
||||
int count = extensions->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
char * currentExtension = extensions->get( i );
|
||||
|
||||
if( currentExtension == extension ) {
|
||||
|
||||
char * mimeType = mimeTypes->get( i );
|
||||
|
||||
return mimeType;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return "no-mimetype";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user