From 28e74579805c35009c8c474c79a2a5715ed92327 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 26 Feb 2018 20:13:50 +0100 Subject: [PATCH] f --- libsolidity/ast/Types.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 8abbbc169..396592f26 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -263,6 +263,44 @@ string Type::escapeIdentifier(string const& _identifier) string Type::unescapeIdentifier(string const& _identifier) { + bool underscore = false; + unsigned dollar = 0; + string out(_identifier.length); + + for (auto const& c: _identifier) + { + if (c == '_') { + // $_ -> ( + if (dollar != 0) { + out.append('('); + } else { + underscore = true; + } + } else if (c == '$') { + // _$ -> ) + if (underscore && dollar == 0) { + underscore = false; + out.append(')'); + } else { + dollar++; + // $$$ -> $ + if (dollar == 3) { + out.append('$'); + dollar = 0; + } + } + } else { + // flush pending underscore + if (underscore) { + out.append('_'); + underscore = false; + } + out.append(c); + } + } + __$$$$$$__ -> __$$$$__ -> __ + + string ret = _identifier; // FIXME: should be _$$$_ boost::algorithm::replace_all(ret, "$$$", "$");