import re


def _cleanup_text(text):
    """Cleans up the text before formatting to camel, pascal or snake case.

    Removes dashes, underscores, single quotes (apostrophes) and replaces
    them with a space character. Multiple spaces, tabs or new line characters
    are collapsed to one space character.
    Returns the result as a string.

    """
    prefixChars = ""
    suffixChars = ""
    if text.startswith("-"):
        prefixChars += "-"
    if text.startswith("_"):
        prefixChars += "_"
    if text.endswith("-"):
        suffixChars += "-"
    if text.endswith("_"):
        suffixChars += "_"
    text = text.strip()
    text = text.replace('-', ' ')
    text = text.replace('_', ' ')
    text = text.replace("'", ' ')
    text = re.sub('[ \t\r\n]+', ' ', text)  # Any whitespaces to one space.
    text = prefixChars + text + suffixChars
    return text