Completed
Push — master ( a40b3d...7d1203 )
by P.R.
01:54
created

SDoc.escape()   A

Complexity

Conditions 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A SDoc.replace() 0 2 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
import re
10
11
12
class SDoc:
13
    """
14
    Utility class with functions for generating SDoc code.
15
    """
16
17
    # ------------------------------------------------------------------------------------------------------------------
18
    @staticmethod
19
    def escape(text):
20
        """
21
        Returns an escaped string that is svae to use in SDoc.
22
23
        :param text: The escaped string.
24
25
        :rtype: str
26
        """
27
28
        def replace(matchobj):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
29
            return '\\' + matchobj.group(0)
30
31
        return re.sub(r'[\\{}]', replace, text)
32
33
    # ------------------------------------------------------------------------------------------------------------------
34
    @staticmethod
35
    def unescape(text):
36
        """
37
        Returns an unescaped SDoc escaped string. I.e. removes back slashes.
38
39
        :param text: The SDoc escaped string.
40
41
        :rtype: str
42
        """
43
44
        def replace(matchobj):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
45
            return matchobj.group(0)[1:]
46
47
        return re.sub(r'\\.', replace, text)
48
49
50
# ----------------------------------------------------------------------------------------------------------------------
51