Making regex replace CTFE by removing malloc
Pierre Krafft via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 2 10:14:24 PDT 2015
We have CTFE regex wich creates an optimized regex engine at
compile time. I would want to expand on that and make the
generated machine CTFE as well. I think the only thing that is
stopping this from working is the use of malloc as seen at
https://github.com/D-Programming-Language/phobos/blob/cb044b02aa3abd0bddc5e48a91faebfd146cab3e/std/regex/package.d#L565
What can replace malloc that can run on compile time and won't
make it slower at run time?
Here is an example of what I would want to work:
unittest {
enum hello_world = camelCaseToUnderscore("helloWorld");
assertEqual(hello_world, "hello_world");
}
private string camelCaseToUnderscore(string input){
import std.regex;
auto ctr = ctRegex!(`([a-z])([A-Z])`);
auto replaceString = "$1_$2";
return replaceAll(input, ctr, replaceString).toLower();
}
More information about the Digitalmars-d
mailing list