small refactor

This commit is contained in:
Akash Mozumdar 2019-02-12 23:54:33 -05:00
parent e494ebc077
commit 551d5ba49d
4 changed files with 8 additions and 9 deletions

View File

@ -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);
}
);

View File

@ -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);
}
);

View File

@ -5,7 +5,7 @@
using InternetHandle = AutoHandle<Functor<WinHttpCloseHandle>>;
std::optional<std::wstring> ReceiveHttpRequest(HINTERNET request)
inline std::optional<std::wstring> ReceiveHttpRequest(HINTERNET request)
{
WinHttpReceiveResponse(request, NULL);
std::string data;
@ -17,14 +17,14 @@ std::optional<std::wstring> ReceiveHttpRequest(HINTERNET request)
if (!dwSize) break;
std::vector<char> 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)
{

View File

@ -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. はい");
}
);