1 module nxt.string_traits; 2 3 @safe pure nothrow @nogc: 4 5 /** Returns: `true` iff `x` is an ASCII (7-bit clean) set of `char`s. 6 * 7 * See_Also: `std.ascii.isASCII`. 8 * See_Also: https://forum.dlang.org/post/syaqzkpybhvdehbhffjn@forum.dlang.org 9 */ 10 bool isASCIIString(scope const(char)[] input) 11 { 12 foreach (e; cast(const(ubyte)[])input) // no decoding to `dchar` needed 13 { 14 if (e >= 0x7F) { return false; } 15 } 16 return true; 17 } 18 19 /// 20 @safe pure unittest 21 { 22 assert(``.isASCIIString); 23 assert(`_`.isASCIIString); 24 assert(`a`.isASCIIString); 25 assert(`ab`.isASCIIString); 26 assert(`abc`.isASCIIString); 27 assert(!`å`.isASCIIString); 28 assert(!`åä`.isASCIIString); 29 assert(!`åäö`.isASCIIString); 30 }