from typing import List


def fold_string(text: str, max_length: int, sep: str = " ") -> List[str]:
    """Splits a string into lines of the given length.

    Arguments:
        text: the string to split
        length: the maximum length of the line
        sep: the separator where splitting the text is allowed

    Returns:
        list: the list of strings
    """

    ret_lines = []
    tokens: List[str] = []
    length = 0
    sep_len = len(sep)

    for token in text.split(sep):
        token_len = len(token)
        if length + token_len + sep_len > max_length:
            if tokens:
                ret_lines.append(sep.join(tokens) + sep)
                tokens = [token]
                length = token_len

            else:
                ret_lines.append(token + sep)
                tokens = []
                length = 0

        else:
            tokens.append(token)
            length += token_len + sep_len

    if tokens:
        ret_lines.append(sep.join(tokens))

    return ret_lines