Skip to content

text_processing

Text functions.

CLASS DESCRIPTION
AppendString

Create a callable that can append a string to the input.

FirstRegExMatch

When called, returns the first match in a string using a predefined regex.

FirstRegExMatchPosition

When called, returns the position of the first match in a string using a predefined regex.

PrefixLines

Creates a callable to prefix lines to input text.

PrefixString

Prefix a string to the input when called.

RegExCommand

A base class to hold regular expression information.

RegexSub

Create a callable that will make substitutions using regular expressions.

SetDefault

Return a default value when called with an empty value.

Slice

When called, return a slice of the sequence.

Strip

Create a callable that will strip a string from the ends of an input.

WrapParagraphs

Create a callable to wrap the paragraphs of a string.

FUNCTION DESCRIPTION
capitalize

Capitalize the first character for a string.

Attributes

Classes

AppendString dataclass

AppendString(postfix: StrOrCallable = '')

Create a callable that can append a string to the input.

METHOD DESCRIPTION
__call__

Append a string to the input_text.

ATTRIBUTE DESCRIPTION
postfix

The string to append.

TYPE: StrOrCallable

Attributes

postfix class-attribute instance-attribute
postfix: StrOrCallable = ''

The string to append.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Append a string to the input_text.

FirstRegExMatch dataclass

FirstRegExMatch(
    pattern: StrOrCallable,
    ascii_flag: bool = False,
    ignorecase_flag: bool = False,
    locale_flag: bool = False,
    multiline_flag: bool = False,
    dotall_flag: bool = False,
    verbose_flag: bool = False,
    named_subgroup: Optional[str] = None,
    default_value: StrOrCallable = "",
)

Bases: RegExCommand

When called, returns the first match in a string using a predefined regex.

METHOD DESCRIPTION
__call__

Search the input_text for the predefined pattern and return it.

ATTRIBUTE DESCRIPTION
default_value

The value to return if no match is found.

TYPE: StrOrCallable

named_subgroup

The named subgroup defined in the pattern to return.

TYPE: Optional[str]

Attributes

default_value class-attribute instance-attribute
default_value: StrOrCallable = ''

The value to return if no match is found.

named_subgroup class-attribute instance-attribute
named_subgroup: Optional[str] = None

The named subgroup defined in the pattern to return.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Search the input_text for the predefined pattern and return it.

FirstRegExMatchPosition dataclass

FirstRegExMatchPosition(
    pattern: StrOrCallable,
    ascii_flag: bool = False,
    ignorecase_flag: bool = False,
    locale_flag: bool = False,
    multiline_flag: bool = False,
    dotall_flag: bool = False,
    verbose_flag: bool = False,
)

Bases: RegExCommand

When called, returns the position of the first match in a string using a predefined regex.

METHOD DESCRIPTION
__call__

Search the input_text for the predefined pattern and return its position.

Functions

__call__
__call__(input_text: StrOrCallable) -> int

Search the input_text for the predefined pattern and return its position.

PrefixLines dataclass

PrefixLines(prefix: StrOrCallable, first_line: Optional[StrOrCallable] = None)

Creates a callable to prefix lines to input text.

METHOD DESCRIPTION
__call__

Prepend characters to the lines in input text.

ATTRIBUTE DESCRIPTION
first_line

Prefix the first line with these characters.

TYPE: Optional[StrOrCallable]

prefix

The characters to put in front of each line.

TYPE: StrOrCallable

Attributes

first_line class-attribute instance-attribute
first_line: Optional[StrOrCallable] = None

Prefix the first line with these characters.

prefix instance-attribute
prefix: StrOrCallable

The characters to put in front of each line.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Prepend characters to the lines in input text.

PrefixString dataclass

PrefixString(prefix: StrOrCallable = '')

Prefix a string to the input when called.

METHOD DESCRIPTION
__call__

Prefix input_text.

ATTRIBUTE DESCRIPTION
prefix

The string to prefix

TYPE: StrOrCallable

Attributes

prefix class-attribute instance-attribute
prefix: StrOrCallable = ''

The string to prefix

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Prefix input_text.

RegExCommand dataclass

RegExCommand(
    pattern: StrOrCallable,
    ascii_flag: bool = False,
    ignorecase_flag: bool = False,
    locale_flag: bool = False,
    multiline_flag: bool = False,
    dotall_flag: bool = False,
    verbose_flag: bool = False,
)

A base class to hold regular expression information.

ATTRIBUTE DESCRIPTION
flags

The combined RegexFlags.

TYPE: RegexFlag

pattern

The regular expression to match against.

TYPE: StrOrCallable

Attributes

flags property
flags: RegexFlag

The combined RegexFlags.

pattern instance-attribute
pattern: StrOrCallable

The regular expression to match against.

RegexSub dataclass

RegexSub(
    pattern: StrOrCallable,
    ascii_flag: bool = False,
    ignorecase_flag: bool = False,
    locale_flag: bool = False,
    multiline_flag: bool = False,
    dotall_flag: bool = False,
    verbose_flag: bool = False,
    replacement: StrOrCallable = "",
)

Bases: RegExCommand

Create a callable that will make substitutions using regular expressions.

METHOD DESCRIPTION
__call__

Do the substitution on the input_text.

ATTRIBUTE DESCRIPTION
replacement

The replacement string for matches.

TYPE: StrOrCallable

Attributes

replacement class-attribute instance-attribute
replacement: StrOrCallable = ''

The replacement string for matches.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Do the substitution on the input_text.

SetDefault dataclass

SetDefault(default: StrOrCallable = '')

Return a default value when called with an empty value.

METHOD DESCRIPTION
__call__

Return a default value when called with an empty value.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Return a default value when called with an empty value.

Slice dataclass

Slice(
    start: Optional[IntOrCallable] = None,
    stop: Optional[IntOrCallable] = None,
    step: Optional[IntOrCallable] = None,
)

When called, return a slice of the sequence.

METHOD DESCRIPTION
__call__

Slice the sequence.

ATTRIBUTE DESCRIPTION
start

The start of the slice. None means the beginning of the sequence.

TYPE: Optional[IntOrCallable]

step

Slice using this step betweeen indices. None means don’t use the step.

TYPE: Optional[IntOrCallable]

stop

The end of the slice. None means the end of the sequence.

TYPE: Optional[IntOrCallable]

Attributes

start class-attribute instance-attribute
start: Optional[IntOrCallable] = None

The start of the slice. None means the beginning of the sequence.

step class-attribute instance-attribute
step: Optional[IntOrCallable] = None

Slice using this step betweeen indices. None means don’t use the step.

stop class-attribute instance-attribute
stop: Optional[IntOrCallable] = None

The end of the slice. None means the end of the sequence.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Slice the sequence.

Strip dataclass

Strip(chars: StrOrCallable = ' ')

Create a callable that will strip a string from the ends of an input.

METHOD DESCRIPTION
__call__

Strip characters from the ends of the input.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Strip characters from the ends of the input.

WrapParagraphs dataclass

WrapParagraphs(
    paragraph_pattern: StrOrCallable = "\n\n",
    paragraph_join: StrOrCallable = "\n\n",
    width: int = 88,
)

Create a callable to wrap the paragraphs of a string.

METHOD DESCRIPTION
__call__

Wrap each paragraph of the input text.

ATTRIBUTE DESCRIPTION
paragraph_join

Join the wrapped paragraphs with this string.

TYPE: StrOrCallable

paragraph_pattern

Pattern to detect paragraphs.

TYPE: StrOrCallable

width

The maximum width of each line of the paragraph.

TYPE: int

Attributes

paragraph_join class-attribute instance-attribute
paragraph_join: StrOrCallable = '\n\n'

Join the wrapped paragraphs with this string.

paragraph_pattern class-attribute instance-attribute
paragraph_pattern: StrOrCallable = '\n\n'

Pattern to detect paragraphs.

width class-attribute instance-attribute
width: int = 88

The maximum width of each line of the paragraph.

Functions

__call__
__call__(input_text: StrOrCallable) -> str

Wrap each paragraph of the input text.

Functions

capitalize

capitalize(msg: str) -> str

Capitalize the first character for a string.

PARAMETER DESCRIPTION
msg

The string to capitalize

TYPE: str

RETURNS DESCRIPTION
str

The capitalized string