| LEFT | RIGHT |
| 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 #include <sstream> | |
| 19 #include <stdexcept> | 18 #include <stdexcept> |
| 20 | 19 |
| 21 #ifdef _WIN32 | 20 #ifdef _WIN32 |
| 22 #include <Windows.h> | 21 #include <Windows.h> |
| 23 #include <Shlwapi.h> | 22 #include <Shlwapi.h> |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 #include "Utils.h" | 25 #include "Utils.h" |
| 27 | 26 |
| 28 using namespace AdblockPlus; | 27 using namespace AdblockPlus; |
| 29 | 28 |
| 30 std::string Utils::FromV8String(const v8::Handle<v8::Value>& value) | 29 std::string Utils::FromV8String(const v8::Handle<v8::Value>& value) |
| 31 { | 30 { |
| 32 v8::String::Utf8Value stringValue(value); | 31 v8::String::Utf8Value stringValue(value); |
| 33 if (stringValue.length()) | 32 if (stringValue.length()) |
| 34 return std::string(*stringValue, stringValue.length()); | 33 return std::string(*stringValue, stringValue.length()); |
| 35 else | 34 else |
| 36 return std::string(); | 35 return std::string(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 std::vector<char> Utils::BufferFromV8String(const v8::Handle<v8::Value>& value) | 38 StringBuffer Utils::StringBufferFromV8String(const v8::Handle<v8::Value>& value) |
| 40 { | 39 { |
| 41 v8::String::Utf8Value stringValue(value); | 40 v8::String::Utf8Value stringValue(value); |
| 42 if (stringValue.length()) | 41 if (stringValue.length()) |
| 43 return std::vector<char>(*stringValue, *stringValue + stringValue.length()); | 42 return IFileSystem::IOBuffer(*stringValue, *stringValue + stringValue.length
()); |
| 44 else | 43 else |
| 45 return std::vector<char>(); | 44 return IFileSystem::IOBuffer(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 v8::Local<v8::String> Utils::ToV8String(v8::Isolate* isolate, const std::string&
str) | 47 v8::Local<v8::String> Utils::ToV8String(v8::Isolate* isolate, const std::string&
str) |
| 49 { | 48 { |
| 50 return v8::String::NewFromUtf8(isolate, str.c_str(), | 49 return v8::String::NewFromUtf8(isolate, str.c_str(), |
| 51 v8::String::NewStringType::kNormalString, str.length()); | 50 v8::String::NewStringType::kNormalString, str.length()); |
| 52 } | 51 } |
| 53 | 52 |
| 54 v8::Local<v8::String> Utils::ToV8String(v8::Isolate* isolate, const std::vector<
char>& str) | 53 v8::Local<v8::String> Utils::StringBufferToV8String(v8::Isolate* isolate, const
StringBuffer& str) |
| 55 { | 54 { |
| 56 return v8::String::NewFromUtf8(isolate, str.data(), | 55 return v8::String::NewFromUtf8(isolate, |
| 56 reinterpret_cast<const char*>(str.data()), |
| 57 v8::String::NewStringType::kNormalString, str.size()); | 57 v8::String::NewStringType::kNormalString, str.size()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Utils::ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str) | 60 void Utils::ThrowExceptionInJS(v8::Isolate* isolate, const std::string& str) |
| 61 { | 61 { |
| 62 isolate->ThrowException(Utils::ToV8String(isolate, str)); | 62 isolate->ThrowException(Utils::ToV8String(isolate, str)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 #ifdef _WIN32 | 65 #ifdef _WIN32 |
| 66 std::wstring Utils::ToUtf16String(const std::string& str) | 66 std::wstring Utils::ToUtf16String(const std::string& str) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (FAILED(hr)) | 109 if (FAILED(hr)) |
| 110 { | 110 { |
| 111 throw std::runtime_error("CanonizeUrl failed\n"); | 111 throw std::runtime_error("CanonizeUrl failed\n"); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 return canonizedUrl; | 114 return canonizedUrl; |
| 115 | 115 |
| 116 } | 116 } |
| 117 #endif | 117 #endif |
| 118 | 118 |
| LEFT | RIGHT |