Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
fml
platform
posix
paths_posix.cc
Go to the documentation of this file.
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 <unistd.h>
8
9
#include <climits>
10
11
#include "flutter/fml/logging.h"
12
13
namespace
fml
{
14
namespace
paths {
15
16
namespace
{
17
18
constexpr
char
kFileURLPrefix[] =
"file://"
;
19
constexpr
size_t
kFileURLPrefixLength =
sizeof
(kFileURLPrefix) - 1;
20
21
std::string
GetCurrentDirectory
() {
22
char
buffer
[
PATH_MAX
];
23
FML_CHECK
(getcwd(
buffer
,
sizeof
(
buffer
)));
24
return
std::string(
buffer
);
25
}
26
27
}
// namespace
28
29
std::string
AbsolutePath
(
const
std::string& path) {
30
if
(!path.empty()) {
31
if
(path[0] ==
'/'
) {
32
// Path is already absolute.
33
return
path;
34
}
35
return
GetCurrentDirectory
() +
"/"
+ path;
36
}
else
{
37
// Path is empty.
38
return
GetCurrentDirectory
();
39
}
40
}
41
42
std::string
GetDirectoryName
(
const
std::string& path) {
43
size_t
separator = path.rfind(
'/'
);
44
if
(separator == 0u) {
45
return
"/"
;
46
}
47
if
(separator == std::string::npos) {
48
return
std::string();
49
}
50
return
path.substr(0, separator);
51
}
52
53
std::string
FromURI
(
const
std::string& uri) {
54
if
(uri.substr(0, kFileURLPrefixLength) != kFileURLPrefix) {
55
return
uri;
56
}
57
58
std::string file_path = uri.substr(kFileURLPrefixLength);
59
return
SanitizeURIEscapedCharacters
(file_path);
60
}
61
62
}
// namespace paths
63
}
// namespace fml
buffer
static const uint8_t buffer[]
Definition
fl_pixel_buffer_texture_test.cc:44
FML_CHECK
#define FML_CHECK(condition)
Definition
logging.h:85
fml::paths::AbsolutePath
std::string AbsolutePath(const std::string &path)
Definition
paths_posix.cc:29
fml::paths::SanitizeURIEscapedCharacters
std::string SanitizeURIEscapedCharacters(const std::string &str)
Definition
paths.cc:32
fml::paths::GetDirectoryName
std::string GetDirectoryName(const std::string &path)
Definition
paths_posix.cc:42
fml::paths::FromURI
std::string FromURI(const std::string &uri)
Definition
paths_posix.cc:53
fml
Definition
ascii_trie.cc:9
PATH_MAX
#define PATH_MAX
Definition
globals.h:708
GetCurrentDirectory
#define GetCurrentDirectory
Definition
windows_types.h:259
Generated on Fri Apr 26 2024 06:14:06 for Flutter Engine by
1.9.8