NintendoSpy
NintendoSpy copied to clipboard
[Bug] Float.TryParse little overview for other CultureInfo system
In the function static float readFloatConfig(XElement elem, string attrName)
in Skin.cs [line 275 actually], there is a little oversight in the usage of Float.TryParse
My locale says that a floating point number should be written with a comma instead of a dot. Of course, as a dev, I always use a dot, but my computer didn't hear it from that ear, and so did NintendoSpy when reading from
&& to
attributes in some rangebutton
configuration in skins.
Thus, there is a little portability issue, as I initially downloaded the skin.xml from whom it worked just fine.
The solutions are simple :
- Decide to let it be, warn users in documentation and lose a little bit of portability over consistency for different locale
- Use the form
float.TryParse (readStringAttr(elem, attrName), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out ret)
forcing the North American style redaction for floating point number. - Use a middle term solution where 3
Float.TryParse
are done in order to try different solutions, and report a fail if all of that didn't work
I've tried the third one, it has allow me to mix a dot-style number with a comma-style number, but it isn't a one line solution. The functions become :
static float readFloatConfig (XElement elem, string attrName)
{
float ret;
string attrValue = readStringAttr(elem, attrName);
if (! float.TryParse (attrValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out ret) &&
! float.TryParse(attrValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out ret) &&
! float.TryParse(attrValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out ret)){
throw new ConfigParseException ("Failed to parse number for property '"+attrName+"' in element '"+elem.Name+"'.");
}
return ret;
}
Thanks for pointing this out. I'll add this in a future commit when I get the chance.
hey, when this bug will be fixed? I'm trying to use rangebutton but that error is very annoying and I can't do what I wanted do to
I don't currently have any time to work on this project, so this bug will get fixed as soon as somebody submits a pull request that solves the issue.
oh ok, I will wait, thanks :D