-
Notifications
You must be signed in to change notification settings - Fork 71
Closed
Labels
Description
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.