Skip to content

Wrong LF count at the end #1502

Description

@goforit22123-netizen

I have following code:

YAML::Emitter out;
out << YAML::BeginMap;
out << YAML::Key << "data" << YAML::Value << YAML::Literal << "hello\nworld\n\n";
out << YAML::EndMap;
std::string tmp(out.c_str());

size_t tmp_cnt = std::count(tmp.begin(), tmp.end(), '\n');
std::cout << "lf count before save: " << tmp_cnt << std::endl;

auto node = YAML::Load(tmp);
auto result = node["data"].as<std::string>();

size_t cnt = std::count(result.begin(), result.end(), '\n');
std::cout << "lf count after load: " << cnt << std::endl;

and I expect 3 LF's in result string but it contains only 2.
I think it happens because yaml-cpp uses | instead of |+ for the literal content.
AFAIK, this problem is fixed in master branch but there is no new release that contains fix.
So, I decided to switch to the master version of yamp-cpp to get this update.
But in the master, we have another issues related to LF at the end.

Here is description of issues and code sample:

  1. If literal_value equals to helloworld, LF count is 0 after load, it's OK
  2. If literal_value equals to "helloworld\n" LF count is 0 after load, it's NOT OK (count should be 1)
  3. If literal_value equals to helloworld\n\n LF count is 1 after load, it's NOT OK (count should be 2)

For some obscure reasons, yaml-cpp removes one LF when data is readed back through YAML::Load.

Here is code:

        YAML::Emitter out;
        std::string literal_value = "helloworld\n\n";
        out << YAML::BeginMap;
        out << YAML::Key << "data" << YAML::Value << YAML::Literal << literal_value;
        out << YAML::EndMap;
        std::string tmp(out.c_str());

        size_t tmp_cnt = std::count(tmp.begin(), tmp.end(), '\n');
        std::cout << "LF count before save: " << tmp_cnt << std::endl;

        auto node = YAML::Load(tmp);
        auto result = node["data"].as<std::string>();

        size_t cnt = std::count(result.begin(), result.end(), '\n');
        std::cout << "LF count after load: " << cnt << std::endl;

        std::cout << tmp;

So, currently I need both functionality:

  1. Block Chomping Indicator
  2. Correct LF count at the end

I apologize for asking, but my project deadline is approaching, and I would like to know roughly when to expect a new version of the library that addresses these issues (or at least fix in master branch). If the release fits within my deadline, I will wait; otherwise, I will switch to a different library to ensure I can complete my tasks on time.

Thanks in advance for your reply.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions