tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NumberParser.h (1382B)


      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 #ifndef intl_components_NumberParser_h_
      5 #define intl_components_NumberParser_h_
      6 
      7 #include "mozilla/intl/ICUError.h"
      8 #include "mozilla/intl/ICU4CGlue.h"
      9 #include "mozilla/Span.h"
     10 #include "mozilla/UniquePtr.h"
     11 
     12 #include "unicode/unum.h"
     13 
     14 namespace mozilla::intl {
     15 
     16 class NumberParser {
     17 public:
     18  /**
     19   * Initialize a new NumberParser for the provided locale and using the
     20   * provided options.
     21   */
     22  static Result<UniquePtr<NumberParser>, ICUError> TryCreate(
     23      std::string_view aLocale, bool aUseGrouping);
     24 
     25  NumberParser() : mNumberFormat(nullptr) {};
     26  NumberParser(const NumberParser&) = delete;
     27  NumberParser& operator=(const NumberParser&) = delete;
     28  ~NumberParser();
     29 
     30  /**
     31   * Attempts to parse a string representing a double, returning the parsed
     32   * double and the parse position if successful, or an error.
     33   *
     34   * The parse position is the index into the input string where parsing
     35   * stopped because an non-numeric character was encountered.
     36   */
     37  Result<std::pair<double, int32_t>, ICUError> ParseDouble(
     38      Span<const char16_t> aDouble) const;
     39 
     40 private:
     41  ICUPointer<UNumberFormat> mNumberFormat;
     42 };
     43 
     44 }  // namespace mozilla::intl
     45 
     46 #endif