Flutter Engine
fml::icu::ICUContext Class Reference

Public Member Functions

 ICUContext (const std::string &icu_data_path)
 
 ICUContext (std::unique_ptr< Mapping > mapping)
 
 ~ICUContext ()=default
 
bool SetupMapping (const std::string &icu_data_path)
 
bool SetupICU ()
 
const uint8_t * GetMapping () const
 
size_t GetSize () const
 
bool IsValid () const
 

Detailed Description

Definition at line 20 of file icu_util.cc.

Constructor & Destructor Documentation

◆ ICUContext() [1/2]

fml::icu::ICUContext::ICUContext ( const std::string &  icu_data_path)
inlineexplicit

Definition at line 22 of file icu_util.cc.

References SetupICU(), and SetupMapping().

Referenced by fml::icu::InitializeICUFromMappingOnce(), and fml::icu::InitializeICUOnce().

22  : valid_(false) {
23  valid_ = SetupMapping(icu_data_path) && SetupICU();
24  }
bool SetupMapping(const std::string &icu_data_path)
Definition: icu_util.cc:33

◆ ICUContext() [2/2]

fml::icu::ICUContext::ICUContext ( std::unique_ptr< Mapping mapping)
inlineexplicit

Definition at line 26 of file icu_util.cc.

References SetupICU(), and ~ICUContext().

27  : mapping_(std::move(mapping)) {
28  valid_ = SetupICU();
29  }

◆ ~ICUContext()

fml::icu::ICUContext::~ICUContext ( )
default

Referenced by ICUContext().

Member Function Documentation

◆ GetMapping()

const uint8_t* fml::icu::ICUContext::GetMapping ( ) const
inline

Definition at line 81 of file icu_util.cc.

Referenced by SetupICU().

81  {
82  return mapping_ ? mapping_->GetMapping() : nullptr;
83  }

◆ GetSize()

size_t fml::icu::ICUContext::GetSize ( ) const
inline

Definition at line 85 of file icu_util.cc.

Referenced by SetupICU().

85 { return mapping_ ? mapping_->GetSize() : 0; }

◆ IsValid()

bool fml::icu::ICUContext::IsValid ( ) const
inline

Definition at line 87 of file icu_util.cc.

Referenced by fml::icu::InitializeICUFromMappingOnce(), and fml::icu::InitializeICUOnce().

87 { return valid_; }

◆ SetupICU()

bool fml::icu::ICUContext::SetupICU ( )
inline

Definition at line 71 of file icu_util.cc.

References GetMapping(), and GetSize().

Referenced by ICUContext().

71  {
72  if (GetSize() == 0) {
73  return false;
74  }
75 
76  UErrorCode err_code = U_ZERO_ERROR;
77  udata_setCommonData(GetMapping(), &err_code);
78  return (err_code == U_ZERO_ERROR);
79  }
size_t GetSize() const
Definition: icu_util.cc:85
const uint8_t * GetMapping() const
Definition: icu_util.cc:81

◆ SetupMapping()

bool fml::icu::ICUContext::SetupMapping ( const std::string &  icu_data_path)
inline

Definition at line 33 of file icu_util.cc.

References fml::paths::GetExecutableDirectoryPath(), fml::paths::JoinPaths(), fml::kRead, fml::FileMapping::kRead, and fml::OpenFile().

Referenced by ICUContext().

33  {
34  // Check if the path exists and it readable directly.
35  auto fd =
36  fml::OpenFile(icu_data_path.c_str(), false, fml::FilePermission::kRead);
37 
38  // Check the path relative to the current executable.
39  if (!fd.is_valid()) {
40  auto directory = fml::paths::GetExecutableDirectoryPath();
41 
42  if (!directory.first) {
43  return false;
44  }
45 
46  std::string path_relative_to_executable =
47  paths::JoinPaths({directory.second, icu_data_path});
48 
49  fd = fml::OpenFile(path_relative_to_executable.c_str(), false,
51  }
52 
53  if (!fd.is_valid()) {
54  return false;
55  }
56 
57  std::initializer_list<FileMapping::Protection> protection = {
59 
60  auto file_mapping =
61  std::make_unique<FileMapping>(fd, std::move(protection));
62 
63  if (file_mapping->GetSize() != 0) {
64  mapping_ = std::move(file_mapping);
65  return true;
66  }
67 
68  return false;
69  }
std::pair< bool, std::string > GetExecutableDirectoryPath()
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition: file_posix.cc:64

The documentation for this class was generated from the following file: