summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/Language.cpp
blob: 229bfae64c2ed474a458f40b046d26bd5455acfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "Language.h"

namespace HackStudio {

Language language_from_file_extension(const String& extension)
{
    VERIFY(!extension.starts_with("."));
    if (extension == "c" || extension == "cc" || extension == "cxx" || extension == "cpp" || extension == "c++"
        || extension == "h" || extension == "hh" || extension == "hxx" || extension == "hpp" || extension == "h++")
        return Language::Cpp;
    if (extension == "js" || extension == "mjs" || extension == "json")
        return Language::JavaScript;
    if (extension == "html" || extension == "htm")
        return Language::HTML;
    if (extension == "css")
        return Language::CSS;
    if (extension == "gml")
        return Language::GML;
    if (extension == "ini")
        return Language::Ini;
    if (extension == "sh" || extension == "bash")
        return Language::Shell;
    if (extension == "sql")
        return Language::SQL;

    return Language::Unknown;
}

Language language_from_name(const String& name)
{
    if (name == "Cpp")
        return Language::Cpp;
    if (name == "Javascript")
        return Language::JavaScript;
    if (name == "Shell")
        return Language::Shell;

    return Language::Unknown;
}

String language_name_from_file_extension(const String& extension)
{
    VERIFY(!extension.starts_with("."));
    if (extension == "c" || extension == "cc" || extension == "cxx" || extension == "cpp" || extension == "c++"
        || extension == "h" || extension == "hh" || extension == "hxx" || extension == "hpp" || extension == "h++")
        return "C++";
    if (extension == "js" || extension == "mjs" || extension == "json")
        return "JavaScript";
    if (extension == "gml")
        return "GML";
    if (extension == "ini")
        return "Ini";
    if (extension == "sh" || extension == "bash")
        return "Shell";
    if (extension == "md")
        return "Markdown";
    if (extension == "html" || extension == "htm")
        return "HTML";
    if (extension == "css")
        return "CSS";
    if (extension == "sql")
        return "SQL";
    if (extension == "txt")
        return "Plaintext";

    return "Unknown";
}

}