aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/demangle.d
diff options
context:
space:
mode:
Diffstat (limited to 'libphobos/src/std/demangle.d')
-rw-r--r--libphobos/src/std/demangle.d106
1 files changed, 43 insertions, 63 deletions
diff --git a/libphobos/src/std/demangle.d b/libphobos/src/std/demangle.d
index e49bb9f..a78d3d3 100644
--- a/libphobos/src/std/demangle.d
+++ b/libphobos/src/std/demangle.d
@@ -3,87 +3,67 @@
/**
* Demangle D mangled names.
*
- * Copyright: Copyright Digital Mars 2000 - 2009.
+ * Copyright: Copyright The D Language Foundation 2000 - 2009.
* License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: $(HTTP digitalmars.com, Walter Bright),
* Thomas K$(UUML)hne, Frits van Bommel
- * Source: $(PHOBOSSRC std/_demangle.d)
+ * Source: $(PHOBOSSRC std/demangle.d)
* $(SCRIPT inhibitQuickIndex = 1;)
*/
/*
- * Copyright Digital Mars 2000 - 2009.
+ * Copyright The D Language Foundation 2000 - 2009.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module std.demangle;
-/+
-private class MangleException : Exception
+/**
+Demangle D mangled names.
+
+Params:
+ name = the mangled name
+Returns:
+ A `string`. If it is not a D mangled name, it returns its argument name.
+ */
+string demangle(string name) @safe pure nothrow
{
- this()
- {
- super("MangleException");
- }
+ import core.demangle : demangle;
+ import std.exception : assumeUnique;
+ auto ret = demangle(name);
+ return () @trusted { return ret.assumeUnique; } ();
}
-+/
-
-/*****************************
- * Demangle D mangled names.
- *
- * If it is not a D mangled name, it returns its argument name.
- * Example:
- * This program reads standard in and writes it to standard out,
- * pretty-printing any found D mangled names.
--------------------
-import core.stdc.stdio : stdin;
-import std.stdio;
-import std.ascii;
-import std.demangle;
-void test(int x, float y) { }
+///
+@safe pure unittest
+{
+ // int b in module a
+ assert(demangle("_D1a1bi") == "int a.b");
+ // char array foo in module test
+ assert(demangle("_D4test3fooAa") == "char[] test.foo");
+}
-int main()
+/**
+This program reads standard in and writes it to standard out,
+pretty-printing any found D mangled names.
+ */
+@system unittest
{
- string buffer;
- bool inword;
- int c;
+ import std.ascii : isAlphaNum;
+ import std.algorithm.iteration : chunkBy, joiner, map;
+ import std.algorithm.mutation : copy;
+ import std.conv : to;
+ import std.demangle : demangle;
+ import std.functional : pipe;
+ import std.stdio : stdin, stdout;
- writefln("Try typing in: %s", test.mangleof);
- while ((c = fgetc(stdin)) != EOF)
+ void main()
{
- if (inword)
- {
- if (c == '_' || isAlphaNum(c))
- buffer ~= cast(char) c;
- else
- {
- inword = false;
- write(demangle(buffer), cast(char) c);
- }
- }
- else
- { if (c == '_' || isAlpha(c))
- {
- inword = true;
- buffer.length = 0;
- buffer ~= cast(char) c;
- }
- else
- write(cast(char) c);
- }
+ stdin.byLineCopy
+ .map!(
+ l => l.chunkBy!(a => isAlphaNum(a) || a == '_')
+ .map!(a => a[1].pipe!(to!string, demangle)).joiner
+ )
+ .copy(stdout.lockingTextWriter);
}
- if (inword)
- write(demangle(buffer));
- return 0;
-}
--------------------
- */
-
-string demangle(string name)
-{
- import core.demangle : demangle;
- import std.exception : assumeUnique;
- auto ret = demangle(name);
- return assumeUnique(ret);
}