forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.cc
64 lines (56 loc) · 1.48 KB
/
paths.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/paths.h"
#include <sstream>
#include "flutter/fml/build_config.h"
namespace fml {
namespace paths {
std::string JoinPaths(std::initializer_list<std::string> components) {
std::stringstream stream;
size_t i = 0;
const size_t size = components.size();
for (const auto& component : components) {
i++;
stream << component;
if (i != size) {
#if FML_OS_WIN
stream << "\\";
#else // FML_OS_WIN
stream << "/";
#endif // FML_OS_WIN
}
}
return stream.str();
}
std::string SanitizeURIEscapedCharacters(const std::string& str) {
std::string result;
result.reserve(str.size());
for (std::string::size_type i = 0; i < str.size(); ++i) {
if (str[i] == '%') {
if (i > str.size() - 3 || !isxdigit(str[i + 1]) ||
!isxdigit(str[i + 2])) {
return "";
}
const std::string hex = str.substr(i + 1, 2);
const unsigned char c = strtoul(hex.c_str(), nullptr, 16);
if (!c) {
return "";
}
result += c;
i += 2;
} else {
result += str[i];
}
}
return result;
}
std::pair<bool, std::string> GetExecutableDirectoryPath() {
auto path = GetExecutablePath();
if (!path.first) {
return {false, ""};
}
return {true, fml::paths::GetDirectoryName(path.second)};
}
} // namespace paths
} // namespace fml