Flutter Engine
fml::paths Namespace Reference

Functions

std::string JoinPaths (std::initializer_list< std::string > components)
 
std::string SanitizeURIEscapedCharacters (const std::string &str)
 
std::pair< bool, std::string > GetExecutableDirectoryPath ()
 
fml::UniqueFD GetCachesDirectory ()
 
std::string AbsolutePath (const std::string &path)
 
std::string GetDirectoryName (const std::string &path)
 
std::string FromURI (const std::string &uri)
 
void InitializeAndroidCachesPath (std::string caches_path)
 

Variables

static std::string gCachesPath
 

Function Documentation

◆ AbsolutePath()

std::string fml::paths::AbsolutePath ( const std::string &  path)

Definition at line 29 of file paths_posix.cc.

References flutter::path.

Referenced by flutter::RunTester().

29  {
30  if (path.size() > 0) {
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 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32

◆ FromURI()

std::string fml::paths::FromURI ( const std::string &  uri)

Definition at line 53 of file paths_posix.cc.

References SanitizeURIEscapedCharacters().

Referenced by flutter::ServiceProtocolFailureError().

53  {
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 }
std::string SanitizeURIEscapedCharacters(const std::string &str)
Definition: paths.cc:32

◆ GetCachesDirectory()

fml::UniqueFD fml::paths::GetCachesDirectory ( )

Definition at line 22 of file paths_android.cc.

References fml::kRead, and fml::OpenDirectory().

Referenced by flutter::PersistentCache::Purge().

22  {
23  // If the caches path is not initialized, the FD will be invalid and caching
24  // will be disabled throughout the system.
26 }
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:94
static std::string gCachesPath

◆ GetDirectoryName()

std::string fml::paths::GetDirectoryName ( const std::string &  path)

Definition at line 42 of file paths_posix.cc.

42  {
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 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32

◆ GetExecutableDirectoryPath()

std::pair< bool, std::string > fml::paths::GetExecutableDirectoryPath ( )

Definition at line 12 of file paths_android.cc.

Referenced by fml::icu::ICUContext::SetupMapping().

12  {
13  return {false, ""};
14 }

◆ InitializeAndroidCachesPath()

void fml::paths::InitializeAndroidCachesPath ( std::string  caches_path)

Definition at line 18 of file paths_android.cc.

Referenced by flutter::FlutterMain::GetSettings().

18  {
19  gCachesPath = std::move(caches_path);
20 }
static std::string gCachesPath

◆ JoinPaths()

std::string fml::paths::JoinPaths ( std::initializer_list< std::string >  components)

Definition at line 14 of file paths.cc.

References fml::size().

Referenced by FlutterEngineInitialize(), flutter::testing::ImageMatchesFixture(), flutter::testing::LoadELFSymbolFromFixturesIfNeccessary(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), flutter::DartCallbackCache::SetCachePath(), flutter::SettingsFromCommandLine(), flutter::testing::EmbedderTestContext::SetupAOTDataIfNecessary(), fml::icu::ICUContext::SetupMapping(), TEST(), and flutter::testing::TEST_F().

14  {
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 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ SanitizeURIEscapedCharacters()

std::string fml::paths::SanitizeURIEscapedCharacters ( const std::string &  str)

Definition at line 32 of file paths.cc.

Referenced by FromURI(), and TEST().

32  {
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 }

Variable Documentation

◆ gCachesPath

std::string fml::paths::gCachesPath
static

Definition at line 16 of file paths_android.cc.