return mangled;
}
+/* Extract the hex-digit from MANGLED, and assign the result to RET.
+ Return the remaining string on success or NULL on failure. */
+static const char *
+dlang_hexdigit (const char *mangled, char *ret)
+{
+ char c;
+
+ /* Return NULL if trying to extract something that isn't a hexdigit. */
+ if (mangled == NULL || !ISXDIGIT (mangled[0]) || !ISXDIGIT (mangled[1]))
+ return NULL;
+
+ c = mangled[0];
+ if (!ISDIGIT (c))
+ (*ret) = (c - (ISUPPER (c) ? 'A' : 'a') + 10);
+ else
+ (*ret) = (c - '0');
+
+ c = mangled[1];
+ if (!ISDIGIT (c))
+ (*ret) = (*ret << 4) | (c - (ISUPPER (c) ? 'A' : 'a') + 10);
+ else
+ (*ret) = (*ret << 4) | (c - '0');
+
+ mangled += 2;
+
+ return mangled;
+}
+
/* Demangle the calling convention from MANGLED and append it to DECL.
Return the remaining string on success or NULL on failure. */
static const char *
return mangled;
}
-/* Convert VAL from an ascii hexdigit to value. */
-static char
-ascii2hex (char val)
-{
- if (val >= 'a' && val <= 'f')
- return (val - 'a' + 10);
-
- if (val >= 'A' && val <= 'F')
- return (val - 'A' + 10);
-
- if (val >= '0' && val <= '9')
- return (val - '0');
-
- return 0;
-}
-
/* Extract the string value from MANGLED and append it to DECL.
Return the remaining string on success or NULL on failure. */
static const char *
string_append (decl, "\"");
while (len--)
{
- if (ISXDIGIT (mangled[0]) && ISXDIGIT (mangled[1]))
+ char val;
+ const char *endptr = dlang_hexdigit (mangled, &val);
+
+ if (endptr == NULL)
+ return NULL;
+
+ /* Sanitize white and non-printable characters. */
+ switch (val)
{
- char a = ascii2hex (mangled[0]);
- char b = ascii2hex (mangled[1]);
- char val = (a << 4) | b;
+ case ' ':
+ string_append (decl, " ");
+ break;
+ case '\t':
+ string_append (decl, "\\t");
+ break;
+ case '\n':
+ string_append (decl, "\\n");
+ break;
+ case '\r':
+ string_append (decl, "\\r");
+ break;
+ case '\f':
+ string_append (decl, "\\f");
+ break;
+ case '\v':
+ string_append (decl, "\\v");
+ break;
- /* Sanitize white and non-printable characters. */
- switch (val)
+ default:
+ if (ISPRINT (val))
+ string_appendn (decl, &val, 1);
+ else
{
- case ' ':
- string_append (decl, " ");
- break;
- case '\t':
- string_append (decl, "\\t");
- break;
- case '\n':
- string_append (decl, "\\n");
- break;
- case '\r':
- string_append (decl, "\\r");
- break;
- case '\f':
- string_append (decl, "\\f");
- break;
- case '\v':
- string_append (decl, "\\v");
- break;
-
- default:
- if (ISPRINT (val))
- string_appendn (decl, &val, 1);
- else
- {
- string_append (decl, "\\x");
- string_appendn (decl, mangled, 2);
- }
+ string_append (decl, "\\x");
+ string_appendn (decl, mangled, 2);
}
}
- else
- return NULL;
- mangled += 2;
+ mangled = endptr;
}
string_append (decl, "\"");
demangle.test!("")
#
--format=dlang
-_D8demangle30__T4testVAyaa7_20090a0d0c0b00Zv
-demangle.test!(" \t\n\r\f\v\x00")
+_D8demangle32__T4testVAyaa8_20090a0d0c0b00ffZv
+demangle.test!(" \t\n\r\f\v\x00\xff")
#
--format=dlang
_D8demangle22__T4testVAiA4i1i2i3i4Zv
_D15__T4testVfe0p1Zv
#
--format=dlang
+_D15__T4testVAyaa1_
+_D15__T4testVAyaa1_
+#
+--format=dlang
_D16__T4testVAyaa0aZv
_D16__T4testVAyaa0aZv
#
--format=dlang
+_D18__T4testVAyaa1_0GZv
+_D18__T4testVAyaa1_0GZv
+#
+--format=dlang
_D18__T4testVAyaa1_YYZv
_D18__T4testVAyaa1_YYZv
#
demangle.fn!(sym, val("null")).fun.position!().confuses!().demangle(void(const(char)) delegate)
#
--format=dlang
+_D8demangle39__T2fnVAyaa12_d0bfd180d0b8d0bcd0b5d180Z2fnFZv
+demangle.fn!("\xd0\xbf\xd1\x80\xd0\xb8\xd0\xbc\xd0\xb5\xd1\x80").fn()
+#
+--format=dlang
+_D8demangle26__T2fnVAyaa6_e4b896e7958cZ2fnFZv
+demangle.fn!("\xe4\xb8\x96\xe7\x95\x8c").fn()
+#
+--format=dlang
_D2gc11gctemplates56__T8mkBitmapTS3std5range13__T4iotaTiTiZ4iotaFiiZ6ResultZ8mkBitmapFNbNiNfPmmZv
gc.gctemplates.mkBitmap!(std.range.iota!(int, int).iota(int, int).Result).mkBitmap(ulong*, ulong)
#