Debian Codegraph @

intl/components/src/NumberingSystem.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/NumberingSystem.h"
6 #include "mozilla/intl/ICU4CGlue.h"
7
8 #include "unicode/unumsys.h"
9 #include "unicode/utypes.h"
10
11 namespace mozilla::intl {
12
13 NumberingSystem::~NumberingSystem() {
14 MOZ_ASSERT(mNumberingSystem);
15 unumsys_close(mNumberingSystem);
16 }
17
18 Result<UniquePtr<NumberingSystem>, ICUError> NumberingSystem::TryCreate(
19 const char* aLocale) {
20 UErrorCode status = U_ZERO_ERROR;
21 UNumberingSystem* numbers = unumsys_open(IcuLocale(aLocale), &status);
22 if (U_FAILURE(status)) {
23 return Err(ToICUError(status));
24 }
25
26 return MakeUnique<NumberingSystem>(numbers);
27 }
28
29 Result<Span<const char>, ICUError> NumberingSystem::GetName() {
30 const char* name = unumsys_getName(mNumberingSystem);
31 if (!name) {
32 return Err(ICUError::InternalError);
33 }
34
35 return MakeStringSpan(name);
36 }
37
38 } // namespace mozilla::intl