Skip to content

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

Open
@apocelipes

Description

@apocelipes

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions