eksperimental
unread,Mar 2, 2022, 8:25:17 AM3/2/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to elixir-l...@googlegroups.com
When starting to work in this implementation was wondering what should
be the return value of
String.trim_leading("--__--abc", [" ", "-", "_"])
and I realized that it should mimic String.replace_leading/3
Therefore it should returning "abc"
Which leads me to think we should introduce String.trim_prefix/2, in
order to be consistent with String.replace_prefix/3
where the same input as above should behave like this:
iex> String.trim_prefix("--__--abc", [" ", "-", "_"])
"__--abc"
Which also makes me think that String.replace_prefix should also
behave like String.replace/3 where the second argument (match) is a
pattern, not a string (ie. a string, list of strings, or a compiled
search pattern). By introducing this last consistency change, the
implementation of the consistency changes for the other functions
mentioned above is straight-forward.
So in short this consistency proposals suggests some functions to
support t:String.pattern/0 which could be a string, a list of strings,
or a compiled search pattern.
1. `String.replace_{leading, prefix, suffix, trailing}/3` to support in
its second argument (match) t:String.pattern/0. Current
String.replace/4 supports t:String.pattern/0 | t:Regex.t/0, but for
the sake of simplifying this proposal I would leave out
Regexes out of the equation for now.
2. Introduce String.trim_{prefix, suffix}/2 which will support
t:String.pattern/0 as a its second arguments. These functions should
mimic String.replace_{prefix, suffix}/2
3. Add support for t:String.pattern/0 for String.{trim, trim_leading,
trim_trailing}/2 to support t:String.pattern/0 as its second argument.
These functions should mimic String.{replace, replace_leading,
replace_trailing}/3
Please let me know what you think.