jagregory / boolangstudio forked from olsonjeffery/boolangstudio

Boo language integration for Visual Studio 2008

This URL has Read+Write access

boolangstudio / Source / BooLangService / StringParsing / BracketPairCollection.cs
100644 88 lines (72 sloc) 1.966 kb
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
using System.Collections;
using System.Collections.Generic;
 
namespace Boo.BooLangService.StringParsing
{
    public class BracketPairCollection : ICollection<BracketPair>
    {
        private readonly List<BracketPair> pairs = new List<BracketPair>();
 
        public IEnumerator<BracketPair> GetEnumerator()
        {
            return pairs.GetEnumerator();
        }
 
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
 
        public void Add(BracketPair item)
        {
            pairs.Add(item);
        }
 
        public void Clear()
        {
            pairs.Clear();
        }
 
        public bool Contains(BracketPair item)
        {
            return pairs.Contains(item);
        }
 
        public void CopyTo(BracketPair[] array, int arrayIndex)
        {
            pairs.CopyTo(array, arrayIndex);
        }
 
        public bool Remove(BracketPair item)
        {
            return pairs.Remove(item);
        }
 
        public int Count
        {
            get { return pairs.Count; }
        }
 
        public bool IsReadOnly
        {
            get { return false; }
        }
 
        public BracketPair FindLeftByIndex(int index)
        {
            foreach (var pair in pairs)
            {
                if (pair.LeftIndex == index)
                    return pair;
            }
 
            return null;
        }
 
        public BracketPair FindRightByIndex(int index)
        {
            foreach (var pair in pairs)
            {
                if (pair.RightIndex == index)
                    return pair;
            }
 
            return null;
        }
 
        public int? FindPartnerIndex(int index)
        {
            foreach (var pair in pairs)
            {
                if (pair.LeftIndex == index) return pair.RightIndex;
                if (pair.RightIndex == index) return pair.LeftIndex;
            }
 
            return null;
        }
    }
}