[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

[bug?]OgreString Converter

Post by nickG » Sun Oct 06, 2013 1:26 pm

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?
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: [bug?]OgreString Converter

Post by spacegaier » Sat Oct 12, 2013 12:38 pm

This works fine for me:

Code: Select all

const char* key = "1";
int test = Ogre::StringConverter::parseInt(key); // test equals '1'
0 x
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: 7152
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 19

Re: [bug?]OgreString Converter

Post by Kojack » Sun Oct 13, 2013 4:12 am

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.
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: [bug?]OgreString Converter

Post by spacegaier » Sun Oct 13, 2013 8:34 am

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.
0 x
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