File: text_sentencecase.py

package info (click to toggle)
inkscape 1.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 402,900 kB
  • sloc: cpp: 547,256; python: 72,677; ansic: 63,355; javascript: 3,864; xml: 2,345; sh: 1,667; makefile: 824; perl: 614
file content (38 lines) | stat: -rwxr-xr-x 1,017 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
"""Convert to sentence case"""

import inkex


class SentenceCase(inkex.TextExtension):
    """Convert text to sentence case"""

    sentence_start = True
    was_punctuation = False

    def map_char(self, char):
        """Turn the char into a sentence using class state"""
        if char in ".!?":
            self.was_punctuation = True
        elif ((char.isspace() or self.newline) and self.was_punctuation) or self.newpar:
            self.sentence_start = True
            self.was_punctuation = False
        elif char in '")':
            pass
        else:
            self.was_punctuation = False

        if not char.isspace():
            self.newline = False
            self.newpar = False

        if self.sentence_start and char.isalpha():
            self.sentence_start = False
            return char.upper()
        elif not self.sentence_start and char.isalpha():
            return char.lower()
        return char


if __name__ == "__main__":
    SentenceCase().run()