NumberingSystem.h (1581B)
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 #ifndef intl_components_NumberingSystem_h_ 6 #define intl_components_NumberingSystem_h_ 7 8 #include "mozilla/intl/ICUError.h" 9 #include "mozilla/Result.h" 10 #include "mozilla/Span.h" 11 #include "mozilla/UniquePtr.h" 12 13 struct UNumberingSystem; 14 15 namespace mozilla::intl { 16 17 /** 18 * This component is a Mozilla-focused API for working with numbering systems in 19 * internationalization code. It is used in coordination with other operations 20 * such as number formatting. 21 */ 22 class NumberingSystem final { 23 public: 24 explicit NumberingSystem(UNumberingSystem* aNumberingSystem) 25 : mNumberingSystem(aNumberingSystem) { 26 MOZ_ASSERT(aNumberingSystem); 27 }; 28 29 // Do not allow copy as this class owns the ICU resource. Move is not 30 // currently implemented, but a custom move operator could be created if 31 // needed. 32 NumberingSystem(const NumberingSystem&) = delete; 33 NumberingSystem& operator=(const NumberingSystem&) = delete; 34 35 ~NumberingSystem(); 36 37 /** 38 * Create a NumberingSystem. 39 */ 40 static Result<UniquePtr<NumberingSystem>, ICUError> TryCreate( 41 const char* aLocale); 42 43 /** 44 * Returns the name of this numbering system. 45 * 46 * The returned string has the same lifetime as this NumberingSystem object. 47 */ 48 Result<Span<const char>, ICUError> GetName(); 49 50 private: 51 UNumberingSystem* mNumberingSystem = nullptr; 52 }; 53 54 } // namespace mozilla::intl 55 56 #endif