Skip to content

Text manipulation

Module for text manipulation functions.

This module contains functions for manipulating text.

Functions:

Name Description
snake_to_sentense

str) -> str: snake to title conversion

kebab_to_sentense

str) -> str: kebab to title conversion

list_to_string

list[str]) -> str: list to string conversion

kebab_to_sentense(kebab_text)

Convert kebab case text to title case text.

Convert kebab case text to title case text. The first letter of the first word is capitalized and the rest of the words are in lower case.

Parameters:

Name Type Description Default
kebab_text str

The kebab case text to convert to title case.

required

Returns:

Name Type Description
str str

The title case text.

Source code in app/dcsp/app/functions/text_manipulation.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def kebab_to_sentense(kebab_text: str) -> str:
    """Convert kebab case text to title case text.

    Convert kebab case text to title case text. The first letter of the first
    word is capitalized and the rest of the words are in lower case.

    Args:
        kebab_text (str): The kebab case text to convert to title case.

    Returns:
        str: The title case text.
    """
    if kebab_text.startswith("-"):
        kebab_text = kebab_text[1:]

    kebab_text = kebab_text.replace("--", "-")

    words = kebab_text.split("-")
    title_text = " ".join(words).capitalize()
    title_text = title_text.strip()
    return title_text

list_to_string(list_to_convert)

Convert a list to a string

Take a list of strings and convert it to a string.

Parameters:

Name Type Description Default
list_to_convert list[str]

The list to convert to a string.

required

Returns:

Name Type Description
str str

String of the list items.

Source code in app/dcsp/app/functions/text_manipulation.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def list_to_string(list_to_convert: list[str]) -> str:
    """Convert a list to a string

    Take a list of strings and convert it to a string.

    Args:
        list_to_convert (list[str]): The list to convert to a string.

    Returns:
        str: String of the list items.
    """
    if len(list_to_convert) == 0:
        return ""
    elif len(list_to_convert) == 1:
        return list_to_convert[0]
    else:
        return ", ".join(list_to_convert[:-1]) + " and " + list_to_convert[-1]

snake_to_sentense(snake_text)

Convert snake case text to title case text.

Convert snake case text to title case text. The first letter of the first word is capitalized and the rest of the words are in lower case.

Parameters:

Name Type Description Default
snake_text str

The snake case text to convert to title case.

required

Returns:

Name Type Description
str str

The title case text.

Source code in app/dcsp/app/functions/text_manipulation.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def snake_to_sentense(snake_text: str) -> str:
    """Convert snake case text to title case text.

    Convert snake case text to title case text. The first letter of the first
    word is capitalized and the rest of the words are in lower case.

    Args:
        snake_text (str): The snake case text to convert to title case.

    Returns:
        str: The title case text.
    """
    if snake_text.startswith("_"):
        snake_text = snake_text[1:]

    snake_text = snake_text.replace("__", "_")
    words = snake_text.split("_")
    title_text = " ".join(words).capitalize()
    title_text = title_text.strip()
    return title_text