Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan Integer with leading zero? #815

Open
MaxMxMz opened this issue Aug 20, 2024 · 2 comments
Open

Scan Integer with leading zero? #815

MaxMxMz opened this issue Aug 20, 2024 · 2 comments

Comments

@MaxMxMz
Copy link

MaxMxMz commented Aug 20, 2024

Hello!
integer data - 01 02 0003 and so on ..... with leading zero

I Use example
int main()
{
char8_t a,b,c,d;
scan(a,".",b,".",c,".",d);
println(a,".",b,".",c,".",d);
}
if i enter 01.2.3.4 - i have exeption

I've tried
scan("0", a); - work,
but when data no have leading zero, i have exeption

@trcrsired
Copy link
Member

trcrsired commented Aug 20, 2024

Hi. This needs to use manipulator ::fast_io::manipulator::base_get<10, false, true>(a)

i have just found it only has bin_get and hex_get so i am adding dec_get and oct_get. so you can use ::fast_io::manipulator::dec_get<false, true>(a) instead

template <::std::size_t bs, bool noskipws = false, bool skipzero = false, bool prefix = false, ::fast_io::details::my_integral scalar_type>
inline constexpr scalar_manip_t<::fast_io::details::base_scan_mani_flags_cache<bs, noskipws, (bs == 10 ? false : prefix), skipzero>,
								scalar_type &>
base_get(scalar_type &t) noexcept
{
	return {t};
}

template <bool noskipws = false, bool skipzero = false, ::fast_io::details::my_integral scalar_type>
inline constexpr scalar_manip_t<::fast_io::details::base_scan_mani_flags_cache<10, noskipws, false, skipzero>,
								scalar_type &>
dec_get(scalar_type &t) noexcept
{
	return {t};
}

The reason zeros are not skipped by default is that numbers starting with a 0 might be interpreted as octal (base 8) numbers, causing issues for things like IP addresses. This is an unfortunate consequence from UNIX.

Scanning with a string literal isn't meant for any kind of string pattern matching. It only means that next part of string in the stream must be that string. fast_io does not use any kind of format string at all.

@trcrsired
Copy link
Member

BTW, in your example i think you need to set noskipws to be true too so it cannot skip spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants