byCodePoint for a range of chars

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 20 11:06:09 PDT 2014


On Tue, 20 May 2014 17:59:07 +0000, John Colvin wrote:

> Given a range with element type char, what's the best way of iterating
> over it by code-point, without filling an array first?
> 
> Related to this: What's the status of std.utf and std.encoding? The
> comments in std.encoding say that some functions supersede their std.utf
> counterparts.

Foreach on narrow strings automatically decodes, so it's as simple as:

// assume UTF-8 encoded
char[] myData = ...
foreach (dchar codePoint; myData)
   ...


More information about the Digitalmars-d-learn mailing list