[bug?]OgreString Converter

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow
x 1

[bug?]OgreString Converter

Post 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?
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: [bug?]OgreString Converter

Post by spacegaier »

This works fine for me:

Code: Select all

const char* key = "1";
int test = Ogre::StringConverter::parseInt(key); // test equals '1'
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: [bug?]OgreString Converter

Post 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.
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: [bug?]OgreString Converter

Post 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.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Post Reply