String Helpers

Warning

The Torii API reference is a work in progress and we are actively working on improving it, however it may be deficient or missing in places.

torii.util.string.ascii_escape(string: str) str

Apply escaping to turn any character that is not A-Za-z0-9_ into hex.

Parameters:

string (str) – The string to escape.

Example

>>> ascii_escape('Hello ニャ~!')
'Hello_20__30cb__30e3__7e__21_'
Returns:

The string with any applicable characters escaped appropriately.

Return type:

str

torii.util.string.tcl_escape(string: str) str

Apply appropriate escaping for use in TCL scripts.

Parameters:

string (str) – The string to escape.

Example

>>> tcl_escape('meow {meow} [meow] \meow')
'{meow \{meow\} [meow] \\meow}'
Returns:

The string with any applicable characters escaped appropriately.

Return type:

str

torii.util.string.tcl_quote(string: str) str

Apply appropriate quoting for use in TCL scripts.

Parameters:

string (str) – The string to escape.

Example

>>> tcl_quote('Meow "meow"')
'"Meow \"meow\""'
>>> tcl_quote("Meow 'meow'")
'"Meow 'meow'"'
Returns:

The string with any applicable characters escaped appropriately.

Return type:

str

torii.util.string.tool_env_var(name: str) str

Convert the given tool name into a normalized version for environment variables.

This generally means replacing any -‘s with _’s and any +’s with X’s and converting the entire name to uppercase.

Parameters:

name (str) – The tool/executable name.

Example

>>> tool_env_var('cat')
'CAT'
>>> tool_env_var('cat-girl')
'CAT_GIRL'
Returns:

The name of the environment variable used to look for for tool overrides.

Return type:

str