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

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

Issue 29331055: Issue #1234 - Remove 'CString' from PluginFilter.* (Closed)
Patch Set: remove TokenSequence Created Feb. 4, 2016, 7:48 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 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);
63 63
64 /** 64 /**
65 * 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
66 * part according to http://en.wikipedia.org/wiki/URI_scheme. 66 * part according to http://en.wikipedia.org/wiki/URI_scheme.
67 */ 67 */
68 std::wstring GetSchemeAndHierarchicalPart(const std::wstring& url); 68 std::wstring GetSchemeAndHierarchicalPart(const std::wstring& url);
69 69
70 std::wstring GetQueryString(const std::wstring& url); 70 std::wstring GetQueryString(const std::wstring& url);
71 71
72 /*
73 * The method used below for trimming strings is taken from here:
74 * http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstr ing
75 */
76 template<class C>
77 bool isNotWhitespace(C x)
78 {
79 return !std::isspace(x, std::locale::classic());
80 };
81
82 template<class T>
83 void TrimStringInPlaceLeft(T& text)
84 {
85 text.erase(text.begin(), std::find_if(text.begin(), text.end(), isNotWhitespac e<T::value_type>));
sergei 2016/05/02 14:33:48 Does it compile? I expect "typename" before "T::va
Eric 2016/05/17 19:30:38 Of course it compiles. Do _you_ post code to revie
86 }
87
88 template<class T>
89 void TrimStringInPlaceRight(T& text)
90 {
91 text.erase(std::find_if(text.rbegin(), text.rend(), isNotWhitespace<T::value_t ype>).base(), text.end());
92 }
93
94 template<class T>
95 void TrimStringInPlace(T& text)
96 {
97 TrimStringInPlaceRight(text);
98 TrimStringInPlaceLeft(text);
99 }
100
101 template<class T>
102 T TrimStringLeft(T text)
103 {
104 TrimStringInPlaceLeft(text);
105 return text;
106 }
107
108 template<class T>
109 T TrimStringRight(T text)
110 {
111 TrimStringInPlaceRight(text);
112 return text;
113 }
114
72 template<class T> 115 template<class T>
73 T TrimString(T text) 116 T TrimString(T text)
74 { 117 {
75 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring 118 TrimStringInPlaceRight(text);
76 T trimmed(text); 119 TrimStringInPlaceLeft(text);
77 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic()); 120 return text;
78 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace)));
79 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end());
80 return trimmed;
81 } 121 }
82 122
83 #endif // UTILS_H 123 #endif // UTILS_H
OLDNEW

Powered by Google App Engine
This is Rietveld