Skip to content
Browse files

[Convert] Workaround for broken names with spaces

  • Loading branch information...
1 parent f0fd13a commit 1e78e62b906fd5fa9f10501ffd0543d4f3e3dc8d @thefiddler thefiddler committed Jun 19, 2014
Showing with 16 additions and 16 deletions.
  1. +16 −16 Source/Converter/GLXmlParser.cs
View
32 Source/Converter/GLXmlParser.cs
@@ -61,7 +61,7 @@ public override IEnumerable<XElement> Parse(string[] lines)
var elements = new SortedDictionary<string, XElement>();
foreach (var e in ParseEnums(input).Concat(ParseFunctions(input)))
{
- var name = e.Attribute("name").Value;
+ var name = e.Attribute("name").Value.Trim().Replace(" ", "_");
var version = (e.Attribute("version") ?? new XAttribute("version", String.Empty)).Value;
var key = name + version;
if (!elements.ContainsKey(key))
@@ -131,7 +131,7 @@ IEnumerable<XElement> ParseEnums(XDocument input)
enums.Add(api, new SortedDictionary<string, string>());
enums[api].Add(
- TrimName(e.Attribute("name").Value),
+ TrimName(e.Attribute("name").Value.Trim().Replace(" ", "_")),
e.Attribute("value").Value);
}
@@ -146,7 +146,7 @@ IEnumerable<XElement> ParseEnums(XDocument input)
.Concat(groups)
.OrderBy(f => TrimName(f.Attribute("name").Value)))
{
- var category = TrimName(feature.Attribute("name").Value);
+ var category = TrimName(feature.Attribute("name").Value.Trim().Replace(" ", "_"));
var extension = feature.Name == "extension" ? category.Substring(0, category.IndexOf("_")) : "Core";
var version = feature.Attribute("number") != null ? feature.Attribute("number").Value : null;
var apinames = GetApiNames(feature);
@@ -165,14 +165,14 @@ IEnumerable<XElement> ParseEnums(XDocument input)
String.IsNullOrEmpty(version) ? null : new XAttribute("version", version)));
var api = APIs[key];
- var enum_name = TrimName(feature.Attribute("name").Value);
+ var enum_name = TrimName(feature.Attribute("name").Value.Trim().Replace(" ", "_"));
var e = new XElement("enum", new XAttribute("name", enum_name));
foreach (var token in
feature.Elements("enum")
.Concat(feature.Elements("require").Elements("enum")))
{
- var token_name = TrimName(token.Attribute("name").Value);
+ var token_name = TrimName(token.Attribute("name").Value.Trim().Replace(" ", "_"));
var token_value =
enums.ContainsKey(apiname) && enums[apiname].ContainsKey(token_name) ? enums[apiname][token_name] :
enums["default"].ContainsKey(token_name) ? enums["default"][token_name] :
@@ -198,23 +198,23 @@ IEnumerable<XElement> ParseEnums(XDocument input)
foreach (var api in APIs.Values)
{
- var apiname = api.Attribute("name").Value;
+ var apiname = api.Attribute("name").Value.Trim().Replace(" ", "_");
// Mark deprecated enums
foreach (var token in feature.Elements("remove").Elements("enum"))
{
- var token_name = TrimName(token.Attribute("name").Value);
+ var token_name = TrimName(token.Attribute("name").Value.Trim().Replace(" ", "_"));
var deprecated =
api.Elements("enum").Elements("token")
- .FirstOrDefault(t => t.Attribute("name").Value == token_name);
+ .FirstOrDefault(t => t.Attribute("name").Value.Trim().Replace(" ", "_") == token_name);
if (deprecated != null)
{
if (apiname == "glcore")
{
// These tokens do not exist in the glcore profile, remove them
api.Elements("enum").Elements("token")
- .First(t => t.Attribute("name").Value == token_name)
+ .First(t => t.Attribute("name").Value.Trim().Replace(" ", "_") == token_name)
.Remove();
}
else
@@ -256,7 +256,7 @@ IEnumerable<XElement> ParseFunctions(XDocument input)
// information about versioning, extension support and deprecation.
foreach (var feature in features.Concat(extensions))
{
- var category = TrimName(feature.Attribute("name").Value);
+ var category = TrimName(feature.Attribute("name").Value.Trim().Replace(" ", "_"));
var apinames = GetApiNames(feature);
var version =
@@ -283,7 +283,7 @@ IEnumerable<XElement> ParseFunctions(XDocument input)
foreach (var command in feature.Elements("require").Elements("command"))
{
- var cmd_name = TrimName(command.Attribute("name").Value);
+ var cmd_name = TrimName(command.Attribute("name").Value.Trim().Replace(" ", "_"));
var cmd_extension =
ExtensionRegex.Match(cmd_name).Value ??
(feature.Name == "extension" ? category.Substring(0, category.IndexOf("_")) : "Core");
@@ -304,24 +304,24 @@ IEnumerable<XElement> ParseFunctions(XDocument input)
foreach (var api in APIs.Values)
{
i++;
- var apiname = api.Attribute("name").Value;
+ var apiname = api.Attribute("name").Value.Trim().Replace(" ", "_");
var cmd_version = version.Length > i ? version[i] : version[0];
// Mark all deprecated functions as such
foreach (var command in feature.Elements("remove").Elements("command"))
{
- var deprecated_name = TrimName(command.Attribute("name").Value);
+ var deprecated_name = TrimName(command.Attribute("name").Value.Trim().Replace(" ", "_"));
var deprecated =
api.Elements("function")
- .FirstOrDefault(t => t.Attribute("name").Value == deprecated_name);
+ .FirstOrDefault(t => t.Attribute("name").Value.Trim().Replace(" ", "_") == deprecated_name);
if (deprecated != null)
{
if (apiname == "glcore")
{
// These tokens do not exist in the glcore profile, remove them
api.Elements("function")
- .First(t => t.Attribute("name").Value == deprecated_name)
+ .First(t => t.Attribute("name").Value.Trim().Replace(" ", "_") == deprecated_name)
.Remove();
}
else
@@ -431,7 +431,7 @@ string FunctionParameterType(XElement e)
// -> <param name="length" type="GLsizei" count="1" />
var proto = e.Value;
- var name = e.Element("name").Value;
+ var name = e.Element("name").Value.Trim().Replace(" ", "_");
var group = e.Attribute("group");
var ret = proto.Remove(proto.LastIndexOf(name)).Trim();

0 comments on commit 1e78e62

Please sign in to comment.
Something went wrong with that request. Please try again.