public static TranslationLengthCorrector Create(IEnumerable <GraphemeTranslation> translations, Language srcLanguage) { int variantCount = srcLanguage.MaxLetter - srcLanguage.MinLetter + 1; TranslationLengthCorrector t = new( srcLanguage.MinLetter, new GraphemeVariant { Variants = new GraphemeVariant?[variantCount] } ); foreach (GraphemeTranslation translation in translations) { if (string.IsNullOrEmpty(translation.Original.Letters)) { continue; } ref var vs = ref t.root.Variants; GraphemeVariant?v = null; foreach (char letter in translation.Original.Letters) { vs ??= new GraphemeVariant[variantCount]; v = vs[letter - t.offset]; if (v == null) { v = new GraphemeVariant(); vs[letter - t.offset] = v; } vs = ref v.Variants; } if (v != null) { v.ExistGrapheme = true; } }
private TranslationLengthCorrector(int offset, GraphemeVariant root) { this.offset = offset; this.root = root; }