import re


def fixName(name):
    """
    Map MySQL field names to PV suffixes.

    Parameters
    ----------
    name : str
        A MySQL field.  It is assumed that this is begins either "FLD_"
        (if this should be a field of the base PV) or "PV_" (if this is
        an extension of the base PV).

    Returns
    -------
    suffix : str
        A suffix to be appended to the base PV name.  "FLD_" will be replaced
        with ".", and "PV_" will be replaced with ":".  Single "_" in the name
        will become ":" and double "_" will become single "_".
    """
    name = re.sub("::", "_", re.sub("_", ":", name))
    if name[:3] == "PV:":
        return name[2:]
    else:
        c = name.rindex(':')
        return name[3:c] + '.' + name[c+1:]