mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
Meta: Move title/camel_casify() functions into their own file
These were duplicated among the CSS generators.
This commit is contained in:
parent
f5fe75f12c
commit
e986331a4f
5 changed files with 51 additions and 85 deletions
|
@ -5,48 +5,12 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "GeneratorUtil.h"
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/SourceGenerator.h>
|
#include <AK/SourceGenerator.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/File.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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,27 +4,12 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "GeneratorUtil.h"
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/SourceGenerator.h>
|
#include <AK/SourceGenerator.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/File.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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,27 +4,12 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "GeneratorUtil.h"
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/SourceGenerator.h>
|
#include <AK/SourceGenerator.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/File.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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,27 +4,12 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "GeneratorUtil.h"
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/SourceGenerator.h>
|
#include <AK/SourceGenerator.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/File.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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
47
Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h
Normal file
47
Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h
Normal file
|
@ -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();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue