Move duplicated sanitizeIdentifier to Extensions
Also ensure that the identifier always starts with an underscore or letter, which fixes issues with obfuscated identifiers.
This commit is contained in:
@@ -8,6 +8,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Il2CppInspector.Reflection
|
||||
{
|
||||
@@ -83,6 +84,15 @@ namespace Il2CppInspector.Reflection
|
||||
return s.ToString();
|
||||
}
|
||||
|
||||
public static string ToCIdentifier(this string str) {
|
||||
// replace illegal characters
|
||||
str = Regex.Replace(str, "[^a-zA-Z0-9_]", "_");
|
||||
// ensure identifier starts with a letter or _ (and is non-empty)
|
||||
if (!Regex.IsMatch(str, "^[a-zA-Z_]"))
|
||||
str = "_" + str;
|
||||
return str;
|
||||
}
|
||||
|
||||
// Output a value in C#-friendly syntax
|
||||
public static string ToCSharpValue(this object value, TypeInfo type, Scope usingScope = null) {
|
||||
if (value is bool)
|
||||
|
||||
Reference in New Issue
Block a user