1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "flutter/fml/paths.h" 6 7 #include <sstream> 8 9 #include "flutter/fml/build_config.h" 10 11 namespace fml { 12 namespace paths { 13 JoinPaths(std::initializer_list<std::string> components)14std::string JoinPaths(std::initializer_list<std::string> components) { 15 std::stringstream stream; 16 size_t i = 0; 17 const size_t size = components.size(); 18 for (const auto& component : components) { 19 i++; 20 stream << component; 21 if (i != size) { 22 #if OS_WIN 23 stream << "\\"; 24 #else // OS_WIN 25 stream << "/"; 26 #endif // OS_WIN 27 } 28 } 29 return stream.str(); 30 } 31 SanitizeURIEscapedCharacters(const std::string & str)32std::string SanitizeURIEscapedCharacters(const std::string& str) { 33 std::string result; 34 result.reserve(str.size()); 35 for (std::string::size_type i = 0; i < str.size(); ++i) { 36 if (str[i] == '%') { 37 if (i > str.size() - 3 || !isxdigit(str[i + 1]) || !isxdigit(str[i + 2])) 38 return ""; 39 const std::string hex = str.substr(i + 1, 2); 40 const unsigned char c = strtoul(hex.c_str(), nullptr, 16); 41 if (!c) 42 return ""; 43 result += c; 44 i += 2; 45 } else { 46 result += str[i]; 47 } 48 } 49 return result; 50 } 51 52 } // namespace paths 53 } // namespace fml 54