nexB/license-expression

Add replace method to LicenseExpression

Closed this issue · 5 comments

I would like to replace a expression and by another expression in a given expression.
The semantics should be the same as the string.replace stdlib function eg:

string.replace(s, old, new[, maxreplace])

    Return a copy of string s with all occurrences of substring old replaced by new. 
    If the optional argument maxreplace is given, the first maxreplace occurrences are replaced.

e.g. the function should apply to all exact sub expressions matching old in the expression tree and should not be recursive like in string.replace:

>>> 'foobarbar'.replace('foobar', 'foo')
'foobar'

The maxreplace is not needed.

The subs method in bastikr/boolean.py#66 is all we need and this is already there.
I am adding some tests to verify that this works as expected.

@pombredanne I think this has been fixed, so can we close this ? Please correct me if I am wrong. :)

@yash-nisar good catch. Thanks! closing.