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:
|
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:
|
named_subgroup |
The named subgroup defined in the pattern to return. |
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
¶
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:
|
prefix |
The characters to put in front of each line.
TYPE:
|
Attributes¶
first_line
class-attribute
instance-attribute
¶
first_line: Optional[StrOrCallable] = None
Prefix the first line with these characters.
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:
|
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:
|
pattern |
The regular expression to match against.
TYPE:
|
Attributes¶
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:
|
Attributes¶
replacement
class-attribute
instance-attribute
¶
replacement: StrOrCallable = ''
The replacement string for matches.
Functions¶
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:
|
step |
Slice using this step betweeen indices. None means don’t use the step.
TYPE:
|
stop |
The end of the slice. None means the end of the sequence.
TYPE:
|
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¶
Strip
dataclass
¶
Strip(chars: StrOrCallable = ' ')
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:
|
paragraph_pattern |
Pattern to detect paragraphs.
TYPE:
|
width |
The maximum width of each line of the paragraph.
TYPE:
|
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.