using System.Collections.Generic; namespace Febucci.UI.Core { /// /// Helper class. Contains methods to parse attributes/values from strings. /// public static class FormatUtils { /// /// Tries to parse a rich text tag parameter. /// /// /// Mostly used in combination with custom typewriter actions. (Manual: Writing Custom actions C#) /// /// list of all the attributesi in the rich text tag /// the parameter's index in the list /// default value, assigned if the parsing is not successful /// result from the parsing /// true if successful public static bool TryGetFloat(List attributes, int index, float defValue, out float result) { if (index >= attributes.Count || index < 0) { result = defValue; return false; } return TryGetFloat(attributes[index], defValue, out result); } //TODO Docs public static bool TryGetFloat(string attribute, float defValue, out float result) { if (ParseFloat(attribute, out result)) return true; result = defValue; return false; } /// /// Tries parsing a float given a string, independently of the system's culture /// /// /// /// public static bool ParseFloat(string value, out float result) { return float.TryParse(value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out result); } } }