diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-03-08 14:36:18 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-09 23:06:30 +0100 |
commit | e986331a4ffae5c1398dbb20d5ccffc2f90e58e0 (patch) | |
tree | 4681fcf2dc1c3c62913a11af360ddd1fdedbf049 /Meta/Lagom | |
parent | f5fe75f12c3162f51403f19d8f38b288f3603006 (diff) | |
download | serenity-e986331a4ffae5c1398dbb20d5ccffc2f90e58e0.zip |
Meta: Move title/camel_casify() functions into their own file
These were duplicated among the CSS generators.
Diffstat (limited to 'Meta/Lagom')
5 files changed, 51 insertions, 85 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp index 6e106a0802..25e7eb68d8 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp @@ -5,48 +5,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include "GeneratorUtil.h" #include <AK/ByteBuffer.h> #include <AK/JsonObject.h> #include <AK/SourceGenerator.h> #include <AK/StringBuilder.h> #include <LibCore/File.h> -#include <ctype.h> - -static String title_casify(const String& dashy_name) -{ - auto parts = dashy_name.split('-'); - StringBuilder builder; - for (auto& part : parts) { - if (part.is_empty()) - continue; - builder.append(toupper(part[0])); - if (part.length() == 1) - continue; - builder.append(part.substring_view(1, part.length() - 1)); - } - return builder.to_string(); -} - -static String camel_casify(StringView dashy_name) -{ - auto parts = dashy_name.split_view('-'); - StringBuilder builder; - bool first = true; - for (auto& part : parts) { - if (part.is_empty()) - continue; - char ch = part[0]; - if (!first) - ch = toupper(ch); - else - first = false; - builder.append(ch); - if (part.length() == 1) - continue; - builder.append(part.substring_view(1, part.length() - 1)); - } - return builder.to_string(); -} int main(int argc, char** argv) { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp index 137333d6dc..2e6413f679 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp @@ -4,27 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include "GeneratorUtil.h" #include <AK/ByteBuffer.h> #include <AK/JsonObject.h> #include <AK/SourceGenerator.h> #include <AK/StringBuilder.h> #include <LibCore/File.h> -#include <ctype.h> - -static String title_casify(const String& dashy_name) -{ - auto parts = dashy_name.split('-'); - StringBuilder builder; - for (auto& part : parts) { - if (part.is_empty()) - continue; - builder.append(toupper(part[0])); - if (part.length() == 1) - continue; - builder.append(part.substring_view(1, part.length() - 1)); - } - return builder.to_string(); -} int main(int argc, char** argv) { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_cpp.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_cpp.cpp index 553782b49e..66bc53fb06 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_cpp.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_cpp.cpp @@ -4,27 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include "GeneratorUtil.h" #include <AK/ByteBuffer.h> #include <AK/JsonObject.h> #include <AK/SourceGenerator.h> #include <AK/StringBuilder.h> #include <LibCore/File.h> -#include <ctype.h> - -static String title_casify(const String& dashy_name) -{ - auto parts = dashy_name.split('-'); - StringBuilder builder; - for (auto& part : parts) { - if (part.is_empty()) - continue; - builder.append(toupper(part[0])); - if (part.length() == 1) - continue; - builder.append(part.substring_view(1, part.length() - 1)); - } - return builder.to_string(); -} int main(int argc, char** argv) { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_h.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_h.cpp index 6c32b1e53e..39a3fa6d10 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_h.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_ValueID_h.cpp @@ -4,27 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include "GeneratorUtil.h" #include <AK/ByteBuffer.h> #include <AK/JsonObject.h> #include <AK/SourceGenerator.h> #include <AK/StringBuilder.h> #include <LibCore/File.h> -#include <ctype.h> - -static String title_casify(const String& dashy_name) -{ - auto parts = dashy_name.split('-'); - StringBuilder builder; - for (auto& part : parts) { - if (part.is_empty()) - continue; - builder.append(toupper(part[0])); - if (part.length() == 1) - continue; - builder.append(part.substring_view(1, part.length() - 1)); - } - return builder.to_string(); -} int main(int argc, char** argv) { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h new file mode 100644 index 0000000000..b1f20c5d68 --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019-2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/String.h> +#include <AK/Vector.h> +#include <ctype.h> + +String title_casify(String const& dashy_name) +{ + auto parts = dashy_name.split('-'); + StringBuilder builder; + for (auto& part : parts) { + if (part.is_empty()) + continue; + builder.append(toupper(part[0])); + if (part.length() == 1) + continue; + builder.append(part.substring_view(1, part.length() - 1)); + } + return builder.to_string(); +} + +String camel_casify(StringView dashy_name) +{ + auto parts = dashy_name.split_view('-'); + StringBuilder builder; + bool first = true; + for (auto& part : parts) { + if (part.is_empty()) + continue; + char ch = part[0]; + if (!first) + ch = toupper(ch); + else + first = false; + builder.append(ch); + if (part.length() == 1) + continue; + builder.append(part.substring_view(1, part.length() - 1)); + } + return builder.to_string(); +} |