View source code Display the source code in std/uni.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.uni.InversionList.toSourceCode

Generates string with D source code of unary function with name of funcName taking a single dchar argument. If funcName is empty the code is adjusted to be a lambda function.

The function generated tests if the passed belongs to this set or not. The result is to be used with string mixin. The intended usage area is aggressive optimization via meta programming in parser generators and the like.

Prototype

string toSourceCode(
  string funcName = ""
);

Note

Use with care for relatively small or regular sets. It could end up being slower then just using multi-staged tables.

Example

import std.stdio;

// construct set directly from [a, b$RPAREN intervals
auto set = CodepointSet(10, 12, 45, 65, 100, 200);
writeln(set);
writeln(set.toSourceCode("func"));

The above outputs something along the lines of:

bool func(dchar ch)  @safe pure nothrow @nogc
{
    if(ch < 45)
    {
        if(ch == 10 || ch == 11) return true;
        return false;
    }
    else if (ch < 65) return true;
    else
    {
        if(ch < 100) return false;
        if(ch < 200) return true;
        return false;
    }
}

Authors

Dmitry Olshansky

License

Boost License 1.0.

Comments