From fddbf65e2819d487021946a51722d23565bdd561 Mon Sep 17 00:00:00 2001 From: Jomar Milan Date: Wed, 22 Mar 2023 03:20:59 -0700 Subject: Handle newlines in cIniFile (#5447) * Handle newlines during read and write in cIniFile When reading the ini file, replace \n with newline. When writing, replace the newline with \n. * Use ReplaceString instead of regex in IniFile * Update cIniFile description * Removed duplicate variable * Revert "Removed duplicate variable" This reverts commit de11bac047d871dfbffec28b72f72a2935bd339e. * Removed duplicate variable Now without plugin changes --------- Co-authored-by: x12xx12x <44411062+12xx12@users.noreply.github.com> --- src/IniFile.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/IniFile.cpp') diff --git a/src/IniFile.cpp b/src/IniFile.cpp index 8b051dd9a..d65154072 100644 --- a/src/IniFile.cpp +++ b/src/IniFile.cpp @@ -147,6 +147,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect) { valuename = line.substr(0, pLeft); value = TrimString(line.substr(pLeft + 1)); + ReplaceString(value, "\\n", "\n"); AddValue(keyname, valuename, value); break; } @@ -191,6 +192,7 @@ bool cIniFile::WriteFile(const AString & a_FileName) const // Normally you would use ofstream, but the SGI CC compiler has // a few bugs with ofstream. So ... fstream used. fstream f; + AString writevalue; f.open((a_FileName).c_str(), ios::out); if (f.fail()) @@ -223,7 +225,9 @@ bool cIniFile::WriteFile(const AString & a_FileName) const // Values. for (size_t valueID = 0; valueID < m_Keys[keyID].m_Names.size(); ++valueID) { - f << m_Keys[keyID].m_Names[valueID] << '=' << m_Keys[keyID].m_Values[valueID] << iniEOL; + writevalue = m_Keys[keyID].m_Values[valueID]; + ReplaceString(writevalue, "\n", "\\n"); + f << m_Keys[keyID].m_Names[valueID] << '=' << writevalue << iniEOL; } f << iniEOL; } -- cgit v1.2.3