'Convert a string of kana to roomaji.'

def romanize(self, string):

    vowels = ['a', 'e', 'i', 'o', 'u', 'y']
    characters = []
    last_kana = None
    last_char = None
    for char in string:
        if (65281 <= ord(char) <= 65374):
            if (last_kana == 'sokuon'):
                raise ValueError('Sokuon    cannot    precede    Latin    characters.')
            char = chr(((ord(char) - 65281) + 33))
            characters.append(char)
            last_kana = None
        elif (char in self.roomaji_small_kana):
            combo = (last_char + char)
            if (combo in self.roomaji_small_kana_combos):
                characters[(-1)] = self.roomaji_small_kana_combos[combo]
            else:
                characters.append(self.roomaji_small_kana[char])
            last_kana = self.roomaji_small_kana[char]
        elif (char in self.roomaji_youon):
            if ((not last_kana) or (last_kana[(-1)] != 'i') or (last_kana == 'i')):
                raise ValueError('Youon    must    follow    an    -i    sound.')
            new_sound = self.roomaji_youon[char]
            if (last_kana in self.y_drop):
                new_char = (self.y_drop[last_kana] + new_sound[1:])
            else:
                new_char = (last_kana[:(-1)] + new_sound)
            characters[(-1)] = new_char
            last_kana = new_char
        elif (char in (u'\u3063', u'\u30c3')):
            last_kana = 'sokuon'
        elif (char == u'\u30fc'):
            if (last_kana[(-1)] not in vowels):
                raise ValueError(u"'\u30fc'    must    follow    by    a    vowel.")
            if (last_kana[(-1)] in self.lengthened_vowels):
                characters[(-1)] = characters[(-1)][:(-1)]
                characters.append(self.lengthened_vowels[last_kana[(-1)]])
            else:
                characters.append(last_kana[(-1)])
            last_kana = None
        elif (char in self.roomaji_kana):
            kana = self.roomaji_kana[char]
            if (last_kana == 'sokuon'):
                if (kana[0] in vowels):
                    raise ValueError('Sokuon    cannot    precede    a    vowel.')
                characters.append(kana[0])
            elif ((last_kana == 'n') and (kana[0] in vowels)):
                characters.append("'")
            if ((kana[0] in self.lengthened_vowels) and characters and (kana == characters[(-1)][(-1)])):
                kana = self.lengthened_vowels[kana[0]]
                characters[(-1)] = characters[(-1)][:(-1)]
            characters.append(kana)
            last_kana = kana
        else:
            if (last_kana == 'sokuon'):
                raise ValueError('Sokuon    must    be    followed    by    another    kana.')
            characters.append(char)
            last_kana = None
        last_char = char
    if (last_kana == 'sokuon'):
        raise ValueError('Sokuon    cannot    be    the    last    character.')
    return u''.join(characters)
