Browse Source

prefix identifiers starting with invalid characters with an underscore

pull/728/head
Siegfried Pammer 9 years ago
parent
commit
c6ce6d3d00
  1. 5
      ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs

5
ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs

@ -40,7 +40,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -40,7 +40,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
string ReplaceInvalid(string s)
{
return string.Concat(s.Select(ch => IsValid(ch) ? ch.ToString() : string.Format("_{0:X4}", (int)ch)));
string name = string.Concat(s.Select(ch => IsValid(ch) ? ch.ToString() : string.Format("_{0:X4}", (int)ch)));
if (name.Length >= 1 && !(char.IsLetter(name[0]) || name[0] == '_'))
name = "_" + name;
return name;
}
public void Run(AstNode rootNode, TransformContext context)

Loading…
Cancel
Save