2 * @brief Find MIME type for a file
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2001,2005 James Aylett
6 * Copyright 2001,2002 Ananova Ltd
7 * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015 Olly Betts
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
33 #include "stringutils.h"
37 // The longest string after a '.' to treat as an extension. If there's a
38 // longer entry in the mime_map, we set this to that length instead.
39 size_t max_ext_len
= max(size_t(7), MAX_BUILTIN_MIMEMAP_EXTENSION_LEN
);
42 built_in_mime_map(const string
& ext
)
44 int k
= keyword2(tab
, ext
.data(), ext
.size());
45 return k
>= 0 ? default_mime_map
[k
] : NULL
;
49 mimetype_from_ext(const map
<string
, string
> & mime_map
, string ext
)
51 map
<string
, string
>::const_iterator mt
= mime_map
.find(ext
);
52 if (mt
!= mime_map
.end())
55 const char * r
= built_in_mime_map(ext
);
58 // The extension wasn't found, see if the lower-cased version (if
59 // different) is found.
62 for (i
= ext
.begin(); i
!= ext
.end(); ++i
) {
63 if (*i
>= 'A' && *i
<= 'Z') {
70 mt
= mime_map
.find(ext
);
71 if (mt
!= mime_map
.end())
74 r
= built_in_mime_map(ext
);