import re


def clean_tag(tag, allow_none=False, mytype='string', default=None, max_len=254):
    """ Clean the given `tag` instance depending of its `mytype`."""
    if default is None and allow_none is False:
        if mytype == 'string':
            default = 'unknown'
        elif mytype == 'integer':
            default = 0
        elif mytype == 'float':
            default = 0.0

    if tag is None or tag == 'None':
        return default if allow_none is False else None

    if mytype == 'string':
        try:
            tag = str(tag).strip()
        except UnicodeDecodeError:
            tag = tag.strip()
    else:
        tag = str(tag)
    if tag == '':
        return default
    elif mytype == 'integer' and re.match(r'\d{1,32}', str(tag)) is None:
        return default
    elif mytype == 'float':
        try:
            return float(tag)
        except ValueError:
            return default
    return tag[:max_len].strip()