camel_tools.utils.stringutils

This submodule contains a collection of useful helper functions when working with strings.

Functions

camel_tools.utils.stringutils.isunicode(obj)

Checks if an object is a Unicode encoded string. Useful for Python 2 and 3 compatibility.

Parameters:obj (object) – The object to check.
Returns:True if obj is a Unicode encoded string, False otherwise.
Return type:bool
camel_tools.utils.stringutils.force_unicode(s, encoding='utf-8')

Convert a given string into a Unicode (decoded) string if it isn’t already.

Parameters:
  • s (str) – String object to convert.
  • encoding (str, optional) – The encoding of s if it is encoded. Defaults to ‘utf-8’.
Returns:

A Unicode (decoded) version of s.

Return type:

str

camel_tools.utils.stringutils.force_encoding(s, encoding='utf-8')

Convert a given string into an encoded string if it isn’t already.

Parameters:
  • s (str) – String object to convert.
  • encoding (str) – The encoding s should be encoded into. Note that if s is already encoded, it is returned as is, even though it is in a differnet encoding than what is passed to this parameter. Defaults to ‘utf-8’.
Returns:

An encoded version of s.

Return type:

str