replace \ properly
This commit is contained in:
parent
c7df716df8
commit
d1917ed9a6
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user