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

Side by Side Diff: src/shared/Utils.h

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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 bool IsWindowsVistaOrLater(); 50 bool IsWindowsVistaOrLater();
51 bool IsWindows8OrLater(); 51 bool IsWindows8OrLater();
52 52
53 std::string ToUtf8String(const std::wstring& str); 53 std::string ToUtf8String(const std::wstring& str);
54 std::wstring ToUtf16String(const std::string& str); 54 std::wstring ToUtf16String(const std::string& str);
55 std::wstring GetDllDir(); 55 std::wstring GetDllDir();
56 std::wstring GetAppDataPath(); 56 std::wstring GetAppDataPath();
57 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement); 57 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement);
58 58
59 /**
60 * Returns the begging of the URL which includes the scheme and hierarchical
61 * part according to http://en.wikipedia.org/wiki/URI_scheme .
62 */
63 std::wstring GetSchemeAndHierarchicalPart(const std::wstring& url);
64
65 std::wstring GetQueryString(const std::wstring& url);
66 /**
67 * Splits a string into tokens separated by a delimiter.
68 * Applies a function to each token.
69 * Terminates early if the function returns false.
70 */
71 void ForEachToken(const std::wstring& value, wchar_t delimiter,
72 const std::function<bool(std::wstring::const_iterator begin, std::wstring::con st_iterator end)>& fn);
73
74 /**
75 * Applies a function to each name=value pair in a query string.
76 * Terminates early if the function returns false.
77 */
78 void ForEachQueryStringParameter(const std::wstring& urlQueryString,
79 const std::function<bool(const std::wstring& name, const std::wstring& value)> & fn);
80
59 template<class T> 81 template<class T>
60 T TrimString(T text) 82 T TrimString(T text)
61 { 83 {
62 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring 84 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring
63 T trimmed(text); 85 T trimmed(text);
64 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic()); 86 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic());
65 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace))); 87 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace)));
66 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end()); 88 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end());
67 return trimmed; 89 return trimmed;
68 } 90 }
69 91
70 #endif // UTILS_H 92 #endif // UTILS_H
OLDNEW

Powered by Google App Engine
This is Rietveld