mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-11-01 05:41:01 +00:00
48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
|
|
/*
|
||
|
|
* 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();
|
||
|
|
}
|