Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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.

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.

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

◆ ~ICUContext()

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

Member Function Documentation

◆ GetMapping()

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

Definition at line 80 of file icu_util.cc.

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

◆ GetSize()

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

Definition at line 84 of file icu_util.cc.

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

◆ IsValid()

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

Definition at line 86 of file icu_util.cc.

86{ return valid_; }

◆ SetupICU()

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

Definition at line 70 of file icu_util.cc.

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

◆ SetupMapping()

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

Definition at line 33 of file icu_util.cc.

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()) {
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 = std::make_unique<FileMapping>(fd, protection);
61
62 if (file_mapping->GetSize() != 0) {
63 mapping_ = std::move(file_mapping);
64 return true;
65 }
66
67 return false;
68 }
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
std::pair< bool, std::string > GetExecutableDirectoryPath()
Definition paths.cc:55
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:66

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