-
Notifications
You must be signed in to change notification settings - Fork 61
Escape quality string characters in JSON output #49
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,45 @@ | ||
| #include "common.h" | ||
| #include "common.h" | ||
|
|
||
| std::string escapeJsonString(const std::string& input) { | ||
| std::string output; | ||
| output.reserve(input.size()); | ||
|
|
||
| for(size_t i = 0; i < input.size(); i++) { | ||
| const unsigned char c = static_cast<unsigned char>(input[i]); | ||
| switch(c) { | ||
| case '"': | ||
| output += "\\\""; | ||
| break; | ||
| case '\\': | ||
| output += "\\\\"; | ||
| break; | ||
| case '\b': | ||
| output += "\\b"; | ||
| break; | ||
| case '\f': | ||
| output += "\\f"; | ||
| break; | ||
| case '\n': | ||
| output += "\\n"; | ||
| break; | ||
| case '\r': | ||
| output += "\\r"; | ||
| break; | ||
| case '\t': | ||
| output += "\\t"; | ||
| break; | ||
| default: | ||
| if(c < 0x20) { | ||
| const char* hex = "0123456789abcdef"; | ||
| output += "\\u00"; | ||
| output += hex[(c >> 4) & 0x0F]; | ||
| output += hex[c & 0x0F]; | ||
| } else { | ||
| output += static_cast<char>(c); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return output; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,9 @@ extern string command; | |
|
|
||
| void JsonReporter::run() { | ||
| mFile << "{" << endl; | ||
| mFile << "\t\"command\":\"" << command << "\"," << endl; | ||
| mFile << "\t\"command\":\"" << escapeJsonString(command) << "\"," << endl; | ||
| mFile << "\t\"version\":\"" << FUSIONSCAN_VER << "\"," << endl; | ||
| mFile << "\t\"time\":\"" << getCurrentSystemTime() << "\"," << endl; | ||
| mFile << "\t\"time\":\"" << escapeJsonString(getCurrentSystemTime()) << "\"," << endl; | ||
|
||
| mFile << "\t\"fusions\":{"; | ||
|
|
||
| bool isFirstMut = true; | ||
|
|
@@ -42,25 +42,25 @@ void JsonReporter::run() { | |
| else | ||
| mFile << "," << endl; | ||
|
|
||
| mFile << "\t\t\"" << fusion.mTitle << "\":{" << endl; | ||
| mFile << "\t\t\"" << escapeJsonString(fusion.mTitle) << "\":{" << endl; | ||
| mFile << "\t\t\t\"" << "left" << "\":{" << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_name" << "\":" << "\"" << fusion.mLeftGene.mName << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_chr" << "\":" << "\"" << fusion.mLeftGene.mChr << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_name" << "\":" << "\"" << escapeJsonString(fusion.mLeftGene.mName) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_chr" << "\":" << "\"" << escapeJsonString(fusion.mLeftGene.mChr) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "position" << "\":" << fusion.mLeftGene.genePos2ChrPos(fusion.mLeftGP.position) << "," << endl; | ||
| mFile << "\t\t\t\t\"" << "reference" << "\":" << "\"" << fusion.mLeftRef << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "ref_ext" << "\":" << "\"" << fusion.mLeftRefExt << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "pos_str" << "\":" << "\"" << fusion.mLeftPos << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "reference" << "\":" << "\"" << escapeJsonString(fusion.mLeftRef) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "ref_ext" << "\":" << "\"" << escapeJsonString(fusion.mLeftRefExt) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "pos_str" << "\":" << "\"" << escapeJsonString(fusion.mLeftPos) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "exon_or_intron" << "\":" << "\"" << (fusion.mLeftIsExon?"exon":"intron") << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "exon_or_intron_id" << "\":" << fusion.mLeftExonOrIntronID << "," << endl; | ||
| mFile << "\t\t\t\t\"" << "strand" << "\":" << "\"" << (fusion.isLeftProteinForward()?"forward":"reversed") << "\"" << endl; | ||
| mFile << "\t\t\t}, " << endl; | ||
| mFile << "\t\t\t\"" << "right" << "\":{" << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_name" << "\":" << "\"" << fusion.mRightGene.mName << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_chr" << "\":" << "\"" << fusion.mRightGene.mChr << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_name" << "\":" << "\"" << escapeJsonString(fusion.mRightGene.mName) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "gene_chr" << "\":" << "\"" << escapeJsonString(fusion.mRightGene.mChr) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "position" << "\":" << fusion.mRightGene.genePos2ChrPos(fusion.mRightGP.position) << "," << endl; | ||
| mFile << "\t\t\t\t\"" << "reference" << "\":" << "\"" << fusion.mRightRef << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "ref_ext" << "\":" << "\"" << fusion.mRightRefExt << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "pos_str" << "\":" << "\"" << fusion.mRightPos << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "reference" << "\":" << "\"" << escapeJsonString(fusion.mRightRef) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "ref_ext" << "\":" << "\"" << escapeJsonString(fusion.mRightRefExt) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "pos_str" << "\":" << "\"" << escapeJsonString(fusion.mRightPos) << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "exon_or_intron" << "\":" << "\"" << (fusion.mRightIsExon?"exon":"intron") << "\"," << endl; | ||
| mFile << "\t\t\t\t\"" << "exon_or_intron_id" << "\":" << fusion.mRightExonOrIntronID << "," << endl; | ||
| mFile << "\t\t\t\t\"" << "strand" << "\":" << "\"" << (fusion.isRightProteinForward()?"forward":"reversed") << "\"" << endl; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
escapeJsonStringis formatted with tab indentation, while most of the codebase uses spaces (e.g., other .cpp files insrc/). Please reformat this function to avoid mixed whitespace and keep style consistent.