'Convert a possibly multibyte string to a safely splittable format.
Uses the input_codec to try and convert the string to Unicode, so it
can be safely split on character boundaries (even for multibyte
characters).
Returns the string as-is if it isn\'t known how to convert it to
Unicode with the input_charset.
Characters that could not be converted to Unicode will be replaced
with the Unicode replacement character U+FFFD.'

def to_splittable(self, s):

    if (isinstance(s, unicode) or (self.input_codec is None)):
        return s
    else:
        try:
            return unicode(s, self.input_codec, 'replace')
        except LookupError:
            return s
        return
