summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/Language.cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-03-05 17:18:22 +0200
committerAndreas Kling <kling@serenityos.org>2021-03-06 09:40:33 +0100
commitba6cbf160b0ac1a84a1906e4278d57304d7b01e8 (patch)
tree91178290c0de9aa00c61c262ddae2ca994e38761 /Userland/DevTools/HackStudio/Language.cpp
parent1edaefca3ae1bb0aabc2218cbba1c875a2ef44ed (diff)
downloadserenity-ba6cbf160b0ac1a84a1906e4278d57304d7b01e8.zip
HackStudio: Create Language enum from file extension or language name
Diffstat (limited to 'Userland/DevTools/HackStudio/Language.cpp')
-rw-r--r--Userland/DevTools/HackStudio/Language.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/Language.cpp b/Userland/DevTools/HackStudio/Language.cpp
new file mode 100644
index 0000000000..813754ceb7
--- /dev/null
+++ b/Userland/DevTools/HackStudio/Language.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020, the SerenityOS developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "Language.h"
+
+namespace HackStudio {
+
+Language language_from_file_extension(const String& extension)
+{
+ VERIFY(!extension.starts_with("."));
+ if (extension == "cpp" || extension == "h")
+ return Language::Cpp;
+ else if (extension == "js")
+ return Language::JavaScript;
+ else if (extension == "gml")
+ return Language::GML;
+ else if (extension == "ini")
+ return Language::Ini;
+ else if (extension == "sh")
+ return Language::Shell;
+
+ 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;
+}
+
+}