Failed Conditions
Pull Request — master (#1127)
by Mischa
01:56
created

coalib.parsing.StringProcessing.LineParser   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 132
Duplicated Lines 0 %
Metric Value
dl 0
loc 132
rs 10
wmc 17

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __get_section_name() 0 7 4
C __seperate_by_first_occurrence() 0 41 7
B __init__() 0 33 1
A __extract_keys_and_value() 0 12 1
B parse() 0 34 4
1
def limit(iterator, count):
2
    """
3
    A filter that removes all elements behind the set limit.
4
5
    :param iterator: The iterator to be filtered.
6
    :param count:    The iterator limit. All elements at positions bigger than
7
                     this limit are trimmed off. Exclusion: 0 or numbers below
8
                     does not limit at all, means the passed iterator is
9
                     completely yielded.
10
    """
11
    if count <= 0:  # Performance branch
12
        for elem in iterator:
13
            yield elem
14
    else:
15
        for elem in iterator:
16
            yield elem
17
            count -= 1
18
            if count == 0:
19
                break
20
21
22
def trim_empty_matches(iterator, groups=(0,)):
23
    """
24
    A filter that removes empty match strings. It can only operate on iterators
25
    whose elements are of type MatchObject.
26
27
    :param iterator: The iterator to be filtered.
28
    :param groups:   An iteratable defining the groups to check for blankness.
29
                     Only results are not yielded if all groups of the match
30
                     are blank.
31
                     You can not only pass numbers but also strings, if your
32
                     MatchObject contains named groups.
33
    """
34
    for elem in iterator:
35
        if any(len(elem.group(group)) > 0 for group in groups):
36
            yield elem
37