replace \ properly

This commit is contained in:
Akash Mozumdar 2019-01-21 14:22:47 -05:00
parent c7df716df8
commit d1917ed9a6
2 changed files with 21 additions and 2 deletions

View File

@ -148,7 +148,17 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
std::wstring translation, translateFrom;
Translate(sentence, translateFrom, translateTo);
translation = Translate(sentence, translateFrom, translateTo);
for (auto& c : translation) if (c == L'\\') c = 0x200b;
for (int i = 0; i < translation.size(); ++i)
{
if (translation[i] == L'\\')
{
translation[i] = 0x200b;
if (translation[i + 1] == L'r') translation[i + 1] = L'\r';
if (translation[i + 1] == L'n') translation[i + 1] = L'\n';
}
}
if (translation.empty()) translation = TRANSLATION_ERROR;
sentence += L"\n" + translation;
return true;

View File

@ -194,7 +194,16 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
std::wstring response(wbuffer);
for (std::wsmatch results; std::regex_search(response, results, std::wregex(L"\\[\"(.*?)\",[n\"]")); response = results.suffix())
translation += std::wstring(results[1]) + L" ";
for (auto& c : translation) if (c == L'\\') c = 0x200b;
for (int i = 0; i < translation.size(); ++i)
{
if (translation[i] == L'\\')
{
translation[i] = 0x200b;
if (translation[i + 1] == L'r') translation[i + 1] = L'\r';
if (translation[i + 1] == L'n') translation[i + 1] = L'\n';
}
}
}
else
{