public
Created

Demangles D symbol names found in standard input.

  • Download Gist
ddemangle.d
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import core.demangle;
import std.ascii;
import std.stdio;
 
void main() {
foreach (line; stdin.byLine(File.KeepTerminator.yes)) {
size_t lastWritten;
bool hadUnderscore;
bool inSymbol;
 
foreach (i, char c; line) {
if (!inSymbol && hadUnderscore && c == 'D') {
inSymbol = true;
write(line[lastWritten .. (i - 1)]);
lastWritten = i - 1;
} else if (inSymbol && !(isAlphaNum(c) || c == '_')) {
inSymbol = false;
write(demangle(line[lastWritten .. i]));
lastWritten = i;
}
 
hadUnderscore = (c == '_');
}
 
auto rest = line[lastWritten .. $];
if (inSymbol) {
write(demangle(rest));
} else {
write(rest);
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.