From 32a3282d5dbfc48d4f1d29a2bca388202363654b Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 28 Apr 2015 16:17:36 +0200 Subject: [PATCH] Support for alternative culture info, in this way it can be guaranteed that ',' works always as a decimal point. --- TestBenchFramework/Program.cs | 4 ++++ TestBenchFramework/Utils.cs | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TestBenchFramework/Program.cs b/TestBenchFramework/Program.cs index 5a9e3b3cb..811ea3cd6 100644 --- a/TestBenchFramework/Program.cs +++ b/TestBenchFramework/Program.cs @@ -30,6 +30,8 @@ namespace TBF public const string LocalSettingsFileName = "config.xml"; public const string LocalSettingsBackupName = "config.backup.xml"; + public static System.Globalization.CultureInfo AltCulture; + /// Database related: This object reference is set after a successful user login public static DatabaseSettings CurrentBench; const string SQLiteDbFName = "SQLite.db"; @@ -143,6 +145,8 @@ namespace TBF new System.Globalization.CultureInfo("en"); } + //AltCulture = null; + AltCulture = new System.Globalization.CultureInfo("SK"); /// This belongs to Application.Run(new MainWnd()) ... /// and should be executed before opening 'loginDlg' diff --git a/TestBenchFramework/Utils.cs b/TestBenchFramework/Utils.cs index 0ce3efe87..3459c55f2 100644 --- a/TestBenchFramework/Utils.cs +++ b/TestBenchFramework/Utils.cs @@ -15,13 +15,16 @@ namespace TBF public static bool TryParseUFloat(string text, out float result) { return float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out result) || - float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result); + float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result) || + (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint, Program.AltCulture, out result)); + } public static float ParseUFloat(string text, float dfltVal) { float result; if (float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out result)) return result; if (float.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result)) return result; + if (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint, Program.AltCulture, out result)) return result; return dfltVal; } public static float ParseUFloat(string text) @@ -35,13 +38,15 @@ namespace TBF public static bool TryParseSFloat(string text, out float result) { return float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.CurrentCulture, out result) || - float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result); + float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result) || + (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Program.AltCulture, out result)); } public static float ParseSFloat(string text, float dfltVal) { float result; if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.CurrentCulture, out result)) return result; if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result)) return result; + if (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Program.AltCulture, out result)) return result; return dfltVal; } public static float ParseSFloat(string text) @@ -55,13 +60,15 @@ namespace TBF public static bool TryParseEFloat(string text, out float result) { return float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out result) || - float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result); + float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result) || + (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, Program.AltCulture, out result)); } public static float ParseEFloat(string text, float dfltVal) { float result; if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out result)) return result; if (float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result)) return result; + if (Program.AltCulture != null && float.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, Program.AltCulture, out result)) return result; return dfltVal; } public static float ParseEFloat(string text)