A game framework written with osu! in mind.
at master 3.6 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4#nullable enable 5 6using System; 7using osu.Framework.Localisation; 8 9namespace osu.Framework.Extensions.LocalisationExtensions 10{ 11 public static class LocalisableStringExtensions 12 { 13 /// <summary> 14 /// Returns a <see cref="LocalisableFormattableString"/> formatting the given <paramref name="value"/> to a string, along with an optional <paramref name="format"/> string. 15 /// </summary> 16 /// <param name="value">The value to format.</param> 17 /// <param name="format">The format string.</param> 18 public static LocalisableFormattableString ToLocalisableString(this IFormattable value, string? format = null) 19 => new LocalisableFormattableString(value, format); 20 21 /// <summary> 22 /// Returns a <see cref="CaseTransformableString"/> with the specified underlying localisable string uppercased. 23 /// </summary> 24 /// <param name="str">The localisable string.</param> 25 /// <returns>A case transformable string with its localisable string uppercased.</returns> 26 public static CaseTransformableString ToUpper(this LocalisableString str) => new CaseTransformableString(str, Casing.UpperCase); 27 28 /// <summary> 29 /// Returns a <see cref="CaseTransformableString"/> with the specified underlying string data uppercased. 30 /// </summary> 31 /// <param name="data">The string data.</param> 32 /// <returns>A case transformable string with its string data uppercased.</returns> 33 public static CaseTransformableString ToUpper(this ILocalisableStringData data) => new LocalisableString(data).ToUpper(); 34 35 /// <summary> 36 /// Returns a <see cref="LocalisableString"/> with the specified underlying localisable string transformed to title case. 37 /// </summary> 38 /// <param name="str">The localisable string.</param> 39 /// <returns>A case transformable string with its localisable string transformed to title case.</returns> 40 public static CaseTransformableString ToTitle(this LocalisableString str) => new CaseTransformableString(str, Casing.TitleCase); 41 42 /// <summary> 43 /// Returns a <see cref="LocalisableString"/> with the specified underlying string data transformed to title case. 44 /// </summary> 45 /// <param name="data">The string data.</param> 46 /// <returns>A case transformable string with its string data transformed to title case.</returns> 47 public static CaseTransformableString ToTitle(this ILocalisableStringData data) => new LocalisableString(data).ToTitle(); 48 49 /// <summary> 50 /// Returns a <see cref="LocalisableString"/> with the specified underlying localisable string lowercased. 51 /// </summary> 52 /// <param name="str">The localisable string.</param> 53 /// <returns>A case transformable string with its localisable string lowercased.</returns> 54 public static CaseTransformableString ToLower(this LocalisableString str) => new CaseTransformableString(str, Casing.LowerCase); 55 56 /// <summary> 57 /// Returns a <see cref="LocalisableString"/> with the specified underlying string data lowercased. 58 /// </summary> 59 /// <param name="data">The string data.</param> 60 /// <returns>A case transformable string with its string data lowercased.</returns> 61 public static CaseTransformableString ToLower(this ILocalisableStringData data) => new LocalisableString(data).ToLower(); 62 } 63}