The string_escaping.py module#

Summary#

escape_string

Escape a string according to ModelCenter conventions.

unescape_string

Unescape a string according to ModelCenter conventions.

Description#

Provides functions for ModelCenter-standard string escaping.

Module detail#

string_escaping.escape_string(unescaped: str) str#

Escape a string according to ModelCenter conventions.

The following characters are escaped: backslash, newline, carriage return, tab, double-quote, and null. Backslash is itself used as an escape character.

Parameters:
unescapedstr

Unescaped string.

Returns:
str

String with the specified characters escaped.

string_escaping.unescape_string(escaped: str) str#

Unescape a string according to ModelCenter conventions.

The escape sequences \n, \r, \t, and \0 are transformed into newline, carriage return, tab, and null respectively. In other cases where a backslash appears, it is simply removed and the following character is allowed to remain. (Note that this also results in the correct behavior for double-quotatoin marks and the backslash itself, even though those characters are escaped by the escape_string() method.)

Parameters:
escapedstr

String with the escape sequences.

Returns:
str

String with the escape sequences undone.