Skip to content

Latest commit

 

History

History
174 lines (92 loc) · 4.51 KB

velocitas_lib.text_utils.md

File metadata and controls

174 lines (92 loc) · 4.51 KB

module velocitas_lib.text_utils


function to_camel_case

to_camel_case(snake_str: str) → str

Return a camel case version of a snake case string.

Args:

  • snake_str (str): A snake case string.

Returns:

  • str: A camel case version of a snake case string.

function create_truncated_string

create_truncated_string(input: str, length: int) → str

Create a truncated version of input if it is longer than length. Will keep the rightmost characters and cut of the front if it is longer than allowed.

Args:

  • input (str): The input string.
  • length (int): The allowed overall length.

Returns:

  • str: A truncated string which has len() of length.

function replace_text_in_file

replace_text_in_file(file_path: str, text: str, replacement: str) → None

Replace all occurrences of text in a file with a replacement.

Args:

  • file_path (str): The path to the file.
  • text (str): The text to find.
  • replacement (str): The replacement for text.

function replace_item_in_list

replace_item_in_list(
    text: List[str],
    matching_text: str,
    replacement: str = '',
    remove_empty: bool = False
) → List[str]

Replace the whole line which matches the given text with a replacement.

Args:

  • text (List[str]): All text lines to replace lines within.
  • text (str): The text to find the line with.
  • replacement (str): The replacement for line.
  • remove_empty (bool): If true and the replacement for a line is empty, the line will be removed.

function replace_text_area

replace_text_area(
    text: List[str],
    start_occurence: str,
    end_occurence: str,
    replacement: str = ''
) → List[str]

Replace all occurrences of all text areas matching the parameters with a replacement. If the replacement for a line is empty, then the line will be removed.

Args:

  • text (List[str]): All text lines to replace text within.
  • start_occurence (str): The starting line which matches the occurence for replacement text area.
  • start_occurence (str): The ending line which matches the occurence for replacement text area.
  • replacement (str): The replacement for text area.

function capture_area_in_file

capture_area_in_file(
    file: TextIOWrapper,
    start_line: str,
    end_line: str,
    map_fn: Optional[Callable[[str], str]] = None
) → List[str]

Capture an area of a textfile between a matching start line (exclusive) and the first line matching end_line (exclusive).

Args:

  • file (TextIOWrapper): The text file to read from.
  • start_line (str): The line which triggers the capture (will not be part of the output)
  • end_line (str): The line which terminates the capture (will not be bart of the output)
  • map_fn (Optional[Callable[[str], str]], optional): An optional mapping function to transform captured lines. Defaults to None.

Returns:

  • List[str]: A list of captured lines.

This file was automatically generated via lazydocs.