Skip to content

Add removeprefix/removesuffix to string #185

@ndmitchell

Description

@ndmitchell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions