int GetDecomposed(ref UnicodeEntry entry, int orgValue) { if (_compositeMap.TryGetValue(entry.CodeValue, out var comp)) { if (!_compositeMap.ContainsKey(orgValue)) { _compositeMap.Add(orgValue, comp); } return(1); } _decomposing.Clear(); _loader.AddDecomposing(entry.CodeValue, _decomposing, true); _decomposeLetters.Clear(); foreach (var c in _decomposing) { if (_loader.TryGetEntry(c, out UnicodeEntry decomposed)) { if (IsLetterOrDigit(decomposed.Category)) { if (decomposed.Uppercase != 0) { if (!_loader.TryGetEntry(decomposed.Uppercase, out decomposed) || !IsLetterOrDigit(decomposed.Category)) { continue; } } _decomposeLetters.Add(decomposed); } } } switch (_decomposeLetters.Count) { case 0: return(0); case 1: return(_decomposeLetters[0].CodeValue); default: _builder.Clear(); _decomposing.Clear(); foreach (var letter in _decomposeLetters) { _decomposing.Add(letter.CodeValue); _builder.Append(' ').Append(letter.ToString()); } _compositeMap.Add(entry.CodeValue, Add(_decomposing.ToArray())); //Debug.WriteLine( $"{entry.Name} ({entry}) d[{_decomposeLetters.Count}]:{_builder.ToString()}" ); return(1); } }
public TableBuilder(UcdLoader loader) { _loader = loader; var list = new List <CodeEntry>(); //foreach ( var entry in loader.GetCodePoints() ) { // all[ entry.CodeValue ] = entry.ToString(); //} var blocks = new List <BlockEntry>(); var decomposing = new List <int>(); var builder = new StringBuilder(); string GetDecomposed(int codePoint, bool cascade) { decomposing.Clear(); loader.AddDecomposing(codePoint, decomposing, cascade); if (decomposing.Count <= 1) { // accept only multi-code point decombosions return(null); } builder.Clear(); foreach (int code in decomposing) { var entry = loader[code]; if (entry.CodeValue == 0) { return(null); } entry.AppendCharTo(builder); } return(builder.ToString()); } foreach (UcdBlock block in loader.Blocks) { switch (block.Block) { case Block.HighSurrogates: case Block.HighPrivateUseSurrogates: case Block.LowSurrogates: case Block.PrivateUseArea: case Block.SupplementaryPrivateUseAreaA: case Block.SupplementaryPrivateUseAreaB: continue; } list.Clear(); foreach (UnicodeEntry entry in loader.GetCodePoints(block)) { list.Add(new CodeEntry(entry.CodeValue, entry.ToString())); if (entry.DecomposingLength > 0) { string decomp = GetDecomposed(entry.CodeValue, true); if (decomp != null) { list.Add(new CodeEntry(entry.CodeValue, decomp, 2)); string decomp2 = GetDecomposed(entry.CodeValue, false); if (decomp2 != null && decomp2 != decomp) { list.Add(new CodeEntry(entry.CodeValue, decomp2, 1)); } } } } blocks.Add(new BlockEntry() { Block = block, Entries = list.ToArray() }); } _allBlocks = blocks.ToArray(); }
int GetDecomposed(int codePoint, bool cascade) { _decomposing.Clear(); _loader.AddDecomposing(codePoint, _decomposing, cascade); return(_decomposing[0]); }