Error in trying to use an inout(char)[] with a regex

Shriramana Sharma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 16 19:56:26 PDT 2015


Ali Çehreli wrote:

> Meanwhile, can you try the following template which works at least for
> the reduced code:
> 
> import std.range;
> 
> auto foo(S)(S text)
> if (isSomeString!S) {
> import std.regex;
> static auto inlineRE = ctRegex!`\$\(ta (.*?)\)`;
> return text.replaceAll!(m => textAttr(m[1]))(inlineRE);
> }

Well I didn't think isSomeString was appropriate since it also allows 
wstring-s and dstring-s which I'm not sure my other functions with work well 
with, but the following worked nicely for me: thank you!

auto applyTextAttr(T)(T text) if (is(T: const(char)[]))
{
    import std.regex;
    static auto inlineRE = ctRegex!`\$\(ta (.*?)\)`;
    return text.replaceAll!(m => textAttr(m[1]))(inlineRE);
}

-- 
Shriramana Sharma, Penguin #395953


More information about the Digitalmars-d-learn mailing list