mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
HackStudio: Create Language enum from file extension or language name
This commit is contained in:
parent
1edaefca3a
commit
ba6cbf160b
4 changed files with 68 additions and 12 deletions
60
Userland/DevTools/HackStudio/Language.cpp
Normal file
60
Userland/DevTools/HackStudio/Language.cpp
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue