blob: 67cd1e205faac47d2022c69bec5a8fda1d079313 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef intl_components_ICU4CLibrary_h
#define intl_components_ICU4CLibrary_h
#include "mozilla/intl/ICU4CGlue.h"
#include "mozilla/Span.h"
#include <stddef.h>
namespace mozilla::intl {
/**
* Wrapper around non-portable, ICU4C specific functions.
*/
class ICU4CLibrary final {
public:
ICU4CLibrary() = delete;
/**
* Initializes the ICU4C library.
*
* Note: This function should only be called once.
*/
static ICUResult Initialize();
/**
* Releases any memory held by ICU. Any open ICU objects and resources are
* left in an undefined state after this operation.
*
* NOTE: This function is not thread-safe.
*/
static void Cleanup();
struct MemoryFunctions {
// These are equivalent to ICU's |UMemAllocFn|, |UMemReallocFn|, and
// |UMemFreeFn| types. The first argument (called |context| in the ICU
// docs) will always be nullptr and should be ignored.
using AllocFn = void* (*)(const void*, size_t);
using ReallocFn = void* (*)(const void*, void*, size_t);
using FreeFn = void (*)(const void*, void*);
/**
* Function called when allocating memory.
*/
AllocFn mAllocFn = nullptr;
/**
* Function called when reallocating memory.
*/
ReallocFn mReallocFn = nullptr;
/**
* Function called when freeing memory.
*/
FreeFn mFreeFn = nullptr;
};
/**
* Sets the ICU memory functions.
*
* This function can only be called before the initial call to Initialize()!
*/
static ICUResult SetMemoryFunctions(MemoryFunctions aMemoryFunctions);
/**
* Return the ICU version number.
*/
static Span<const char> GetVersion();
};
} // namespace mozilla::intl
#endif
|