c++: auto in trailing-return-type in parameter [PR117778]
[gcc.git] / libphobos / src / std / demangle.d
bloba78d3d3605f2b049e1052d206a8a1dc2c20ebecb
1 // Written in the D programming language.
3 /**
4 * Demangle D mangled names.
6 * Copyright: Copyright The D Language Foundation 2000 - 2009.
7 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
8 * Authors: $(HTTP digitalmars.com, Walter Bright),
9 * Thomas K$(UUML)hne, Frits van Bommel
10 * Source: $(PHOBOSSRC std/demangle.d)
11 * $(SCRIPT inhibitQuickIndex = 1;)
14 * Copyright The D Language Foundation 2000 - 2009.
15 * Distributed under the Boost Software License, Version 1.0.
16 * (See accompanying file LICENSE_1_0.txt or copy at
17 * http://www.boost.org/LICENSE_1_0.txt)
19 module std.demangle;
21 /**
22 Demangle D mangled names.
24 Params:
25 name = the mangled name
26 Returns:
27 A `string`. If it is not a D mangled name, it returns its argument name.
29 string demangle(string name) @safe pure nothrow
31 import core.demangle : demangle;
32 import std.exception : assumeUnique;
33 auto ret = demangle(name);
34 return () @trusted { return ret.assumeUnique; } ();
37 ///
38 @safe pure unittest
40 // int b in module a
41 assert(demangle("_D1a1bi") == "int a.b");
42 // char array foo in module test
43 assert(demangle("_D4test3fooAa") == "char[] test.foo");
46 /**
47 This program reads standard in and writes it to standard out,
48 pretty-printing any found D mangled names.
50 @system unittest
52 import std.ascii : isAlphaNum;
53 import std.algorithm.iteration : chunkBy, joiner, map;
54 import std.algorithm.mutation : copy;
55 import std.conv : to;
56 import std.demangle : demangle;
57 import std.functional : pipe;
58 import std.stdio : stdin, stdout;
60 void main()
62 stdin.byLineCopy
63 .map!(
64 l => l.chunkBy!(a => isAlphaNum(a) || a == '_')
65 .map!(a => a[1].pipe!(to!string, demangle)).joiner
67 .copy(stdout.lockingTextWriter);