Commit Graph

7 Commits

Author SHA1 Message Date
Brant Watson f7e1cb8111 Improve arguments & add shortcut function
- Escape strings using re.escape unless regex flag
  is set
- Added shortcut function multi_replace
- New unittests
2018-07-10 09:47:57 -07:00
Brant Watson 0336273acf Add MultiSub tool for single pass substitutions
MultiSub leverages regular expressions and the sub
module to perform a series of multiple replacements
in a string in a single pass.

For example:

long_string = long_string.replace('foo', 'bar')
long_string = long_string.replace('baz', 'fizz')
long_string = long_string.replace('bang', 'lame')

.... and so on - can get tedious and requires multiple
passes over the same string value.

The multisub equivilant would be:

m = MultiSub({
    'foo': 'bar',
    'baz': 'fizz',
    'bang': 'lame',
)
long_string = m.sub(long_string)

The longer the string in question the more of a
performance increase you'll see relative to a series
of calls to .replace
2018-07-10 09:47:57 -07:00
Adam Gibson f79f0288c8 Rename range2list() & list2range() functions to parse_int_list() & format_int_list(). 2016-05-23 16:11:50 +08:00
Adam Gibson c669103ccb Added range2list() and list2range() functions to strutils.py - added applicable tests to test_strutils.py 2016-05-23 13:42:17 +08:00
Kevin Deldycke 0b797d14a6 Add is_uuid unit-tests, including garbage types. 2016-03-02 11:35:28 +01:00
Mahmoud Hashemi 495d5c2e96 adding strutils.indent 2016-01-24 00:47:01 -08:00
Mahmoud Hashemi 9007b6bd94 super basic strutils tests 2015-05-19 23:18:38 -07:00