On Wednesday, 22 February 2017 at 20:07:34 UTC, Ali Çehreli wrote:
One more:

bool isAscii(string s) {
    import std.string : representation;
    import std.algorithm : canFind;
    return !s.representation.canFind!(c => c >= 0x80);
}

unittest {
    assert(isAscii("hello world"));
    assert(!isAscii("hellö wörld"));
}

Ali

One more again as I couldn't believe noone went for 'any' yet:

---
import std.algorithm;
return !s.any!"a > 127"; // code-point level
---

Reply via email to