Bug 9702 – std.string.replace for single chars too?

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-12T10:53:25Z
Last change time
2018-11-15T07:20:38Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-03-12T10:53:25Z
The first form is accepted but the second form is rejected: import std.string: replace; void main() { auto s1 = "hello".replace("h", "a"); // OK auto s2 = "hello".replace('h', 'a'); // error } DMD 2.063alpha gives: temp.d(4): Error: no overload matches for replace(E, R1, R2)(E[] subject, R1 from, R2 to) if (isDynamicArray!(E[]) && isForwardRange!(R1) && isForwardRange!(R2) && (hasLength!(R2) || isSomeString!(R2))) Maybe it's worth supporting the second form too. The advantage is possibly a little more efficient algorithm, and more flexibility.
Comment #1 by greensunny12 — 2017-07-11T18:20:31Z
You might like https://github.com/dlang/phobos/pull/5596 - it's "replace on steroids" (lazy, support for replacing subranges, Compile-Time overloads).
Comment #2 by greensunny12 — 2018-02-09T12:58:54Z
1) replace comes from std.array 2) This would be fixed by https://github.com/dlang/phobos/pull/6022
Comment #3 by github-bugzilla — 2018-11-15T07:20:34Z
Commit pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/bf5dc02f1a898e5283bbd8edfc60b03887f1f47c Fix Issue 9702, 10930 - std.array.replace cannot simple replace an element in array