-
Notifications
You must be signed in to change notification settings - Fork 0
/
Glyph.cs
49 lines (42 loc) · 1.16 KB
/
Glyph.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
public struct Glyph
{
static readonly char[] vowels = new char[] { 'a', 'e', 'o', 'i', 'u' };
public char Base { get; set; }
public char? Diacritic { get; set; }
public bool IsVowel => vowels.Contains(Base);
public int Weight
{
get
{
switch (Diacritic ?? ' ')
{
case Constants.CIRCUMFLEX:
return 2;
case Constants.MACRON:
return 1;
default:
return 0;
}
}
}
public Glyph(string str) : this(str.ToList()) { }
public Glyph(IList<char> str) {
switch (str.Count)
{
case 1:
Base = str[0];
Diacritic = null;
break;
case 2:
Base = str[0];
Diacritic = str[1];
break;
default:
throw new ArgumentException($"{str} has invalid length {str.Count}");
}
}
public override string ToString() => Base.ToString() + Diacritic ?? "";
}