Skip to content

proposal: strings: add new functions to deprecate strings.{Trim/TrimRight/TrimLeft} to avoid mistakes #50399

@hitzhangjie

Description

@hitzhangjie

Hi, could we add new methods to solve the problem of cutset type in Strings.{Trim/TrimRight/TrimLeft}.

Apparently, many gohpers misunderstood the this cutset type, and it cauese some bugs. And, there're several proposals for solving the cutset type problem:

I read through this proposals and see the conclusion is no change will be made.

This cutset problem affects many developers:

  • if we have known the problem already, we may not make the same mistake again.
  • but if we doesn't know it in advance, we may likely make the mistake.

In python, str.{strip/rstrip/lstrip}('cutset') method works the same as in go strings.{Trim/TrimRight/TrimLeft}(s, "cutset"). Maybe this signature is ok.

If we:

  • add new methods strings.{TrimCutset\TrimRightCutset\TrimLeftCutset}, and add //Deprecated and go:linkname on strings.{Trim/TrimRight/TrimLeft}, we may make this clearer
  • or add new methods strings.{TrimCutset\TrimRightCutset\TrimLeftCutset}, and declare the cutset as []rune, and use this methods to reimplement strings.{Trim/TrimRight/TrimLeft}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Hold

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions