Mercurial > pub > ImplabNet
comparison Implab/Formats/CharMap.cs @ 228:6fa235c5a760 v2
Rewritten JsonScanner, JsonParser, fixed naming style
author | cin |
---|---|
date | Tue, 12 Sep 2017 01:19:12 +0300 |
parents | |
children | 302ca905c19e |
comparison
equal
deleted
inserted
replaced
227:8d5de4eb9c2c | 228:6fa235c5a760 |
---|---|
1 using Implab.Automaton; | |
2 using System; | |
3 using System.Collections.Generic; | |
4 using System.Linq; | |
5 using System.Runtime.CompilerServices; | |
6 using System.Text; | |
7 using System.Threading.Tasks; | |
8 | |
9 namespace Implab.Formats { | |
10 public class CharMap : IAlphabet<char> { | |
11 readonly char m_min; | |
12 readonly char m_max; | |
13 readonly int[] m_map; | |
14 | |
15 public CharMap(char min, int[] map) { | |
16 Safe.ArgumentNotNull(map, nameof(map)); | |
17 Count = map.Max()+1; | |
18 m_min = min; | |
19 m_map = map; | |
20 m_max = (char)(min + map.Length); | |
21 } | |
22 | |
23 public int Count { | |
24 get; private set; | |
25 } | |
26 | |
27 public bool Contains(char symbol) { | |
28 return symbol >= m_min && symbol <= m_max && m_map[symbol-m_min] != AutomatonConst.UNCLASSIFIED_INPUT; | |
29 } | |
30 | |
31 public IEnumerable<char> GetSymbols(int cls) { | |
32 for (var i = 0; i < m_map.Length; i++) | |
33 if (m_map[i] == cls) | |
34 yield return (char)(i + m_min); | |
35 } | |
36 | |
37 [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
38 public int Translate(char symbol) { | |
39 return symbol >= m_min && symbol <= m_max ? m_map[symbol-m_min] : AutomatonConst.UNCLASSIFIED_INPUT; | |
40 } | |
41 } | |
42 } |