|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
|
|
namespace Avalonia.Media.TextFormatting.Unicode |
|
|
|
@ -222,6 +223,71 @@ namespace Avalonia.Media.TextFormatting.Unicode |
|
|
|
|
|
|
|
return new Codepoint(code); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads the <see cref="Codepoint"/> at specified position.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="text">The buffer to read from.</param>
|
|
|
|
/// <param name="index">The index to read at.</param>
|
|
|
|
/// <param name="count">The count of character that were read.</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static Codepoint ReadAt(ReadOnlySpan<char> text, int index, out int count) |
|
|
|
{ |
|
|
|
count = 1; |
|
|
|
|
|
|
|
if (index >= text.Length) |
|
|
|
{ |
|
|
|
return ReplacementCodepoint; |
|
|
|
} |
|
|
|
|
|
|
|
var code = text[index]; |
|
|
|
|
|
|
|
ushort hi, low; |
|
|
|
|
|
|
|
//# High surrogate
|
|
|
|
if (0xD800 <= code && code <= 0xDBFF) |
|
|
|
{ |
|
|
|
hi = code; |
|
|
|
|
|
|
|
if (index + 1 == text.Length) |
|
|
|
{ |
|
|
|
return ReplacementCodepoint; |
|
|
|
} |
|
|
|
|
|
|
|
low = text[index + 1]; |
|
|
|
|
|
|
|
if (0xDC00 <= low && low <= 0xDFFF) |
|
|
|
{ |
|
|
|
count = 2; |
|
|
|
return new Codepoint((uint)((hi - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)); |
|
|
|
} |
|
|
|
|
|
|
|
return ReplacementCodepoint; |
|
|
|
} |
|
|
|
|
|
|
|
//# Low surrogate
|
|
|
|
if (0xDC00 <= code && code <= 0xDFFF) |
|
|
|
{ |
|
|
|
if (index == 0) |
|
|
|
{ |
|
|
|
return ReplacementCodepoint; |
|
|
|
} |
|
|
|
|
|
|
|
hi = text[index - 1]; |
|
|
|
|
|
|
|
low = code; |
|
|
|
|
|
|
|
if (0xD800 <= hi && hi <= 0xDBFF) |
|
|
|
{ |
|
|
|
count = 2; |
|
|
|
return new Codepoint((uint)((hi - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)); |
|
|
|
} |
|
|
|
|
|
|
|
return ReplacementCodepoint; |
|
|
|
} |
|
|
|
|
|
|
|
return new Codepoint(code); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns <see langword="true"/> if <paramref name="cp"/> is between
|
|
|
|
|