Debian Codegraph @

intl/components/src/ICU4CLibrary.cpp

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "mozilla/intl/ICU4CLibrary.h"
6
7 #include "unicode/putil.h"
8 #include "unicode/uclean.h"
9 #include "unicode/utypes.h"
10 #include "unicode/uversion.h"
11
12 namespace mozilla::intl {
13
14 ICUResult ICU4CLibrary::Initialize() {
15 #if !MOZ_SYSTEM_ICU
16 // Explicitly set the data directory to its default value, but only when we're
17 // sure that we use our in-tree ICU copy. See bug 1527879 and ICU bug
18 // report <https://unicode-org.atlassian.net/browse/ICU-20491>.
19 u_setDataDirectory("");
20 #endif
21
22 UErrorCode status = U_ZERO_ERROR;
23 u_init(&status);
24 return ToICUResult(status);
25 }
26
27 void ICU4CLibrary::Cleanup() { u_cleanup(); }
28
29 ICUResult ICU4CLibrary::SetMemoryFunctions(MemoryFunctions aMemoryFunctions) {
30 UErrorCode status = U_ZERO_ERROR;
31 u_setMemoryFunctions(/* context = */ nullptr, aMemoryFunctions.mAllocFn,
32 aMemoryFunctions.mReallocFn, aMemoryFunctions.mFreeFn,
33 &status);
34 return ToICUResult(status);
35 }
36
37 Span<const char> ICU4CLibrary::GetVersion() {
38 return MakeStringSpan(U_ICU_VERSION);
39 }
40
41 } // namespace mozilla::intl