1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

LibCore: Add some extensions that are text/plain

C++ source/header files, GML, IPC, CMake and various Serenity config
files.
This commit is contained in:
Maciej 2022-03-18 19:23:24 +01:00 committed by Andreas Kling
parent 933a717f3b
commit 273b69f947

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/MimeData.h>
@ -86,6 +87,20 @@ String guess_mime_type_based_on_filename(StringView path)
return "text/html";
if (path.ends_with(".csv", CaseSensitivity::CaseInsensitive))
return "text/csv";
// FIXME: Share this, TextEditor and HackStudio language detection somehow.
auto basename = LexicalPath::basename(path);
if (path.ends_with(".cpp", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".c", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".hpp", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".h", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".gml", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".ini", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".ipc", CaseSensitivity::CaseInsensitive)
|| path.ends_with(".txt", CaseSensitivity::CaseInsensitive)
|| basename == "CMakeLists.txt"
|| basename == ".history"
|| basename == ".shellrc")
return "text/plain";
return "application/octet-stream";
}