Created
July 7, 2011 16:00
-
-
Save dnadlinger/1069843 to your computer and use it in GitHub Desktop.
Demangles D symbol names found in standard input.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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