Skip to main content

smart_split

Generator that splits a string by spaces, leaving quoted phrases together. Supports both single and double quotes, and supports escaping quotes with backslashes. In the output, strings will keep their initial and trailing quote marks and escaped quotes will remain escaped (the results can then be further processed with unescape_string_literal()).

def smart_split(
text: str
) - > Generator[str, None, None]

Generator that splits a string by spaces, leaving quoted phrases together. Supports both single and double quotes, and supports escaping quotes with backslashes. In the output, strings will keep their initial and trailing quote marks and escaped quotes will remain escaped (the results can then be further processed with unescape_string_literal()).

Parameters

NameTypeDescription
textstrThe input string to be partitioned into space-separated tokens and quoted phrases.

Returns

TypeDescription
Generator[str, None, None]A generator yielding individual string segments, where quoted phrases are preserved as single units.