File size: 1,485 Bytes
e53fda1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import hashlib
import sys
import re


def hash_text_sha256(text: str) -> str:
    hash_object = hashlib.sha256(text.encode())
    return hash_object.hexdigest()


def contains_regex_characters(s: str) -> bool:
    # Pattern to match special regex characters
    regex_chars_pattern = r'[\.\^\$\*\+\?\{\}\[\]\\|()]'

    # Search for special regex characters in the string
    return re.search(regex_chars_pattern, s)


def strip_anchor_chars(s: str) -> str:
    # Strip the first character if it's '^'
    if s.startswith('^'):
        s = s[1:]

    # Strip the last character if it's '$'
    if s.endswith('$'):
        s = s[:-1]

    return s


def contains_punctuation(s: str) -> bool:
    # Pattern to match punctuation characters
    punctuation_pattern = r'[^\w\s_]'

    # Search for punctuation characters in the string
    return re.search(punctuation_pattern, s)


def is_numbered_bullet_list_item(s: str) -> int:
    # Regular expression to match the series of numbers followed by a dot
    pattern = r'^\d+\.'

    match = re.match(pattern, s)
    if match:
        # If there's a match, return the index right after the matched pattern
        return match.end()
    else:
        # If no match, return an invalid value
        return -1


def replace_unsupported_chars(text, replacement='?'):
    encoding = sys.getdefaultencoding()  # Get the default system encoding
    return text.encode(encoding, errors='replace').decode(encoding).replace('\ufffd', replacement)