[Bind] Do not re-translate translated enum names

This commit is contained in:
thefiddler 2014-08-14 10:30:14 +02:00
parent d50bef3ba6
commit 5ec28b65be
3 changed files with 112 additions and 79 deletions

View file

@ -139,6 +139,17 @@ namespace Bind
return name;
}
static bool IsAlreadyProcessed(string name)
{
string extension = Utilities.GetExtension(name, true);
bool unprocessed = false;
unprocessed |= name.Contains("_") || name.Contains("-");
unprocessed |= Char.IsDigit(name[0]);
unprocessed |= name.All(c => Char.IsUpper(c));
unprocessed |= !String.IsNullOrEmpty(extension) && extension.All(c => Char.IsUpper(c));
return !unprocessed;
}
public string TranslateEnumName(string name)
{
if (String.IsNullOrEmpty(name))
@ -147,6 +158,8 @@ namespace Bind
if (Utilities.Keywords(Settings.Language).Contains(name))
return name;
if (!IsAlreadyProcessed(name))
{
if (Char.IsDigit(name[0]))
name = Settings.ConstantPrefix + name;
@ -211,6 +224,7 @@ namespace Bind
name = translator.ToString();
if (name.StartsWith(Settings.EnumPrefix))
name = name.Substring(Settings.EnumPrefix.Length);
}
return name;
}

View file

@ -103,14 +103,28 @@ namespace Bind
public static readonly char[] Separators = { ' ', '\n', ',', '(', ')', ';', '#' };
public static Regex Extensions { get; private set; }
public static Regex Acronyms { get; private set; }
//public static readonly Regex Extensions = new Regex(
// "ARB|EXT|ATIX|ATI|AMDX|AMD|NV|NVX|SUNX|SUN|SGIS|SGIX|SGI|MESAX|MESA|3DFX|IBM|GREMEDY|HP|INTEL|PGI|INGR|APPLE|OML|I3D|ARM|ANGLE|OES|QCOM|VIV|IMG",
// RegexOptions.Compiled);
//public static readonly Regex Acronyms = new Regex(Extensions.ToString() + "|EGL|3TC|DXT|ES|GL|CL|RGBA|BGRA|RGB|BGR|ETC",
// RegexOptions.Compiled);
public static void InitExtensions(IEnumerable<string> extensions)
static List<string> extension_names = new List<string>();
public static void AddExtensions(IEnumerable<string> extensions)
{
// Merge the new extensions with the current list of extensions
int extension_count = extension_names.Count;
extension_names.AddRange(
extensions.Where(n => !extension_names.Contains(n)));
// If any new extensions have been added,
// recreate the Extensions regex.
if (extension_names.Count != extension_count)
{
// Sort longest extensions first, otherwise SGIS may be
// incorrectly matched as SGI.
extension_names.Sort((a, b) => b.Length.CompareTo(a.Length));
Extensions = new Regex(
String.Join("|", extension_names.ToArray()),
RegexOptions.Compiled);
var acronyms = new string[]
{
"EGL", "ES", "GL", "CL",
@ -121,13 +135,10 @@ namespace Bind
"ANGLE", "MESAX", "MESA",
};
Extensions = new Regex(
String.Join("|", extensions.ToArray()),
RegexOptions.Compiled);
Acronyms = new Regex(
String.Join("|", extensions.Concat(acronyms).ToArray()),
RegexOptions.Compiled);
var acronym_names = extensions.Concat(acronyms).ToList();
acronym_names.Sort((a, b) => b.Length.CompareTo(a.Length));
Acronyms = new Regex(String.Join("|", acronym_names.ToArray()), RegexOptions.Compiled);
}
}
#region internal StreamReader OpenSpecFile(string file)
@ -271,15 +282,23 @@ namespace Bind
#region internal static string GetGL2Extension(string name)
internal static string GetGL2Extension(string name)
{
return GetExtension(name, false);
}
internal static string GetExtension(string name, bool return_unmodified)
{
var match = Extensions.Match(name);
if (match.Success)
{
string ext = match.Value;
if (!return_unmodified)
{
if (ext.Length > 2)
{
ext = ext[0] + ext.Substring(1).ToLower();
}
}
return ext;
}
else

View file

@ -331,7 +331,7 @@ namespace Bind
delegates.Add(d);
}
Utilities.InitExtensions(extensions);
Utilities.AddExtensions(extensions);
return delegates;
}