countUntil with negated pre-defined predicate?
Harry Gillanders
ayjsy47yyz8 at temp.mailbox.org
Sat May 2 22:33:59 UTC 2020
On Saturday, 2 May 2020 at 18:23:30 UTC, Robert M. Münch wrote:
> Or is there an even better way to search for all "drawable
> unicode characters"?
This depends on what you classify as drawable, and what you
consider to be a character (the joys of Unicode), and why you
want to search for them anyway.
One way (I haven't verified this) could be to check if any of the
code-points within a grapheme are graphical[1], and not
white-space (and are not any other code-point you consider
non-drawable).
Which could look like so:
import std.algorithm;
import std.range;
import std.uni;
size_t drawableCharacterCount (CodePoints) (auto ref CodePoints
codePoints)
if (isInputRange!CodePoints && is(ElementType!CodePoints :
dchar))
{
bool isDrawableCodePoint (dchar c)
{
return c.isGraphical() && !c.isWhite();
}
return codePoints.byGrapheme().count!(
g => g[].any!isDrawableCodePoint
);
}
[1]:
https://www.unicode.org/versions/Unicode13.0.0/ch02.pdf#G286941
---
The source-code in this reply is available for use under the
terms of Creative Commons CC0 1.0 Universal.
More information about the Digitalmars-d-learn
mailing list