1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

Meta: Move title/camel_casify() functions into their own file

These were duplicated among the CSS generators.
This commit is contained in:
Sam Atkins 2022-03-08 14:36:18 +00:00 committed by Andreas Kling
parent f5fe75f12c
commit e986331a4f
5 changed files with 51 additions and 85 deletions

View 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();
}