Skip to content

Commit

Permalink
Merge pull request #6 from abarim-games/master
Browse files Browse the repository at this point in the history
Missing fields fix
  • Loading branch information
cyotek committed Mar 17, 2016
2 parents 3469af8 + 6b7c275 commit 4b712e0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/Cyotek.Drawing.BitmapFont/BitmapFontLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,43 @@ public static BitmapFont LoadFontFromXmlFile(string fileName)
/// </summary>
/// <param name="parts">The array of parts.</param>
/// <param name="name">The name of the value to return.</param>
/// <param name="defaultValue">Default value(if the key doesnt exist or can't be parsed)</param>
/// <returns></returns>
internal static bool GetNamedBool(string[] parts, string name)
internal static bool GetNamedBool(string[] parts, string name, bool defaultValue = false)
{
return GetNamedInt(parts, name) != 0;
var s = GetNamedString(parts, name);

bool result;
int v;
if (int.TryParse(s, out v))
{
result = v > 0;
} else
{
result = defaultValue;
}

return result;
}

/// <summary>
/// Returns an integer from an array of name/value pairs.
/// </summary>
/// <param name="parts">The array of parts.</param>
/// <param name="name">The name of the value to return.</param>
/// <param name="defaultValue">Default value(if the key doesnt exist or can't be parsed)</param>
/// <returns></returns>
internal static int GetNamedInt(string[] parts, string name)
internal static int GetNamedInt(string[] parts, string name, int defaultValue = 0)
{
return Convert.ToInt32(GetNamedString(parts, name));
var s = GetNamedString(parts, name);

int result;
if (!int.TryParse(s, out result))
{
result = defaultValue;
}

return result;
}

/// <summary>
Expand Down

0 comments on commit 4b712e0

Please sign in to comment.