Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » StrInt returning value
StrInt returning value [message #59848] Wed, 03 May 2023 08:06 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

it seems that StrInt() return an integer but it can return even a Null in case the conversion cannot be done.
I would like that StrInt() can return 0 as default instead of Null.
Do we have an alternative version of StrInt() that return 0 as default?

StrInt is based on ScanInt

int ScanInt(const char *ptr)
{
	int x;
	bool overflow = false;
	return ScanInt<char, byte, uint32, int, 10>(x, ptr, overflow) && !overflow ? x : Null;
}


The syntax is too complicated for me. I wonder if the following version can return 0 as wanted

int ScanInt0(const char *ptr)
{
	int x;
	bool overflow = false;
	return ScanInt<char, byte, uint32, int, 10>(x, ptr, overflow) && !overflow ? x : 0; //<----
}


Thanks,
Luigi

[Updated on: Wed, 03 May 2023 08:13]

Report message to a moderator

Re: StrInt returning value [message #59849 is a reply to message #59848] Wed, 03 May 2023 14:02 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1076
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Lugi,

Changes like you proposed all out of scope. The current behavior is with us for a very long period of time and users are used to it. The function behaves in accordance to our documentation. Also changing this behavior to what you have proposed means breaking API change, which should be avoided at all cost. You will literally break dozens of application that relays on this function.

The alternative version doesn't exist, because c++ doesn't allow to have the same functions but with different return type. Anyway, introducing new function we will pollute our API. Keep it simple stupid with one implementation is reasonable in this case.

So, at the moment you just need to align to the current behavior and handle Null as error case.

Klugier


U++ - one framework to rule them all.
Re: StrInt returning value [message #59850 is a reply to message #59848] Wed, 03 May 2023 15:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Wed, 03 May 2023 08:06
Hello,

it seems that StrInt() return an integer but it can return even a Null in case the conversion cannot be done.
I would like that StrInt() can return 0 as default instead of Null.
Do we have an alternative version of StrInt() that return 0 as default?



Well, we already had Atof, so I guess it is logical to have Atoi and Atoi64.

https://github.com/ultimatepp/ultimatepp/commit/0cea273540d8 f19c65bc6994cb5f40ccafbf1bab

Mirek
Re: StrInt returning value [message #59851 is a reply to message #59850] Wed, 03 May 2023 16:35 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
mirek wrote on Wed, 03 May 2023 15:21

Well, we already had Atof, so I guess it is logical to have Atoi and Atoi64.

Mirek


Great!

Thanks,
Luigi
Previous Topic: CreateProcessW doesn't compile with CLANG
Next Topic: memory consumption of my application
Goto Forum:
  


Current Time: Thu Apr 25 07:47:28 CEST 2024

Total time taken to generate the page: 0.04052 seconds