-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharSet.cs
101 lines (89 loc) · 2.06 KB
/
CharSet.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace Lex
{
/*
* Class: CharSet
*/
using System;
using System.Collections;
using BitSet;
public class CharSet
{
/*
* Member Variables
*/
private BitSet set;
private bool compflag;
/*
* Function: CharSet
*/
public CharSet()
{
set = new BitSet();
compflag = false;
}
/*
* Function: complement
*/
public void complement()
{
compflag = true;
}
/*
* Function: add
*/
public void add(int i)
{
if (i == 0)
Console.WriteLine("i = 0");
set.Set(i, true);
}
/*
* Function: addncase
* Description: add, ignoring case.
*/
public void addncase(char c)
{
/* Do this in a Unicode-friendly way. */
/* (note that duplicate adds have no effect) */
add(c);
add(Char.ToLower(c));
add(Char.ToUpper(c));
}
/*
* Function: contains
*/
public bool contains(int i)
{
bool result;
result = set.Get(i);
if (compflag)
return (false == result);
return result;
}
/*
* Function: mimic
*/
public void mimic(CharSet s)
{
compflag = s.compflag;
set = new BitSet(s.set);
}
public IEnumerator GetEnumerator() { return set.GetEnumerator(); }
/*
* Map set using character classes
*/
public void map(CharSet old, int[] mapping)
{
compflag = old.compflag;
set = new BitSet();
foreach (int index in old)
{
if (index < mapping.Length) // skip unmapped chars
{
int pos = mapping[index];
set.Set(pos, true);
}
}
}
}
}