'Automatically decode ``data`` into a ``unicode`` object.
:param normalize_to_nfc: Normalize returned unicode to the NFC normal form as is required by both the EPUB and AZW3 formats.'

def decode(self, data, normalize_to_nfc=True):

    def fix_data(d):
        return d.replace(u'\r\n', u'\n').replace(u'\r', u'\n')
    if isinstance(data, unicode):
        return fix_data(data)
    bom_enc = None
    if (data[:4] in {'\x00\x00\xfe\xff', '\xff\xfe\x00\x00'}):
        bom_enc = {'\x00\x00\xfe\xff': u'utf-32-be', '\xff\xfe\x00\x00': u'utf-32-le'}[data[:4]]
        data = data[4:]
    elif (data[:2] in {'\xff\xfe', '\xfe\xff'}):
        bom_enc = {'\xff\xfe': u'utf-16-le', '\xfe\xff': u'utf-16-be'}[data[:2]]
        data = data[2:]
    elif (data[:3] == '\xef\xbb\xbf'):
        bom_enc = u'utf-8'
        data = data[3:]
    if (bom_enc is not None):
        try:
            self.used_encoding = bom_enc
            return fix_data(data.decode(bom_enc))
        except UnicodeDecodeError:
            pass
    try:
        self.used_encoding = u'utf-8'
        return fix_data(data.decode(u'utf-8'))
    except UnicodeDecodeError:
        pass
    (data, self.used_encoding) = xml_to_unicode(data)
    if normalize_to_nfc:
        data = unicodedata.normalize(u'NFC', data)
    return fix_data(data)
