From ba3f51f4b1a76b6bc9d7c19c6aaade4e749e6295 Mon Sep 17 00:00:00 2001 From: aydin Date: Sat, 1 Jun 2024 18:42:07 +0200 Subject: [PATCH 1/2] Added escaping for \n and \r --- include/CSVWriter.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/CSVWriter.h b/include/CSVWriter.h index 358b79d..c5777ca 100644 --- a/include/CSVWriter.h +++ b/include/CSVWriter.h @@ -46,6 +46,18 @@ class CSVWriter } CSVWriter& add(std::string str){ + // escpace \n and \r + size_t new_line = str.find("\n", 0); + while(new_line != std::string::npos){ + str.replace(new_line, 1, "\\n"); + new_line = str.find("\n", 0); + } + size_t carriage_return = str.find("\r", 0); + while(carriage_return != std::string::npos){ + str.replace(carriage_return, 1, "\\r"); + carriage_return = str.find("\n", 0); + } + //if " character was found, escape it size_t position = str.find("\"",0); bool foundQuotationMarks = position != std::string::npos; From 47c7cb5882ea94f0a84335ec101e56da6a3e31d5 Mon Sep 17 00:00:00 2001 From: aydin Date: Mon, 3 Jun 2024 11:58:56 +0200 Subject: [PATCH 2/2] Changed variables to camel case --- include/CSVWriter.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/CSVWriter.h b/include/CSVWriter.h index c5777ca..eeeef61 100644 --- a/include/CSVWriter.h +++ b/include/CSVWriter.h @@ -47,15 +47,15 @@ class CSVWriter CSVWriter& add(std::string str){ // escpace \n and \r - size_t new_line = str.find("\n", 0); - while(new_line != std::string::npos){ - str.replace(new_line, 1, "\\n"); - new_line = str.find("\n", 0); + size_t newLinePosition = str.find("\n", 0); + while(newLinePosition != std::string::npos){ + str.replace(newLinePosition, 1, "\\n"); + newLinePosition = str.find("\n", 0); } - size_t carriage_return = str.find("\r", 0); - while(carriage_return != std::string::npos){ - str.replace(carriage_return, 1, "\\r"); - carriage_return = str.find("\n", 0); + size_t carriageReturnPosition = str.find("\r", 0); + while(carriageReturnPosition != std::string::npos){ + str.replace(carriageReturnPosition, 1, "\\r"); + carriageReturnPosition = str.find("\n", 0); } //if " character was found, escape it