On Sunday, 19 June 2016 at 19:03:55 UTC, Robert burner Schadek wrote:
On Sunday, 19 June 2016 at 18:51:09 UTC, Jack Stouffer wrote:
I would like to try this out on my date parsing library, but I don't see a way to generate strings of a specific format.

take a look at https://github.com/dlang/phobos/pull/2995/files#diff-1a5f159e09980950bb9931ac674cbf40R358

just create a new Gen struct that generates what you want and make it a parameter to a function. And you should be done.

Hmm, isGen is failing for some reason, and I can't tell why

struct GenDateString
{
    import std.format : formattedWrite;
    import std.random : Random, uniform;
    import std.array : appender;

    string value;

    void gen(ref Random gen)
    {
        auto app = appender!string();

        app.formattedWrite(
            "%s-%s-%s",
            uniform!("[]")(1, 3000),
            uniform!("[]")(1, 12),
            uniform!("[]")(1, 28)
        );

        this.value = app.data;
    }

    ref string opCall()
    {
        return this.value;
    }

    alias opCall this;
}

Reply via email to