OLD | NEW |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 ADBLOCK_PLUS_UTILS_H | 18 #ifndef ADBLOCK_PLUS_UTILS_H |
19 #define ADBLOCK_PLUS_UTILS_H | 19 #define ADBLOCK_PLUS_UTILS_H |
20 | 20 |
21 #include <algorithm> | 21 #include <algorithm> |
22 #include <cctype> | 22 #include <cctype> |
23 #include <functional> | 23 #include <functional> |
24 #include <istream> | 24 #include <istream> |
25 #include <string> | 25 #include <string> |
| 26 #include <vector> |
26 #include <v8.h> | 27 #include <v8.h> |
27 | 28 |
28 namespace AdblockPlus | 29 namespace AdblockPlus |
29 { | 30 { |
30 namespace Utils | 31 namespace Utils |
31 { | 32 { |
32 std::string Slurp(std::istream& stream); | |
33 std::string FromV8String(const v8::Handle<v8::Value>& value); | 33 std::string FromV8String(const v8::Handle<v8::Value>& value); |
| 34 std::vector<char> BufferFromV8String(const v8::Handle<v8::Value>& value); |
34 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const std::string& st
r); | 35 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const std::string& st
r); |
| 36 v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const std::vector<cha
r>& bytes); |
35 void ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str); | 37 void ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str); |
36 | 38 |
37 // Code for templated function has to be in a header file, can't be in .cpp | 39 // Code for templated function has to be in a header file, can't be in .cpp |
38 template<class T> | 40 template<class T> |
39 T TrimString(const T& text) | 41 T TrimString(const T& text) |
40 { | 42 { |
41 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-tri
m-stdstring | 43 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-tri
m-stdstring |
42 T trimmed(text); | 44 T trimmed(text); |
43 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end()
, std::not1(std::ptr_fun<int, int>(std::isspace)))); | 45 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end()
, std::not1(std::ptr_fun<int, int>(std::isspace)))); |
44 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std
::ptr_fun<int, int>(std::isspace))).base(), trimmed.end()); | 46 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std
::ptr_fun<int, int>(std::isspace))).base(), trimmed.end()); |
45 return trimmed; | 47 return trimmed; |
46 } | 48 } |
47 #ifdef _WIN32 | 49 #ifdef _WIN32 |
48 std::wstring ToUtf16String(const std::string& str); | 50 std::wstring ToUtf16String(const std::string& str); |
49 std::string ToUtf8String(const std::wstring& str); | 51 std::string ToUtf8String(const std::wstring& str); |
50 std::wstring CanonizeUrl(const std::wstring& url); | 52 std::wstring CanonizeUrl(const std::wstring& url); |
51 #endif | 53 #endif |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 #endif | 57 #endif |
OLD | NEW |