using System.Diagnostics;
namespace System.Unicode
{
/// Provides information on radical and additional stroke count for a code point.
/// Values of this type are usually associated with the property kRSUnicode (aka. Unicode_Radical_Stroke).
[DebuggerDisplay(@"{IsSimplified ? ""Simplified"" : ""Traditional"",nq} Radical {Radical} + {StrokeCount} Strokes")]
public struct UnicodeRadicalStrokeCount
{
internal static readonly UnicodeRadicalStrokeCount[] EmptyArray = new UnicodeRadicalStrokeCount[0];
/// Initializes a new instance of the class from raw data.
/// The raw value to use for .
/// The raw value to use for .
internal UnicodeRadicalStrokeCount(byte rawRadical, byte rawStrokeCount)
{
Radical = rawRadical;
RawStrokeCount = rawStrokeCount;
}
/// Initializes a new instance of the class .
/// must be between -64 and 63 included.
/// The index of the Kangxi radical of the character.
/// The number of additional strokes required to form the character from the radical.
/// Indicates whether the character is simplified.
/// is outside of the allowed range.
internal UnicodeRadicalStrokeCount(byte radical, sbyte strokeCount, bool isSimplified)
{
if (strokeCount < -64 || strokeCount > 63) throw new ArgumentOutOfRangeException(nameof(strokeCount));
Radical = radical;
// Pack strokeCount together with isSimplified in a single byte.
RawStrokeCount = unchecked((byte)(strokeCount & 0x7F | (isSimplified ? 0x80 : 0x00)));
}
/// Gets the index of the Kangxi radical of the character.
/// The Kangxi radicals are numbered from 1 to 214 inclusive.
/// The index of the Kangxi radical.
public byte Radical { get; }
/// Gets the value of packed with .
/// The stroke count is stored as a 7bit signed value, together with the flag as a 1bit value.
/// The raw value of .
internal byte RawStrokeCount { get; }
/// Gets the additional stroke count.
/// The additional stroke count.
public sbyte StrokeCount { get { return unchecked((sbyte)(RawStrokeCount & 0x7F | (RawStrokeCount & 0x40) << 1)); } } // To unpack the stroke count, we simply need to copy bit 6 to bit 7.
/// Gets a value indicating whether the information is based on the simplified form of the radical.
/// if the information is based on the simplified form of the radical; otherwise, .
public bool IsSimplified { get { return (RawStrokeCount & 0x80) != 0; } }
}
}