D demangling filter tool?

Michel Fortin michel.fortin at michelf.com
Thu Jun 23 04:49:13 PDT 2011


On 2011-06-23 06:57:39 -0400, Robert Clipsham <robert at octarineparrot.com> said:

> On 23/06/2011 02:16, Michel Fortin wrote:
>> On 2011-06-22 18:58:44 -0400, David Nadlinger <see at klickverbot.at> said:
>> 
>>> Does anybody have a tool lying around which reads in some text (from a
>>> file or stdin) and replaces all mangled D names it comes across with
>>> the demangled text? I thought I would ask before quickly whipping
>>> together a short program myself…
>> 
>> I made one a few months ago, but I can't seem to find it back now... Ah!
>> found it:
>> <http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=129673&header>

I 
>> 
> don't suppose you could repaste the code, I can't seem to copy/paste 
> the above, the web news reader just takes me back to its home page when 
> I try D;


import std.stdio;
import core.demangle;

void main()
{
	foreach (line; stdin.byLine())
	{
		size_t beginIdx, endIdx;

		enum State { searching_, searchingD, searchingEnd, done }
		State state;
		foreach (i, char c; line)
		{
			switch (state)
			{
			case State.searching_:
				if (c == '_')
				{
					beginIdx = i;
					state = State.searchingD;
				}
				break;
			case State.searchingD:
				if (c == 'D')
					state = State.searchingEnd;
				else if (c != '_')
					state = State.searching_;
				break;
			case State.searchingEnd:
				if (c == ' ' || c == '"' || c == '\'')
				{
					endIdx = i;
					state = State.done;
				}
				break;
			}
			if (state == State.done)
				break;
		}

		if (endIdx > beginIdx)
			writeln(line[0..beginIdx], demangle(line[beginIdx..endIdx]), 
line[endIdx..$]);
		else
			writeln(line);
	}
}

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list