Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ascii: new internal package consolidating common functions #68736

Open
apocelipes opened this issue Aug 5, 2024 · 3 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@apocelipes
Copy link
Contributor

Proposal Details

The standard packages write their own ASCII helper functions many times, for examples you can find ASCII-only isSpace, toUpper and equalFold in "encoding/json", "net", "internal/filepathlite". The "net/http" also has a internal package called net/http/internal/ascii.

Handling ASCII-encoded characters is a common requirement in the standard library, so a new package can share these logic and eliminate duplicate codes.

Based on my investigation of the standard library code, the new package should have these functions in it:

  • Is/IsString (check if it is ASCII)
  • IsLower/IsUpper
  • ToLower/ToUpper (for single char)
  • ToLowerString/ToUpperString
  • EqualFold
  • IsSpace
  • TrimSpace
  • IsDigit
  • IsLetter
  • IsPrint

This package should minimize external dependencies, and some necessary constants can be copied from packages such as "unicode".

Normal users can continue to use "bytes", "strings" and "unicode" for most tasks, so there is little point in making this package public. However, many standard packages can't directly import packages like "unicode", "strings", etc., so I thought it would be appropriate to put this new package in "internal".

@gopherbot gopherbot added this to the Proposal milestone Aug 5, 2024
@ianlancetaylor
Copy link
Contributor

Thanks. The proposal process is for externally visible changes, and this is a purely internal reorganization, so taking this out of the proposal process.

@ianlancetaylor ianlancetaylor changed the title proposal: new internal package internal/asciilite internal/asciilite: new internal package consolidating common functions Aug 5, 2024
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Proposal labels Aug 5, 2024
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Backlog Aug 5, 2024
@ianlancetaylor
Copy link
Contributor

The "lite" convention is for internal versions of packages that have a public API. So asciilite isn't the right name, since there is no ascii package. On the other hand, this could be internal/ascii.

@apocelipes apocelipes changed the title internal/asciilite: new internal package consolidating common functions internal/ascii: new internal package consolidating common functions Aug 6, 2024
@apocelipes
Copy link
Contributor Author

The "lite" convention is for internal versions of packages that have a public API. So asciilite isn't the right name, since there is no ascii package. On the other hand, this could be internal/ascii.

Yes. internal/ascii is a suitable name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants