annotate Implab/Formats/CharMap.cs @ 276:b4e0f81c7425 v3

container configuration docs
author cin
date Sat, 28 Apr 2018 00:11:38 +0300
parents 302ca905c19e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
1 using Implab.Automaton;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
2 using System;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
3 using System.Collections.Generic;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
4 using System.Linq;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
5 using System.Runtime.CompilerServices;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
6 using System.Text;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
7 using System.Threading.Tasks;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
8
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
9 namespace Implab.Formats {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
10 public class CharMap : IAlphabet<char> {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
11 readonly char m_min;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
12 readonly char m_max;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
13 readonly int[] m_map;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
14
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
15 public CharMap(char min, int[] map) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
16 Safe.ArgumentNotNull(map, nameof(map));
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
17 Count = map.Max()+1;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
18 m_min = min;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
19 m_map = map;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
20 m_max = (char)(min + map.Length);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
21 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
22
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
23 public int Count {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
24 get; private set;
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
25 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
26
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
27 public bool Contains(char symbol) {
236
302ca905c19e JsonReader optimizations
cin
parents: 228
diff changeset
28 return symbol >= m_min && symbol <= m_max && m_map[symbol-m_min] != AutomatonConst.UnclassifiedInput;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
29 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
30
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
31 public IEnumerable<char> GetSymbols(int cls) {
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
32 for (var i = 0; i < m_map.Length; i++)
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
33 if (m_map[i] == cls)
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
34 yield return (char)(i + m_min);
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
35 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
36
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
37 [MethodImpl(MethodImplOptions.AggressiveInlining)]
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
38 public int Translate(char symbol) {
236
302ca905c19e JsonReader optimizations
cin
parents: 228
diff changeset
39 return symbol >= m_min && symbol <= m_max ? m_map[symbol-m_min] : AutomatonConst.UnclassifiedInput;
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
40 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
41 }
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents:
diff changeset
42 }