Problem 1:

I'm trying to get a string to behave as a .byGrapheme range by default, but I can't figure out Grapheme. I'm trying to replicate this behavior:

foreach (g; "hello".byGrapheme) {
    write(g[]);
}

In a custom type:

struct ustring {
    string data;
    this(string data) {
        this.data = data;
    }
    auto get() {
        static struct Range {
            typeof(string.init.byGrapheme) source;
            bool empty() { return source.empty; }
            void popFront() { source.popFront; }
            auto front() { return source.front[]; }
            auto save() { return this; };
        }
        return Range(this.data.byGrapheme);
    }
    alias get this;
}

But I keep on ending up with a UTFException: "Encoding an invalid code point in UTF-8" with code like:

writeln("hello".ustring);

Problem 2:

How can I get the aliased ustring type to behave as a ForwardRange? If I add the save method to the voldermort range type, the isForwardRange!ustring fails because the requirement on isForwardRange checks to see if save returns the same type it's called on. Which is not the case here since typeof(ustring.save) == ustring.get.Range). But nontheless does have a save method.

Cheers,
- Ali

Reply via email to