
Since AK can't refer to LibUnicode directly, the strategy here is that if you need case transformations, you can link LibUnicode and receive them. If you try to use either of these methods without linking it, then you'll of course get a linker error (note we don't do any fallbacks to e.g. ASCII case transformations). If you don't need these methods, you don't have to link LibUnicode.
29 lines
752 B
C++
29 lines
752 B
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/StringBuilder.h>
|
|
#include <LibUnicode/UnicodeUtils.h>
|
|
|
|
// This file contains definitions of AK::String methods which require UCD data.
|
|
|
|
namespace AK {
|
|
|
|
ErrorOr<String> String::to_lowercase(Optional<StringView> const& locale) const
|
|
{
|
|
StringBuilder builder;
|
|
TRY(Unicode::Detail::build_lowercase_string(code_points(), builder, locale));
|
|
return builder.to_string();
|
|
}
|
|
|
|
ErrorOr<String> String::to_uppercase(Optional<StringView> const& locale) const
|
|
{
|
|
StringBuilder builder;
|
|
TRY(Unicode::Detail::build_uppercase_string(code_points(), builder, locale));
|
|
return builder.to_string();
|
|
}
|
|
|
|
}
|