From 551d5ba49d6e9c186c56beb4b5c017ec29219906 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 12 Feb 2019 23:54:33 -0500 Subject: [PATCH] small refactor --- extensions/bingtranslate.cpp | 2 +- extensions/googletranslate.cpp | 2 +- extensions/network.h | 6 +++--- extensions/removerepeat.cpp | 7 +++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/extensions/bingtranslate.cpp b/extensions/bingtranslate.cpp index 04691fb..a073fa5 100644 --- a/extensions/bingtranslate.cpp +++ b/extensions/bingtranslate.cpp @@ -130,7 +130,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) TEST( { std::wstring test = L"こんにちは"; - ProcessSentence(test, SentenceInfo{ SentenceInfo::DUMMY }); + ProcessSentence(test, { SentenceInfo::DUMMY }); assert(test.find(L"Hello") != std::wstring::npos); } ); diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index 384a3bd..90d1368 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -166,7 +166,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) TEST( { std::wstring test = L"こんにちは"; - ProcessSentence(test, SentenceInfo{ SentenceInfo::DUMMY }); + ProcessSentence(test, { SentenceInfo::DUMMY }); assert(test.find(L"Hello") != std::wstring::npos); } ); diff --git a/extensions/network.h b/extensions/network.h index 3131e91..d47b53f 100644 --- a/extensions/network.h +++ b/extensions/network.h @@ -5,7 +5,7 @@ using InternetHandle = AutoHandle>; -std::optional ReceiveHttpRequest(HINTERNET request) +inline std::optional ReceiveHttpRequest(HINTERNET request) { WinHttpReceiveResponse(request, NULL); std::string data; @@ -17,14 +17,14 @@ std::optional ReceiveHttpRequest(HINTERNET request) if (!dwSize) break; std::vector buffer(dwSize); WinHttpReadData(request, buffer.data(), dwSize, &dwDownloaded); - data += std::string(buffer.data(), dwDownloaded); + data.append(buffer.data(), dwDownloaded); } while (dwSize > 0); if (data.empty()) return {}; return StringToWideString(data); } -void Escape(std::wstring& text) +inline void Escape(std::wstring& text) { for (int i = 0; i < text.size(); ++i) { diff --git a/extensions/removerepeat.cpp b/extensions/removerepeat.cpp index 3a66393..691bcc9 100644 --- a/extensions/removerepeat.cpp +++ b/extensions/removerepeat.cpp @@ -61,11 +61,10 @@ TEST( RemoveCyclicRepeats(cyclicRepeats); assert(cyclicRepeats == L"abcdefg"); - InfoForExtension tester{ "hook address", 0 }; std::wstring empty = L"", one = L" ", normal = L"This is a normal sentence. はい"; - ProcessSentence(empty, { &tester }); - ProcessSentence(one, { &tester }); - ProcessSentence(normal, { &tester }); + ProcessSentence(empty, { SentenceInfo::DUMMY }); + ProcessSentence(one, { SentenceInfo::DUMMY }); + ProcessSentence(normal, { SentenceInfo::DUMMY }); assert(empty == L"" && one == L" " && normal == L"This is a normal sentence. はい"); } );