| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="SentenceCasingTransform.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Globalization; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Text.TextCasing; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Transforms a string to sentence case, meaning the first letter is capitalized and the rest are unchanged. |
| | | 14 | | /// </summary> |
| | | 15 | | public sealed class SentenceCasingTransform : ITextCasingTransform |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Initializes a new instance of the <see cref="SentenceCasingTransform"/> class. |
| | | 19 | | /// </summary> |
| | 6 | 20 | | internal SentenceCasingTransform() { } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Transforms the input to sentence case. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="input">The string to transform.</param> |
| | | 26 | | /// <param name="culture">The culture to use for the transformation.</param> |
| | | 27 | | /// <returns>The transformed string in sentence case.</returns> |
| | | 28 | | public string Apply(string input, CultureInfo culture) |
| | | 29 | | { |
| | 18 | 30 | | ArgumentNullException.ThrowIfNull(input); |
| | 18 | 31 | | ArgumentNullException.ThrowIfNull(culture); |
| | | 32 | | |
| | 18 | 33 | | return string.IsNullOrEmpty(input) |
| | 18 | 34 | | ? input |
| | 18 | 35 | | : input.Length == 1 |
| | 18 | 36 | | ? input.ToUpper(culture) |
| | 18 | 37 | | : string.Concat( |
| | 18 | 38 | | culture.TextInfo.ToUpper(input[..1]), |
| | 18 | 39 | | input[1..]); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |