Failed Conditions
Pull Request — master (#1990)
by Mischa
01:34
created

coalib.parsing.StringProcessing.Match   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %
Metric Value
dl 0
loc 60
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A Match.position() 0 8 1
A Match.__len__() 0 2 1
A Match.range() 0 9 1
A Match.end_position() 0 8 1
A Match.__str__() 0 2 1
A Match.match() 0 8 1
A Match.__init__() 0 10 1
1
from coalib.misc.Decorators import generate_ordering, generate_repr
2
3
4
@generate_repr("match", "range")
5
@generate_ordering("range", "match")
6
class Match:
7
    """
8
    Stores information about a single textual match.
9
    """
10
11
    def __init__(self, match, position):
12
        """
13
        Instantiates a new Match.
14
15
        :param match:    The actual matched string.
16
        :param position: The position where the match was found. Starts from
17
                         zero.
18
        """
19
        self._match = match
20
        self._position = position
21
22
    def __len__(self):
23
        return len(self.match)
24
25
    def __str__(self):
26
        return self.match
27
28
    @property
29
    def match(self):
30
        """
31
        Returns the text matched.
32
33
        :returns: The text matched.
34
        """
35
        return self._match
36
37
    @property
38
    def position(self):
39
        """
40
        Returns the position where the text was matched (zero-based).
41
42
        :returns: The position.
43
        """
44
        return self._position
45
46
    @property
47
    def end_position(self):
48
        """
49
        Marks the end position of the matched text (zero-based).
50
51
        :returns: The end-position.
52
        """
53
        return len(self) + self.position
54
55
    @property
56
    def range(self):
57
        """
58
        Returns the position range where the text was matched.
59
60
        :returns: A pair indicating the position range. The first element is
61
                  the start position, the second one the end position.
62
        """
63
        return (self.position, self.end_position)
64