summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSyntax
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2022-12-06 19:32:17 +0100
committerTim Flynn <trflynn89@pm.me>2022-12-19 14:13:50 -0500
commitc75bfa9cda240792657579ba1d0b7ce5c2ddd88c (patch)
tree55231b27fd0f6ce0dc702ad9de4cf2d9c9cfd045 /Userland/Libraries/LibSyntax
parentfb61b3d41d39e4f42d6826e5df4289b0f25f585b (diff)
downloadserenity-c75bfa9cda240792657579ba1d0b7ce5c2ddd88c.zip
LibSyntax: Add `common_language_extension()` function
The main motivation for this is to prefill an extension for user when saving a new file.
Diffstat (limited to 'Userland/Libraries/LibSyntax')
-rw-r--r--Userland/Libraries/LibSyntax/Highlighter.cpp27
-rw-r--r--Userland/Libraries/LibSyntax/Highlighter.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/Userland/Libraries/LibSyntax/Highlighter.cpp b/Userland/Libraries/LibSyntax/Highlighter.cpp
index ba3daa3fd2..e4b8189f10 100644
--- a/Userland/Libraries/LibSyntax/Highlighter.cpp
+++ b/Userland/Libraries/LibSyntax/Highlighter.cpp
@@ -165,4 +165,31 @@ StringView language_to_string(Language language)
VERIFY_NOT_REACHED();
}
+StringView common_language_extension(Language language)
+{
+ switch (language) {
+ case Language::Cpp:
+ return "cpp"sv;
+ case Language::CSS:
+ return "css"sv;
+ case Language::GitCommit:
+ return {};
+ case Language::GML:
+ return "gml"sv;
+ case Language::HTML:
+ return "html"sv;
+ case Language::INI:
+ return "ini"sv;
+ case Language::JavaScript:
+ return "js"sv;
+ case Language::PlainText:
+ return "txt"sv;
+ case Language::Shell:
+ return "sh"sv;
+ case Language::SQL:
+ return "sql"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
}
diff --git a/Userland/Libraries/LibSyntax/Highlighter.h b/Userland/Libraries/LibSyntax/Highlighter.h
index 21952ec6a6..9903f08379 100644
--- a/Userland/Libraries/LibSyntax/Highlighter.h
+++ b/Userland/Libraries/LibSyntax/Highlighter.h
@@ -33,6 +33,7 @@ struct TextStyle {
};
StringView language_to_string(Language);
+StringView common_language_extension(Language);
class Highlighter {
AK_MAKE_NONCOPYABLE(Highlighter);