| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="PascalCasingTransform.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 | | using System.Text.RegularExpressions; |
| | | 10 | | |
| | | 11 | | namespace MyNet.Text.TextCasing; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Transforms a string to PascalCase. |
| | | 15 | | /// </summary> |
| | | 16 | | public sealed partial class PascalCasingTransform : ITextCasingTransform |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="PascalCasingTransform"/> class. |
| | | 20 | | /// </summary> |
| | 48 | 21 | | internal PascalCasingTransform() { } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc/> |
| | | 24 | | public string Apply(string input, CultureInfo culture) |
| | | 25 | | { |
| | 81 | 26 | | ArgumentNullException.ThrowIfNull(input); |
| | 81 | 27 | | ArgumentNullException.ThrowIfNull(culture); |
| | | 28 | | |
| | 81 | 29 | | return PascalizeRegex().Replace(input, match => match.Groups[1].Value.ToUpper(culture)); |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | [GeneratedRegex("(?:^|_| +)(.)")] |
| | | 33 | | private static partial Regex PascalizeRegex(); |
| | | 34 | | } |
| | | 35 | | |