Someone wanted to change libFoos.so to Foos so they did the (not unreasonable) x.lstrip("lib").rstrip(".so"), which looks like it does that, but completely doesn't (it returns Foo). I then change that to index slicing, in particular [:-len(extension)], but that fails in the corner case of an empty extension. These aren't unreasonable things to do, but the default Starlark operators are full of pitfalls.
Python 3.9 added string.removeprefixand string.removesuffix. I've added them to the Rust Starlark, since they are super helpful and avoid bugs. It would be great to add them to standard Starlark too.
Someone wanted to change
libFoos.sotoFoosso they did the (not unreasonable)x.lstrip("lib").rstrip(".so"), which looks like it does that, but completely doesn't (it returnsFoo). I then change that to index slicing, in particular[:-len(extension)], but that fails in the corner case of an empty extension. These aren't unreasonable things to do, but the default Starlark operators are full of pitfalls.Python 3.9 added
string.removeprefixandstring.removesuffix. I've added them to the Rust Starlark, since they are super helpful and avoid bugs. It would be great to add them to standard Starlark too.