String Helpers¶
- 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_'
- Return type:
- Returns:
str – The string with any applicable characters escaped appropriately.
- 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('nya {nya} [nya] \nya') '{nya \{nya\} [nya] \\nya}'
- Return type:
- Returns:
str – The string with any applicable characters escaped appropriately.
- 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'"'
- Return type:
- Returns:
str – The string with any applicable characters escaped appropriately.
- 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 withX
’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'
- Return type:
- Returns:
str – The name of the environment variable used to look for for tool overrides.