feat(strings): add IUtf8ToAsciiConverter and ICharacterMappingLoader interfaces
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
16
src/Umbraco.Core/Strings/ICharacterMappingLoader.cs
Normal file
16
src/Umbraco.Core/Strings/ICharacterMappingLoader.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Frozen;
|
||||
|
||||
namespace Umbraco.Cms.Core.Strings;
|
||||
|
||||
/// <summary>
|
||||
/// Loads character mappings from JSON files.
|
||||
/// </summary>
|
||||
public interface ICharacterMappingLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads all mapping files and returns combined FrozenDictionary.
|
||||
/// Higher priority mappings override lower priority.
|
||||
/// </summary>
|
||||
/// <returns>Frozen dictionary of character to string mappings.</returns>
|
||||
FrozenDictionary<char, string> LoadMappings();
|
||||
}
|
||||
25
src/Umbraco.Core/Strings/IUtf8ToAsciiConverter.cs
Normal file
25
src/Umbraco.Core/Strings/IUtf8ToAsciiConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Umbraco.Cms.Core.Strings;
|
||||
|
||||
/// <summary>
|
||||
/// Converts UTF-8 text to ASCII, handling accented characters and transliteration.
|
||||
/// </summary>
|
||||
public interface IUtf8ToAsciiConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts text to ASCII, returning a new string.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to convert.</param>
|
||||
/// <param name="fallback">Character to use for unmappable characters. Default '?'.</param>
|
||||
/// <returns>The ASCII-converted string.</returns>
|
||||
string Convert(string? text, char fallback = '?');
|
||||
|
||||
/// <summary>
|
||||
/// Converts text to ASCII, writing to output span.
|
||||
/// Zero-allocation for callers who provide buffer.
|
||||
/// </summary>
|
||||
/// <param name="input">The input text span.</param>
|
||||
/// <param name="output">The output buffer. Must be at least input.Length * 4.</param>
|
||||
/// <param name="fallback">Character to use for unmappable characters. Default '?'.</param>
|
||||
/// <returns>Number of characters written to output.</returns>
|
||||
int Convert(ReadOnlySpan<char> input, Span<char> output, char fallback = '?');
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Strings;
|
||||
|
||||
[TestFixture]
|
||||
public class Utf8ToAsciiConverterInterfaceTests
|
||||
{
|
||||
[Test]
|
||||
public void IUtf8ToAsciiConverter_HasConvertStringMethod()
|
||||
{
|
||||
var type = typeof(IUtf8ToAsciiConverter);
|
||||
var method = type.GetMethod("Convert", new[] { typeof(string), typeof(char) });
|
||||
|
||||
Assert.IsNotNull(method);
|
||||
Assert.AreEqual(typeof(string), method.ReturnType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IUtf8ToAsciiConverter_HasConvertSpanMethod()
|
||||
{
|
||||
var type = typeof(IUtf8ToAsciiConverter);
|
||||
var methods = type.GetMethods().Where(m => m.Name == "Convert").ToList();
|
||||
|
||||
Assert.That(methods.Count, Is.GreaterThanOrEqualTo(2), "Should have at least 2 Convert overloads");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user