1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10:47:34 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -169,7 +169,7 @@ Optional<Weekday> get_locale_weekend_end(StringView locale)
return find_regional_values_for_locale(locale, get_regional_weekend_end);
}
String combine_skeletons(StringView first, StringView second)
DeprecatedString combine_skeletons(StringView first, StringView second)
{
// https://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems
constexpr auto field_order = Array {
@ -241,7 +241,7 @@ Optional<StringView> __attribute__((weak)) get_calendar_day_period_symbol_for_ho
Optional<StringView> __attribute__((weak)) get_time_zone_name(StringView, StringView, CalendarPatternStyle, TimeZone::InDST) { return {}; }
Optional<TimeZoneFormat> __attribute__((weak)) get_time_zone_format(StringView) { return {}; }
static Optional<String> format_time_zone_offset(StringView locale, CalendarPatternStyle style, i64 offset_seconds)
static Optional<DeprecatedString> format_time_zone_offset(StringView locale, CalendarPatternStyle style, i64 offset_seconds)
{
auto formats = get_time_zone_format(locale);
if (!formats.has_value())
@ -295,7 +295,7 @@ static Optional<String> format_time_zone_offset(StringView locale, CalendarPatte
}
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Zone_Format_Terminology
String format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time)
DeprecatedString format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time)
{
auto offset = TimeZone::get_time_zone_offset(time_zone, time);
if (!offset.has_value())

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Time.h>
#include <AK/Types.h>
@ -111,9 +111,9 @@ struct CalendarPattern {
callback(time_zone_name, other.time_zone_name, Field::TimeZoneName);
}
String skeleton {};
String pattern {};
Optional<String> pattern12 {};
DeprecatedString skeleton {};
DeprecatedString pattern {};
Optional<DeprecatedString> pattern12 {};
Optional<HourCycle> hour_cycle {};
// https://unicode.org/reports/tr35/tr35-dates.html#Calendar_Fields
@ -145,9 +145,9 @@ struct CalendarRangePattern : public CalendarPattern {
};
Optional<Field> field {};
String start_range {};
DeprecatedString start_range {};
StringView separator {};
String end_range {};
DeprecatedString end_range {};
};
enum class CalendarFormatType : u8 {
@ -208,7 +208,7 @@ Optional<WeekendEndRegion> weekend_end_region_from_string(StringView weekend_end
Optional<Weekday> get_regional_weekend_end(StringView region);
Optional<Weekday> get_locale_weekend_end(StringView region);
String combine_skeletons(StringView first, StringView second);
DeprecatedString combine_skeletons(StringView first, StringView second);
Optional<CalendarFormat> get_calendar_date_format(StringView locale, StringView calendar);
Optional<CalendarFormat> get_calendar_time_format(StringView locale, StringView calendar);
@ -225,7 +225,7 @@ Optional<StringView> get_calendar_weekday_symbol(StringView locale, StringView c
Optional<StringView> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
Optional<StringView> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
String format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time);
DeprecatedString format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time);
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style, TimeZone::InDST in_dst);
Optional<TimeZoneFormat> get_time_zone_format(StringView locale);

View file

@ -393,7 +393,7 @@ static Optional<Extension> parse_extension(GenericLexer& lexer)
return {};
}
static Vector<String> parse_private_use_extensions(GenericLexer& lexer)
static Vector<DeprecatedString> parse_private_use_extensions(GenericLexer& lexer)
{
// https://unicode.org/reports/tr35/#pu_extensions
//
@ -404,8 +404,8 @@ static Vector<String> parse_private_use_extensions(GenericLexer& lexer)
if (!header.has_value())
return {};
auto parse_values = [&]() -> Vector<String> {
Vector<String> extensions;
auto parse_values = [&]() -> Vector<DeprecatedString> {
Vector<DeprecatedString> extensions;
while (true) {
auto segment = consume_next_segment(lexer);
@ -473,7 +473,7 @@ Optional<LocaleID> parse_unicode_locale_id(StringView locale)
return locale_id;
}
static void perform_hard_coded_key_value_substitutions(StringView key, String& value)
static void perform_hard_coded_key_value_substitutions(StringView key, DeprecatedString& value)
{
// FIXME: In the XML export of CLDR, there are some aliases defined in the following files:
// https://github.com/unicode-org/cldr-staging/blob/master/production/common/bcp47/calendar.xml
@ -538,7 +538,7 @@ static void perform_hard_coded_key_value_substitutions(StringView key, String& v
}
}
void canonicalize_unicode_extension_values(StringView key, String& value, bool remove_true)
void canonicalize_unicode_extension_values(StringView key, DeprecatedString& value, bool remove_true)
{
value = value.to_lowercase();
perform_hard_coded_key_value_substitutions(key, value);
@ -665,12 +665,12 @@ static void transform_unicode_locale_id_to_canonical_syntax(LocaleID& locale_id)
extension = extension.to_lowercase();
}
Optional<String> canonicalize_unicode_locale_id(LocaleID& locale_id)
Optional<DeprecatedString> canonicalize_unicode_locale_id(LocaleID& locale_id)
{
// https://unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers
StringBuilder builder;
auto append_sep_and_string = [&](Optional<String> const& string) {
auto append_sep_and_string = [&](Optional<DeprecatedString> const& string) {
if (!string.has_value() || string->is_empty())
return;
builder.appendff("-{}", *string);
@ -730,9 +730,9 @@ Optional<String> canonicalize_unicode_locale_id(LocaleID& locale_id)
return builder.build();
}
String const& default_locale()
DeprecatedString const& default_locale()
{
static String locale = "en"sv;
static DeprecatedString locale = "en"sv;
return locale;
}
@ -804,7 +804,7 @@ Optional<StringView> __attribute__((weak)) get_locale_short_date_field_mapping(S
Optional<StringView> __attribute__((weak)) get_locale_narrow_date_field_mapping(StringView, StringView) { return {}; }
// https://www.unicode.org/reports/tr35/tr35-39/tr35-general.html#Display_Name_Elements
Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id)
Optional<DeprecatedString> format_locale_for_display(StringView locale, LocaleID locale_id)
{
auto language_id = move(locale_id.language_id);
VERIFY(language_id.language.has_value());
@ -822,7 +822,7 @@ Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id
if (language_id.region.has_value())
region = get_locale_territory_mapping(locale, *language_id.region).value_or(*language_id.region);
Optional<String> secondary_tag;
Optional<DeprecatedString> secondary_tag;
if (script.has_value() && region.has_value())
secondary_tag = patterns->locale_separator.replace("{0}"sv, *script, ReplaceMode::FirstOnly).replace("{1}"sv, *region, ReplaceMode::FirstOnly);
@ -872,7 +872,7 @@ Optional<LanguageID> remove_likely_subtags(LanguageID const& language_id)
// 4. Then for trial in {languagemax, languagemax_regionmax, languagemax_scriptmax}:
// If AddLikelySubtags(trial) = max, then return trial + variants.
auto run_trial = [&](Optional<String> language, Optional<String> script, Optional<String> region) -> Optional<LanguageID> {
auto run_trial = [&](Optional<DeprecatedString> language, Optional<DeprecatedString> script, Optional<DeprecatedString> region) -> Optional<LanguageID> {
LanguageID trial { .language = move(language), .script = move(script), .region = move(region) };
if (add_likely_subtags(trial) == maximized)
@ -891,9 +891,9 @@ Optional<LanguageID> remove_likely_subtags(LanguageID const& language_id)
return return_language_and_variants(maximized.release_value(), move(variants));
}
Optional<String> __attribute__((weak)) resolve_most_likely_territory(LanguageID const&) { return {}; }
Optional<DeprecatedString> __attribute__((weak)) resolve_most_likely_territory(LanguageID const&) { return {}; }
String resolve_most_likely_territory_alias(LanguageID const& language_id, StringView territory_alias)
DeprecatedString resolve_most_likely_territory_alias(LanguageID const& language_id, StringView territory_alias)
{
auto aliases = territory_alias.split_view(' ');
@ -906,11 +906,11 @@ String resolve_most_likely_territory_alias(LanguageID const& language_id, String
return aliases[0].to_string();
}
String LanguageID::to_string() const
DeprecatedString LanguageID::to_string() const
{
StringBuilder builder;
auto append_segment = [&](Optional<String> const& segment) {
auto append_segment = [&](Optional<DeprecatedString> const& segment) {
if (!segment.has_value())
return;
if (!builder.is_empty())
@ -927,11 +927,11 @@ String LanguageID::to_string() const
return builder.build();
}
String LocaleID::to_string() const
DeprecatedString LocaleID::to_string() const
{
StringBuilder builder;
auto append_segment = [&](Optional<String> const& segment) {
auto append_segment = [&](Optional<DeprecatedString> const& segment) {
if (!segment.has_value() || segment->is_empty())
return;
if (!builder.is_empty())

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
@ -17,29 +17,29 @@
namespace Locale {
struct LanguageID {
String to_string() const;
DeprecatedString to_string() const;
bool operator==(LanguageID const&) const = default;
bool is_root { false };
Optional<String> language {};
Optional<String> script {};
Optional<String> region {};
Vector<String> variants {};
Optional<DeprecatedString> language {};
Optional<DeprecatedString> script {};
Optional<DeprecatedString> region {};
Vector<DeprecatedString> variants {};
};
struct Keyword {
String key {};
String value {};
DeprecatedString key {};
DeprecatedString value {};
};
struct LocaleExtension {
Vector<String> attributes {};
Vector<DeprecatedString> attributes {};
Vector<Keyword> keywords {};
};
struct TransformedField {
String key {};
String value {};
DeprecatedString key {};
DeprecatedString value {};
};
struct TransformedExtension {
@ -49,13 +49,13 @@ struct TransformedExtension {
struct OtherExtension {
char key {};
String value {};
DeprecatedString value {};
};
using Extension = AK::Variant<LocaleExtension, TransformedExtension, OtherExtension>;
struct LocaleID {
String to_string() const;
DeprecatedString to_string() const;
template<typename ExtensionType>
Vector<Extension> remove_extension_type()
@ -75,7 +75,7 @@ struct LocaleID {
LanguageID language_id {};
Vector<Extension> extensions {};
Vector<String> private_use_extensions {};
Vector<DeprecatedString> private_use_extensions {};
};
enum class Style : u8 {
@ -139,10 +139,10 @@ bool is_type_identifier(StringView);
Optional<LanguageID> parse_unicode_language_id(StringView);
Optional<LocaleID> parse_unicode_locale_id(StringView);
void canonicalize_unicode_extension_values(StringView key, String& value, bool remove_true);
Optional<String> canonicalize_unicode_locale_id(LocaleID&);
void canonicalize_unicode_extension_values(StringView key, DeprecatedString& value, bool remove_true);
Optional<DeprecatedString> canonicalize_unicode_locale_id(LocaleID&);
String const& default_locale();
DeprecatedString const& default_locale();
bool is_locale_available(StringView locale);
Span<StringView const> get_available_keyword_values(StringView key);
@ -176,7 +176,7 @@ Vector<StringView> get_keywords_for_locale(StringView locale, StringView key);
Optional<StringView> get_preferred_keyword_value_for_locale(StringView locale, StringView key);
Optional<DisplayPattern> get_locale_display_patterns(StringView locale);
Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id);
Optional<DeprecatedString> format_locale_for_display(StringView locale, LocaleID locale_id);
Optional<StringView> get_locale_language_mapping(StringView locale, StringView language);
Optional<StringView> get_locale_territory_mapping(StringView locale, StringView territory);
@ -206,7 +206,7 @@ void resolve_complex_language_aliases(LanguageID& language_id);
Optional<LanguageID> add_likely_subtags(LanguageID const& language_id);
Optional<LanguageID> remove_likely_subtags(LanguageID const& language_id);
Optional<String> resolve_most_likely_territory(LanguageID const& language_id);
String resolve_most_likely_territory_alias(LanguageID const& language_id, StringView territory_alias);
Optional<DeprecatedString> resolve_most_likely_territory(LanguageID const& language_id);
DeprecatedString resolve_most_likely_territory_alias(LanguageID const& language_id, StringView territory_alias);
}

View file

@ -29,7 +29,7 @@ Optional<Span<u32 const>> __attribute__((weak)) get_digits_for_number_system(Str
return digits.span();
}
String replace_digits_for_number_system(StringView system, StringView number)
DeprecatedString replace_digits_for_number_system(StringView system, StringView number)
{
auto digits = get_digits_for_number_system(system);
if (!digits.has_value())
@ -64,7 +64,7 @@ static u32 last_code_point(StringView string)
#endif
// https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView currency_display, [[maybe_unused]] StringView base_pattern)
Optional<DeprecatedString> augment_currency_format_pattern([[maybe_unused]] StringView currency_display, [[maybe_unused]] StringView base_pattern)
{
#if ENABLE_UNICODE_DATA
constexpr auto number_key = "{number}"sv;
@ -78,7 +78,7 @@ Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView cur
VERIFY(currency_index.has_value());
Utf8View utf8_currency_display { currency_display };
Optional<String> currency_key_with_spacing;
Optional<DeprecatedString> currency_key_with_spacing;
if (*number_index < *currency_index) {
u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *currency_index));
@ -87,7 +87,7 @@ Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView cur
u32 first_currency_code_point = *utf8_currency_display.begin();
if (!Unicode::code_point_has_general_category(first_currency_code_point, Unicode::GeneralCategory::Symbol))
currency_key_with_spacing = String::formatted("{}{}", spacing, currency_key);
currency_key_with_spacing = DeprecatedString::formatted("{}{}", spacing, currency_key);
}
} else {
u32 last_pattern_code_point = last_code_point(base_pattern.substring_view(0, *number_index));
@ -96,7 +96,7 @@ Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView cur
u32 last_currency_code_point = last_code_point(currency_display);
if (!Unicode::code_point_has_general_category(last_currency_code_point, Unicode::GeneralCategory::Symbol))
currency_key_with_spacing = String::formatted("{}{}", currency_key, spacing);
currency_key_with_spacing = DeprecatedString::formatted("{}{}", currency_key, spacing);
}
}
@ -108,11 +108,11 @@ Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView cur
}
// https://unicode.org/reports/tr35/tr35-numbers.html#83-range-pattern-processing
Optional<String> augment_range_pattern([[maybe_unused]] StringView range_separator, [[maybe_unused]] StringView lower, [[maybe_unused]] StringView upper)
Optional<DeprecatedString> augment_range_pattern([[maybe_unused]] StringView range_separator, [[maybe_unused]] StringView lower, [[maybe_unused]] StringView upper)
{
#if ENABLE_UNICODE_DATA
auto range_pattern_with_spacing = [&]() {
return String::formatted(" {} ", range_separator);
return DeprecatedString::formatted(" {} ", range_separator);
};
Utf8View utf8_range_separator { range_separator };

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibLocale/Forward.h>
@ -64,13 +64,13 @@ Optional<StringView> get_number_system_symbol(StringView locale, StringView syst
Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system);
Optional<Span<u32 const>> get_digits_for_number_system(StringView system);
String replace_digits_for_number_system(StringView system, StringView number);
DeprecatedString replace_digits_for_number_system(StringView system, StringView number);
Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style);
Optional<String> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
Optional<String> augment_range_pattern(StringView range_separator, StringView lower, StringView upper);
Optional<DeprecatedString> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
Optional<DeprecatedString> augment_range_pattern(StringView range_separator, StringView lower, StringView upper);
}