Skip to content

Instantly share code, notes, and snippets.

@dnadlinger
Created July 7, 2011 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnadlinger/1069843 to your computer and use it in GitHub Desktop.
Save dnadlinger/1069843 to your computer and use it in GitHub Desktop.
Demangles D symbol names found in standard input.
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment