View source code
Display the source code in std/uni.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
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.
string toSourceCode
(
string funcName = ""
);
The function generated tests if the code point 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.
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
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.