Make the Diacritics class public for use in external StreamProcessors

This commit is contained in:
BobLd
2025-05-30 08:31:16 +01:00
parent d9b3891eb3
commit b5b58434e9
2 changed files with 32 additions and 2 deletions

View File

@@ -278,6 +278,7 @@
"UglyToad.PdfPig.Util.DefaultWordExtractor",
"UglyToad.PdfPig.Util.DateFormatHelper",
"UglyToad.PdfPig.Util.DictionaryTokenExtensions",
"UglyToad.PdfPig.Util.Diacritics",
"UglyToad.PdfPig.Util.WhitespaceSizeStatistics",
"UglyToad.PdfPig.Writer.ITokenWriter",
"UglyToad.PdfPig.Writer.PdfAStandard",

View File

@@ -4,7 +4,10 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
internal static class Diacritics
/// <summary>
/// Helper class for diacritics.
/// </summary>
public static class Diacritics
{
private static readonly HashSet<string> NonCombiningDiacritics =
[
@@ -21,8 +24,21 @@
"¸"
];
public static bool IsPotentialStandaloneDiacritic(string value) => NonCombiningDiacritics.Contains(value);
internal static bool IsPotentialStandaloneDiacritic(string value) => NonCombiningDiacritics.Contains(value);
/// <summary>
/// Determines whether the specified string contains a single character
/// that falls within the Unicode combining diacritic range (U+0300 to U+036F).
/// </summary>
/// <param name="value">The string to check. It should contain exactly one character.</param>
/// <returns>
/// <c>true</c> if the character in the string is within the combining diacritic range;
/// otherwise, <c>false</c>.
/// </returns>
/// <remarks>
/// This method is useful for identifying characters that are typically used as
/// combining diacritics in Unicode text.
/// </remarks>
public static bool IsInCombiningDiacriticRange(string value)
{
if (value.Length != 1)
@@ -40,6 +56,19 @@
return false;
}
/// <summary>
/// Attempts to combine a diacritic character with the preceding letter to form a single combined character.
/// </summary>
/// <param name="diacritic">The diacritic character to combine.</param>
/// <param name="previous">The preceding letter to combine with the diacritic.</param>
/// <param name="result">
/// When this method returns, contains the combined character if the combination was successful;
/// otherwise, <see langword="null"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the diacritic was successfully combined with the preceding letter;
/// otherwise, <see langword="false"/>.
/// </returns>
public static bool TryCombineDiacriticWithPreviousLetter(string diacritic, string previous, [NotNullWhen(true)] out string? result)
{
result = null;