Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/Utils.cpp

Issue 5921969115496448: Issue 1115 - Some yahoo page not correctly shown on IE8 when ABP enabled (Closed)
Patch Set: rebase and address comments Created Feb. 12, 2015, 2:30 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/shared/Utils.cpp
diff --git a/src/shared/Utils.cpp b/src/shared/Utils.cpp
index 52b5a69f7920a6b9a49a46e16b250e2accaa33f8..8edb3e786cea4147a74038f5af651c60286bc7f9 100644
--- a/src/shared/Utils.cpp
+++ b/src/shared/Utils.cpp
@@ -147,3 +147,68 @@ void ReplaceString(std::wstring& input, const std::wstring placeholder, const st
input.replace(replaceStart, placeholder.length(), replacement);
}
}
+
+std::wstring GetSchemeAndHierarchicalPart(const std::wstring& url)
+{
+ auto schemeAndHierarchicalPartEndsAt = url.find(L'?');
+ if (schemeAndHierarchicalPartEndsAt == std::wstring::npos)
+ {
+ schemeAndHierarchicalPartEndsAt = url.find(L'#');
Oleksandr 2015/02/13 03:32:16 So what if there's neither '?' nor '#' in the url?
sergei 2015/02/13 15:21:56 It means there is neither query nor fragment and w
Oleksandr 2015/02/16 06:59:28 We are using WinHTTPCrackUrl in libadblockplus in
+ }
+ return url.substr(0, schemeAndHierarchicalPartEndsAt);
+}
+
+std::wstring GetQueryString(const std::wstring& url)
+{
+ auto questionSignPos = url.find(L'?');
+ if (questionSignPos == std::wstring::npos)
+ {
+ return L"";
+ }
+ auto queryStringBeginsAt = questionSignPos + 1;
+ auto endQueryStringPos = url.find(L'#', queryStringBeginsAt);
+ if (endQueryStringPos == std::wstring::npos)
+ {
+ endQueryStringPos = url.length();
+ }
+ return url.substr(queryStringBeginsAt, endQueryStringPos - queryStringBeginsAt);
+}
Eric 2015/02/12 17:24:41 This version much clearer and easier to verify cor
+
+void ForEachToken(const std::wstring& value, wchar_t delimiter,
+ const std::function<bool(std::wstring::const_iterator begin, std::wstring::const_iterator end)>& tokenHandler)
+{
+ if (value.empty())
+ {
+ return;
+ }
+ std::wstring::size_type delimiterPos = value.find(delimiter);
+ std::wstring::size_type prevDelimiterPos = 0;
+ while(delimiterPos != std::wstring::npos)
+ {
+ if (!tokenHandler(value.begin() + prevDelimiterPos, value.begin() + delimiterPos))
+ {
+ return;
+ }
+ prevDelimiterPos = delimiterPos;
+ ++prevDelimiterPos; // skip the delimiter
+ delimiterPos = value.find(delimiter, prevDelimiterPos);
+ }
+ tokenHandler(value.begin() + prevDelimiterPos, value.end());
+}
+
+void ForEachQueryStringParameter(const std::wstring& queryString,
+ const std::function<bool(const std::wstring& name, const std::wstring& value)>& parameterHandler)
+{
+ if (queryString.empty())
+ {
+ return;
+ }
+ ForEachToken(queryString, L'&',
+ [&parameterHandler](std::wstring::const_iterator begin,
+ std::wstring::const_iterator end)->bool
+ {
+ auto assignSignIt = std::find(begin, end, L'=');
+ auto valueBeginsAt = assignSignIt != end ? assignSignIt + 1 : assignSignIt;
+ return parameterHandler(std::wstring(begin, assignSignIt), std::wstring(valueBeginsAt, end));
+ });
+}

Powered by Google App Engine
This is Rietveld