Skip to content

Feature: Translate string from a set of runes to another #21

@huandu

Description

@huandu

See String#tr in ruby.

Function signature will be func Translate(str, from, to string) string. In this function, from and to are a pattern defined as following.

  • Special characters:
    • - means a range of runes, e.g. "a-z" means all characters from 'a' to 'z' inclusive.
    • ^ as first character means a set of all runes excepted listed, e.g. "^a-z" means all characters except 'a' to 'z' inclusive.
    • \ escapes special characters.
  • Normal character represents itself, e.g. "abc" is a set including 'a', 'b' and 'c'.

Translate will try to find a 1:1 mapping from from to to. If to is smaller than from, last rune in to will be used to map "out of range" characters.

There should be a set of functions to "compile" translate from and to string to a rune set for better performance.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions