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

fix: using stream operator not set eofbit #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Night12138
Copy link

@Night12138 Night12138 commented Feb 11, 2022

In the current version, there are the following issue

#include <iostream>
#include "picojson.hpp"

int main()
{
    while (!std::cin.eof()) // won't break
    {
        picojson::value v;
        std::cin >> v;
        // processing
        const auto &err = picojson::get_last_error();
        std::cout << "err: " << err << std::endl;
        std::cout << "res: " << v << std::endl;
    }
    return 0;
}

at Line 6, when read eof state from std::cin always return false.

fix: add beg/end judge in parse(value &out, std::istream &is) at Line 1135

inline std::string parse(value &out, std::istream &is) {
  std::string err;
  const auto &beg = std::istreambuf_iterator<char>(is.rdbuf());
  const auto &end = std::istreambuf_iterator<char>();
  parse(out, beg, end, &err);
  if (beg == end) {
    is.setstate(std::ios_base::eofbit); // set eof state because stream has no more data available
  }
  return err;
}

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

Successfully merging this pull request may close these issues.

1 participant