From 30811cb4acb087c475f6667d66634b25455d9913 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 4 Nov 2007 15:20:19 +0000 Subject: [PATCH] Translation code to follow .Net naming conventions. --- Source/Bind/Structures/Constant.cs | 45 +++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/Source/Bind/Structures/Constant.cs b/Source/Bind/Structures/Constant.cs index 06736dfc..dc4b5793 100644 --- a/Source/Bind/Structures/Constant.cs +++ b/Source/Bind/Structures/Constant.cs @@ -17,12 +17,15 @@ namespace Bind.Structures /// public class Constant { + static StringBuilder translator = new StringBuilder(); + #region public string Name string _name; /// /// Gets or sets the name of the opengl constant (eg. GL_LINES). + /// Undergoes processing unless the Settings.Legacy.NoAdvancedEnumProcessing flag is set. /// public string Name { @@ -30,7 +33,7 @@ namespace Bind.Structures set { if (!String.IsNullOrEmpty(value)) - _name = value.Trim(); + _name = Translate(value.Trim()); } } @@ -49,7 +52,7 @@ namespace Bind.Structures set { if (!String.IsNullOrEmpty(value)) - _value = value.Trim(); + _value = Translate(value.Trim()); } } @@ -60,7 +63,8 @@ namespace Bind.Structures string _reference; /// - /// Gets or sets the value of the opengl constant (eg. 0x00000001). + /// Gets or sets a string indicating the OpenGL enum reference by this constant. + /// Can be null. /// public string Reference { @@ -68,7 +72,7 @@ namespace Bind.Structures set { if (!String.IsNullOrEmpty(value)) - _reference = value.Trim(); + _reference = Enum.TranslateName(value.Trim()); } } @@ -108,6 +112,39 @@ namespace Bind.Structures #endregion + #region string Translate(string s) + + string Translate(string s) + { + translator.Remove(0, translator.Length); + + // Translate the constant's name to match .Net naming conventions + if ((Settings.Compatibility & Settings.Legacy.NoAdvancedEnumProcessing) == Settings.Legacy.None) + { + bool next_char_uppercase = true; + + foreach (char c in s) + { + if (c != '_') + { + translator.Append(next_char_uppercase ? Char.ToUpper(c) : Char.ToLower(c)); + next_char_uppercase = false; + } + else + next_char_uppercase = true; + } + + translator[0] = Char.ToUpper(translator[0]); + } + else + translator.Append(s); + + + return translator.ToString(); + } + + #endregion + #region public override string ToString() ///