Skip to content

Support line ending options#2085

Open
SinghRajenM wants to merge 1 commit into
Tencent:masterfrom
NPP-JSONViewer:line_ending
Open

Support line ending options#2085
SinghRajenM wants to merge 1 commit into
Tencent:masterfrom
NPP-JSONViewer:line_ending

Conversation

@SinghRajenM
Copy link
Copy Markdown

No description provided.

@tencent-adm
Copy link
Copy Markdown
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@miloyip
Copy link
Copy Markdown
Collaborator

miloyip commented Oct 10, 2022

I think this can be done in output stream instead.
Also, standard file i/o stream should already have conversion.

@SinghRajenM
Copy link
Copy Markdown
Author

I think this can be done in output stream instead. Also, standard file i/o stream should already have conversion.

I am not pretty much sure about it.

But we are using StringBuffer to get prettier string. Something like below -

    rj::StringBuffer                                                                                      sb;
    rj::PrettyWriter<rj::StringBuffer, rj::UTF8<>, rj::UTF8<>, rj::CrtAllocator, rj::kWriteNanAndInfFlag> handler(sb);
    handler.SetLineEnding(le);
    handler.SetFormatOptions(lf);
    handler.SetIndent(indentChar, indentLen);
    
    rj::Reader       reader;
    rj::StringStream ss(jsonText.c_str());
    success = reader.Parse<someflags>(ss, handler) && sb.GetString();

Here, we are expecting that sb.GetString should provide pretty json with desired line ending option.

@SinghRajenM
Copy link
Copy Markdown
Author

SinghRajenM commented Nov 27, 2022

@miloyip Is there anything needed from my end to get this accepted and merged?

@miloyip
Copy link
Copy Markdown
Collaborator

miloyip commented Feb 25, 2025

Hi. As mentioned previously, πdon't think this should be implemented at this level of abstraction. For example, if you write to string, and then output it as a file, it should do the conversion at file writing part, which is accomplished by lower level APIs.

@SinghRajenM
Copy link
Copy Markdown
Author

SinghRajenM commented Feb 26, 2025

Hi @miloyip,

I didn't fully understand your comment. However, what makes you think that PrettyWriter (here and other places assumes the line ending should be \n)?

if (!empty) {
Base::os_->Put('\n');
WriteIndent();
}

That said, I'll leave it up to you to accept or reject the solution. I've been using this approach for a long time in one of my other projects, and it has been working well. Please note that this change does not alter the default behavior—the line ending remains \n unless explicitly specified. The only issue I face is that whenever I update the RapidJSON submodule, I have to manually ensure that this change persists after fetching the latest version. Hence, this proposal.

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.

3 participants