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
11namespace fml {
12namespace paths {
13
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
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]) ||
38 !isxdigit(str[i + 2])) {
39 return "";
40 }
41 const std::string hex = str.substr(i + 1, 2);
42 const unsigned char c = strtoul(hex.c_str(), nullptr, 16);
43 if (!c) {
44 return "";
45 }
46 result += c;
47 i += 2;
48 } else {
49 result += str[i];
50 }
51 }
52 return result;
53}
54
55} // namespace paths
56} // namespace fml
57