On 25Mar2020 08:14, Paul Moore email@example.com wrote:
[...] The issue for me is how the function should behave with a list of affixes if one is a prefix of another, e.g.,removeprefix(('Test', 'Tests')). The empty string case is just one form of that. The behaviour should be defined clearly, and while I imagine "always remove the longest" is the "obvious" sensible choice, I am fairly certain there will be other opinions :-) So deferring the decision for now until we have more experience with the single-affix form seems perfectly reasonable.
I'd like to preface this with "I'm fine to implement multiple affixes later, if at all". That said:
To me "first match" is the _only_ sensible choice. "longest match" can always be implemented with a "first match" function by sorting on length if desired.
Also, "longest first" requires the implementation to do a prescan of the supplied affixes whereas "first match" lets the implementation just iterate over the choices as supplied.
I'm beginning to think I must again threaten my partner's anecdote about Netscape Proxy's rule system, which prioritised rules by the lexical length of their regexp, not their config file order of appearance. That way lies (and, indeeed, lay) madness.
Cheers, Cameron Simpson firstname.lastname@example.org