Flutter Engine
file_loader_win.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 
6 
7 #include <iostream>
8 #include <memory>
9 #include <utility>
10 
11 #include "tonic/common/macros.h"
15 
16 namespace tonic {
17 namespace {
18 
19 void FindAndReplaceInPlace(std::string& str,
20  const std::string& findStr,
21  const std::string& replaceStr) {
22  size_t pos = 0;
23  while ((pos = str.find(findStr, pos)) != std::string::npos) {
24  str.replace(pos, findStr.length(), replaceStr);
25  pos += replaceStr.length();
26  }
27 }
28 
29 } // namespace
30 
31 const char FileLoader::kFileURLPrefix[] = "file:///";
33  sizeof(FileLoader::kFileURLPrefix) - 1;
34 const std::string FileLoader::kPathSeparator = "\\";
35 
36 std::string FileLoader::SanitizePath(const std::string& url) {
37  std::string sanitized = url;
38  FindAndReplaceInPlace(sanitized, "/", FileLoader::kPathSeparator);
39  return SanitizeURIEscapedCharacters(sanitized);
40 }
41 
42 std::string FileLoader::CanonicalizeFileURL(const std::string& url) {
43  return SanitizePath(url.substr(FileLoader::kFileURLPrefixLength));
44 }
45 
46 bool FileLoader::ReadFileToString(const std::string& path,
47  std::string* result) {
48  TONIC_DCHECK(dirfd_ == -1);
49  return filesystem::ReadFileToString(path, result);
50 }
51 
52 std::pair<uint8_t*, intptr_t> FileLoader::ReadFileToBytes(
53  const std::string& path) {
54  TONIC_DCHECK(dirfd_ == -1);
55  return filesystem::ReadFileToBytes(path);
56 }
57 
58 } // namespace tonic
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define TONIC_DCHECK
Definition: macros.h:32
std::pair< uint8_t *, intptr_t > ReadFileToBytes(const std::string &path)
Definition: file.cc:94
static const char kFileURLPrefix[]
Definition: file_loader.h:42
static const std::string kPathSeparator
Definition: file_loader.h:44
static const size_t kFileURLPrefixLength
Definition: file_loader.h:43
bool ReadFileToString(const std::string &path, std::string *result)
Definition: file.cc:85