WebParser: Cosmetics

This commit is contained in:
Birunthan Mohanathas 2013-07-12 10:39:00 +03:00
parent 19551cbb6c
commit 56aef6edfa

View File

@ -708,22 +708,20 @@ PLUGIN_EXPORT void Initialize(void** data, void* rm)
++g_InstanceCount; ++g_InstanceCount;
} }
std::vector<std::wstring> TokenizeUrl(const std::wstring url) std::vector<std::wstring> TokenizeUrl(const std::wstring& url)
{ {
std::vector<std::wstring> tokens; std::vector<std::wstring> tokens;
std::wstring::size_type start = 0; std::wstring::size_type start = 0;
std::wstring::size_type end = url.find_first_of(L'[', 0); std::wstring::size_type end = url.find_first_of(L'[', 0);
while (std::wstring::npos != start || std::wstring::npos != end) while (std::wstring::npos != start || std::wstring::npos != end)
{ {
std::wstring::size_type ending = url.find_first_of(L']', end); const std::wstring::size_type ending = url.find_first_of(L']', end);
if (ending == std::wstring::npos) if (ending == std::wstring::npos)
{ {
// Push back rest of string // Push back rest of string
if (url.size() != start) if (url.size() != start)
{ {
tokens.emplace_back(url.substr(start, url.size() - start)); tokens.emplace_back(url, start, url.size() - start);
} }
break; break;
} }
@ -731,11 +729,11 @@ std::vector<std::wstring> TokenizeUrl(const std::wstring url)
// Push non-Measure name chars (if any) // Push non-Measure name chars (if any)
if (start != end) if (start != end)
{ {
tokens.emplace_back(url.substr(start, end - start)); tokens.emplace_back(url, start, end - start);
} }
// Push back [MeasureName] // Push back [MeasureName]
tokens.emplace_back(url.substr(end, ending - end + 1)); tokens.emplace_back(url, end, ending - end + 1);
start = ending + 1; start = ending + 1;
end = url.find_first_of(L'[', start); end = url.find_first_of(L'[', start);
@ -757,7 +755,7 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{ {
std::vector<std::wstring> tokens = TokenizeUrl(url); std::vector<std::wstring> tokens = TokenizeUrl(url);
std::unordered_map<std::wstring, std::wstring> replacedTokens; std::unordered_map<std::wstring, std::wstring> replacedTokens;
for (auto iter : tokens) for (const auto& iter : tokens)
{ {
if (iter.size() >= 3 && iter[0] == L'[' && iter[iter.size() - 1] == L']') if (iter.size() >= 3 && iter[0] == L'[' && iter[iter.size() - 1] == L']')
{ {
@ -767,7 +765,7 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
// Check for "escaped" Webparser measures eg. [$WebparserMeasure$] // Check for "escaped" Webparser measures eg. [$WebparserMeasure$]
if (section[0] != L'$' && section[section.size() - 1] != L'$') if (section[0] != L'$' && section[section.size() - 1] != L'$')
{ {
for (auto jter : g_Measures) for (const auto& jter : g_Measures)
{ {
if (jter->section == section) if (jter->section == section)
{ {
@ -778,7 +776,7 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
} }
else else
{ {
section.erase(0,1); section.erase(0, 1);
section.erase(section.size() - 1, 1); section.erase(section.size() - 1, 1);
} }
@ -793,7 +791,7 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
} }
} }
for (auto iter : replacedTokens) for (const auto& iter : replacedTokens)
{ {
std::wstring::size_type start = url.find(iter.first); std::wstring::size_type start = url.find(iter.first);
while (start != std::wstring::npos) while (start != std::wstring::npos)