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

scn::scan/prompt from stdin with literal text does not work #29

Closed
melak47 opened this issue Aug 3, 2020 · 4 comments
Closed

scn::scan/prompt from stdin with literal text does not work #29

melak47 opened this issue Aug 3, 2020 · 4 comments

Comments

@melak47
Copy link

melak47 commented Aug 3, 2020

When trying to scan a format string with a literal at the start, a debug assertions fires:

File: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\xstring
Line: 1853

Expression: cannot seek string iterator before begin

Code I used, adapted from the examples (using scnlib 0.3):

#include <scn/scn.h>
#include <iostream>

int main() {
    int i = 0;
    if (scn::prompt("Hi there! What's your favorite number? ", "uhh, {}", i)) {
        std::cout << "Ooh, " << i << ", interesting!\n";
    }
    else {
        std::cout << "That doesn't look like any number I've ever seen.\n";
    }
}
@melak47 melak47 changed the title scn::scan with literal text does not work scn::scan/prompt from stdin with literal text does not work Aug 3, 2020
@melak47
Copy link
Author

melak47 commented Aug 3, 2020

It seems to be related specifically to the file putback, it works when you scan from e.g. a string_view.

@melak47
Copy link
Author

melak47 commented Aug 4, 2020

In range_wrapper::advance:

iterator advance(difference_type n = 1) noexcept
{
m_read += n;
if (!is_caching_range<Range>::value) {
ranges::advance(m_begin, n);
}
return m_begin;
}

the begin iterator of the range is not incremented for the caching cfile iterator.
As far as I can tell, this leads to operator* always yielding the same character, thus matching the literal fails.

Also, in range_wrapper::reset_to_rollback_point:

error reset_to_rollback_point()
{
for (; m_read != 0; --m_read) {
--m_begin;

the iterator is decremented m_read times, even though it may have been incremented less than that (outside of range_wrapper).

@melak47
Copy link
Author

melak47 commented Oct 30, 2020

This seems to be resolved on master.

@melak47 melak47 closed this as completed Oct 30, 2020
@eliaskosunen
Copy link
Owner

It is, sorry for not responding and fixing this earlier.

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