def encode(self, word, max_length=-<NUM_LIT:1>, keep_vowels=False, vowel_char='<STR_LIT:*>'):
<EOL>word = unicode_normalize('<STR_LIT>', text_type(word.upper()))<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = '<STR_LIT>'.join(c for c in word if c in self._uc_set)<EOL>if word[:<NUM_LIT:3>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>word = '<STR_LIT>' + word[<NUM_LIT:3>:]<EOL><DEDENT>elif word[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>word = '<STR_LIT>' + word[<NUM_LIT:2>:]<EOL><DEDENT>pos = len(word) - <NUM_LIT:2><EOL>while pos > -<NUM_LIT:1>:<EOL><INDENT>if word[pos : pos + <NUM_LIT:2>] in {<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>}:<EOL><INDENT>word = word[: pos + <NUM_LIT:1>] + word[pos + <NUM_LIT:2> :]<EOL>pos += <NUM_LIT:1><EOL><DEDENT>pos -= <NUM_LIT:1><EOL><DEDENT>word = word.replace('<STR_LIT:X>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>pos = word.find('<STR_LIT>', <NUM_LIT:1>)<EOL>while pos != -<NUM_LIT:1>:<EOL><INDENT>if word[pos - <NUM_LIT:1> : pos] not in self._uc_vy_set:<EOL><INDENT>word = word[:pos] + '<STR_LIT:S>' + word[pos + <NUM_LIT:1> :]<EOL><DEDENT>pos = word.find('<STR_LIT>', pos + <NUM_LIT:1>)<EOL><DEDENT>word = word.replace('<STR_LIT:C>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:S>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:R>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>word = word.replace('<STR_LIT:T>', '<STR_LIT:D>')<EOL>word = word.replace('<STR_LIT>', '<STR_LIT:F>')<EOL>pos = word.find('<STR_LIT>', <NUM_LIT:0>)<EOL>while pos != -<NUM_LIT:1>:<EOL><INDENT>if pos > <NUM_LIT:1> and word[pos - <NUM_LIT:1> : pos] not in self._uc_vy_set | {<EOL>'<STR_LIT:L>',<EOL>'<STR_LIT:N>',<EOL>'<STR_LIT:R>',<EOL>}:<EOL><INDENT>word = word[: pos - <NUM_LIT:1>] + word[pos:]<EOL>pos -= <NUM_LIT:1><EOL><DEDENT>pos = word.find('<STR_LIT>', pos + <NUM_LIT:1>)<EOL><DEDENT>if max_length > <NUM_LIT:0> and word[-<NUM_LIT:1>:] == '<STR_LIT:E>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>word = self._delete_consecutive_repeats(word)<EOL>if word[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>word = word[<NUM_LIT:1>:]<EOL><DEDENT>if word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>word = word[:-<NUM_LIT:1>]<EOL><DEDENT>elif word[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>if word[-<NUM_LIT:3>:-<NUM_LIT:2>] in self._uc_vy_set:<EOL><INDENT>word = word[:-<NUM_LIT:2>] + '<STR_LIT:F>'<EOL><DEDENT>else:<EOL><INDENT>word = word[:-<NUM_LIT:2>] + '<STR_LIT>'<EOL><DEDENT><DEDENT>word = word.replace('<STR_LIT>', '<STR_LIT>')<EOL>if max_length > <NUM_LIT:0>:<EOL><INDENT>word = word.replace('<STR_LIT>', '<STR_LIT:F>')<EOL><DEDENT>first = <NUM_LIT:1> + (<NUM_LIT:1> if max_length > <NUM_LIT:0> else <NUM_LIT:0>)<EOL>code = '<STR_LIT>'<EOL>for pos, char in enumerate(word):<EOL><INDENT>if char in self._uc_vy_set:<EOL><INDENT>if first or keep_vowels:<EOL><INDENT>code += vowel_char<EOL>first -= <NUM_LIT:1><EOL><DEDENT><DEDENT>elif pos > <NUM_LIT:0> and char in {'<STR_LIT>', '<STR_LIT:H>'}:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>code += char<EOL><DEDENT><DEDENT>if max_length > <NUM_LIT:0>:<EOL><INDENT>if len(code) > max_length and code[-<NUM_LIT:1>:] == '<STR_LIT:S>':<EOL><INDENT>code = code[:-<NUM_LIT:1>]<EOL><DEDENT>if keep_vowels:<EOL><INDENT>code = code[:max_length]<EOL><DEDENT>else:<EOL><INDENT>code = code[: max_length + <NUM_LIT:2>]<EOL>while len(code) > max_length:<EOL><INDENT>vowels = len(code) - max_length<EOL>excess = vowels - <NUM_LIT:1><EOL>word = code<EOL>code = '<STR_LIT>'<EOL>for char in word:<EOL><INDENT>if char == vowel_char:<EOL><INDENT>if vowels:<EOL><INDENT>code += char<EOL>vowels -= <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>code += char<EOL><DEDENT><DEDENT>code = code[: max_length + excess]<EOL><DEDENT><DEDENT>code += '<STR_LIT:U+0020>' * (max_length - len(code))<EOL><DEDENT>return code<EOL>
r"""Return the Dolby Code of a name.

        Parameters
        ----------
        word : str
            The word to transform
        max_length : int
            Maximum length of the returned Dolby code -- this also activates
            the fixed-length code mode if it is greater than 0
        keep_vowels : bool
            If True, retains all vowel markers
        vowel_char : str
            The vowel marker character (default to \*)

        Returns
        -------
        str
            The Dolby Code

        Examples
        --------
        >>> pe = Dolby()
        >>> pe.encode('Hansen')
        'H*NSN'
        >>> pe.encode('Larsen')
        'L*RSN'
        >>> pe.encode('Aagaard')
        '*GR'
        >>> pe.encode('Braaten')
        'BR*DN'
        >>> pe.encode('Sandvik')
        'S*NVK'
        >>> pe.encode('Hansen', max_length=6)
        'H*NS*N'
        >>> pe.encode('Larsen', max_length=6)
        'L*RS*N'
        >>> pe.encode('Aagaard', max_length=6)
        '*G*R  '
        >>> pe.encode('Braaten', max_length=6)
        'BR*D*N'
        >>> pe.encode('Sandvik', max_length=6)
        'S*NF*K'

        >>> pe.encode('Smith')
        'SM*D'
        >>> pe.encode('Waters')
        'W*DRS'
        >>> pe.encode('James')
        'J*MS'
        >>> pe.encode('Schmidt')
        'SM*D'
        >>> pe.encode('Ashcroft')
        '*SKRFD'
        >>> pe.encode('Smith', max_length=6)
        'SM*D  '
        >>> pe.encode('Waters', max_length=6)
        'W*D*RS'
        >>> pe.encode('James', max_length=6)
        'J*M*S '
        >>> pe.encode('Schmidt', max_length=6)
        'SM*D  '
        >>> pe.encode('Ashcroft', max_length=6)
        '*SKRFD'