lower case only first letter of word
kdevel
kdevel at vogtner.de
Tue Dec 5 19:41:13 UTC 2017
On Tuesday, 5 December 2017 at 17:25:57 UTC, Steven Schveighoffer
wrote:
[...]
> struct LowerCaseFirst(R) // if(isSomeString!R)
> {
> R src;
> bool notFirst; // terrible name, but I want default false
> dchar front() {
> import std.uni: toLower;
> return notFirst ? src.front : src.front.toLower;
> }
> void popFront() { notFirst = true; src.popFront; }
> bool empty() { return src.empty; }
> }
>
> auto lowerCaseFirst(R)(R r)
> {
> return LowerCaseFirst!R(r);
> }
>
> Warning: it ain't going to be fast. Auto-decoding everywhere.
But one cannot use the return value of lowerCaseFirst as argument
for foo(string). Only the use as argument to writeln seems to
work. Also I had to put
import std.range.primitives : front, popFront, empty;
outside the struct otherwise the compiler complains about missing
front, popFront and empty for type string.
More information about the Digitalmars-d-learn
mailing list