On 2020-05-02 22:33:59 +0000, Harry Gillanders said:

This depends on what you classify as drawable, and what you consider to be a character (the joys of Unicode),

Absolutely... however, trying getting close to what works in most cases.

and why you want to search for them anyway.

I'm doing some cursor-movement in a text-field. So, need to find out where the cursor should be positioned.

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).

Yes, that makes sense. I wasn't aware about graphical category... so would have used the !isWhite approach only. Thanks.

Which could look like so:

        import std.algorithm;
        import std.range;
        import std.uni;

        size_t drawableCharacterCount (CodePoints) (auto ref CodePoints 
codePoints)

What does this line do?

        if (isInputRange!CodePoints && is(ElementType!CodePoints : dchar))
        {
                bool isDrawableCodePoint (dchar c)
                {
                        return c.isGraphical() && !c.isWhite();
                }

                return codePoints.byGrapheme().count!(
                        g => g[].any!isDrawableCodePoint
                );
        }

I want to identify spans of drawable and isWhite in a grapheme array. So, I think any! just gives the total count of the whole thing. But anyway, thanks for the input, helps to better understand the whole thing.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to