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

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

Issue 29332484: Noissue - Add conversion function from 'BSTR' to 'std::wstring' (Closed)
Patch Set: Created Dec. 9, 2015, 1:11 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
« no previous file with comments | « adblockplus.gyp ('k') | src/shared/Utils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef UTILS_H 18 #ifndef UTILS_H
19 #define UTILS_H 19 #define UTILS_H
20 20
21 #include <algorithm> 21 #include <algorithm>
22 #include <locale> 22 #include <locale>
23 #include <functional> 23 #include <functional>
24 #include <string> 24 #include <string>
25 #include <vector> 25 #include <vector>
26 #include <wtypes.h>
26 27
27 #define WM_ALREADY_UP_TO_DATE WM_APP+1 28 #define WM_ALREADY_UP_TO_DATE WM_APP+1
28 #define WM_UPDATE_CHECK_ERROR WM_APP+2 29 #define WM_UPDATE_CHECK_ERROR WM_APP+2
29 #define WM_DOWNLOADING_UPDATE WM_APP+3 30 #define WM_DOWNLOADING_UPDATE WM_APP+3
30 31
31 // 32 //
32 // Application Package Authority. 33 // Application Package Authority.
33 // 34 //
34 35
35 #define SECURITY_APP_PACKAGE_AUTHORITY {0,0,0,0,0,15} 36 #define SECURITY_APP_PACKAGE_AUTHORITY {0,0,0,0,0,15}
36 37
37 #define SECURITY_APP_PACKAGE_BASE_RID (0x00000002L) 38 #define SECURITY_APP_PACKAGE_BASE_RID (0x00000002L)
38 #define SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT (2L) 39 #define SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT (2L)
39 #define SECURITY_APP_PACKAGE_RID_COUNT (8L) 40 #define SECURITY_APP_PACKAGE_RID_COUNT (8L)
40 #define SECURITY_CAPABILITY_BASE_RID (0x00000003L) 41 #define SECURITY_CAPABILITY_BASE_RID (0x00000003L)
41 #define SECURITY_BUILTIN_CAPABILITY_RID_COUNT (2L) 42 #define SECURITY_BUILTIN_CAPABILITY_RID_COUNT (2L)
42 #define SECURITY_CAPABILITY_RID_COUNT (5L) 43 #define SECURITY_CAPABILITY_RID_COUNT (5L)
43 44
44 // 45 //
45 // Built-in Packages. 46 // Built-in Packages.
46 // 47 //
47 48
48 #define SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE (0x00000001L) 49 #define SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE (0x00000001L)
49 50
50 51
51 bool IsWindowsVistaOrLater(); 52 bool IsWindowsVistaOrLater();
52 bool IsWindows8OrLater(); 53 bool IsWindows8OrLater();
53 54
55 std::wstring ToWstring(const BSTR b);
54 std::string ToUtf8String(const std::wstring& str); 56 std::string ToUtf8String(const std::wstring& str);
55 std::wstring ToUtf16String(const std::string& str); 57 std::wstring ToUtf16String(const std::string& str);
56 std::vector<std::wstring> ToUtf16Strings(const std::vector<std::string>& value); 58 std::vector<std::wstring> ToUtf16Strings(const std::vector<std::string>& value);
57 std::wstring GetDllDir(); 59 std::wstring GetDllDir();
58 std::wstring GetExeDir(); 60 std::wstring GetExeDir();
59 std::wstring GetAppDataPath(); 61 std::wstring GetAppDataPath();
60 void ReplaceString(std::wstring& input, const std::wstring& placeholder, const s td::wstring& replacement); 62 void ReplaceString(std::wstring& input, const std::wstring& placeholder, const s td::wstring& replacement);
61 63
62 /** 64 /**
63 * Returns the beginning of the URL which includes the scheme and hierarchical 65 * Returns the beginning of the URL which includes the scheme and hierarchical
64 * part according to http://en.wikipedia.org/wiki/URI_scheme. 66 * part according to http://en.wikipedia.org/wiki/URI_scheme.
65 */ 67 */
66 std::wstring GetSchemeAndHierarchicalPart(const std::wstring& url); 68 std::wstring GetSchemeAndHierarchicalPart(const std::wstring& url);
67 69
68 std::wstring GetQueryString(const std::wstring& url); 70 std::wstring GetQueryString(const std::wstring& url);
69 71
70 template<class T> 72 template<class T>
71 T TrimString(T text) 73 T TrimString(T text)
72 { 74 {
73 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring 75 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring
74 T trimmed(text); 76 T trimmed(text);
75 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic()); 77 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic());
76 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace))); 78 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace)));
77 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end()); 79 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end());
78 return trimmed; 80 return trimmed;
79 } 81 }
80 82
81 #endif // UTILS_H 83 #endif // UTILS_H
OLDNEW
« no previous file with comments | « adblockplus.gyp ('k') | src/shared/Utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld