[Issue 15285] Range-ified functions for std.string
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Mar 4 05:50:01 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15285
--- Comment #4 from greenify <greeenify at gmail.com> ---
Hey I had a look at what types does functions allow:
abbrev string[]
capitalize isSomeString
isNumeric isSomeString
inPattern isSomeString
munch isSomeString
representation Char[] (char[],wchar[],dchar[])
squeeze anything - no constrains???
succ isSomeString
translate immutable char[]
outdent isSomeString
wrap isSomeString
I guess the biggest win is, if we first focus on those isSomeString functions.
So you mean we could add to isSomeString a RangeString?
```
template isRangeString(R)
{
enum bool isRangeString = is(typeof(
(inout int = 0)
{
static assert(isInputRange!R);
static assert(hasLength!R); // all the algorithms allocate a new
immutable string
static asssert(isSomeChar!(isElementType!R));
}
}
```
The only problem then would be that currently those algorithms use an
index-based for-loop
```
for (size_t i = j; i < iLen; i++)
{
immutable c = s[i];
```
can we just replace that with
```
foreach (i,immutable c;s)
```
so in summary - my questions:
1) can we replace for --> foreach or do we have to use `static if`?
2) we still will return a newly allocated immutable string. Should we return
something different for ranges?
--
More information about the Digitalmars-d-bugs
mailing list