Page 1 of 1

[bug?]OgreString Converter

Posted: Sun Oct 06, 2013 1:26 pm
by nickG
I tried use:

Code: Select all

int Config::getValueAsInt(const char* key)	{
return 
Ogre::StringConverter::parseInt(key);
}
But in anyway i getting 0;(for example config string =1)

My equal solution

Code: Select all

	int Config::getValueAsInt(const char* key)	{
		if(!getValueAsString(key).empty())
		return atoi(getValueAsString(key).c_str());
		else return 0;
	}
It's ogre bug,or my logic error?

Re: [bug?]OgreString Converter

Posted: Sat Oct 12, 2013 12:38 pm
by spacegaier
This works fine for me:

Code: Select all

const char* key = "1";
int test = Ogre::StringConverter::parseInt(key); // test equals '1'

Re: [bug?]OgreString Converter

Posted: Sun Oct 13, 2013 4:12 am
by Kojack
parseInt is used over 100 times in ogre, to convert meshes from xml, load materials, etc. So not being able to handle "1" would be rather surprising.
Try breakpointing inside of getValueAsInt and check the actual contents of key. Make sure there's no extra symbols in there.
Locale can affect things, for example some countries use commas instead of periods for fractions (not going to affect ints though, just an example). atoi is an old c function while parseInt uses c++ string streams which have locale support.

Re: [bug?]OgreString Converter

Posted: Sun Oct 13, 2013 8:34 am
by spacegaier
Kojack wrote:Locale can affect things, for example some countries use commas instead of periods for fractions (not going to affect ints though, just an example).
Note: Locale support was only added in 1.9 IIRC and is disabled by default for backward compatibility.