author Raymond Etornam Agbeame(:retornam) <>
Thu, 22 Jan 2015 16:02:30 -0800
changeset 225501 f4ddeae5b6c4b5bfda50066386133e4346697e94
parent 202895 0c07ef5e87c084c4bbf81ee6f71cc0f4ca03e49c
child 266255 05f45d36851d49c7874a2b478a0299673ac298bb
permissions -rw-r--r--
Bug 1109235 - remove nsIStreamCipher and implementation r=keeler

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 */

#ifndef mozilla_ICUUtils_h__
#define mozilla_ICUUtils_h__

// We only build the ICU utils if we're building ICU:

// The ICU utils implementation needs internal things like XPCOM strings and
// nsGkAtom, so we only build when included into internal libs:

#include "mozilla/Scoped.h"
#include "nsStringGlue.h"
#include "unicode/unum.h" // for UNumberFormat

class nsIContent;

namespace {
  struct ScopedUNumberFormatTraits {
    typedef UNumberFormat* type;
    static type empty() { return nullptr; }
    static void release(type handle) { if (handle) unum_close(handle); }
typedef mozilla::Scoped<ScopedUNumberFormatTraits> AutoCloseUNumberFormat;

class ICUUtils

   * This class is used to encapsulate an nsIContent object to allow lazy
   * iteration over its primary and fallback BCP 47 language tags.
  class LanguageTagIterForContent {
    explicit LanguageTagIterForContent(nsIContent* aContent)
      : mContent(aContent)
      , mCurrentFallbackIndex(-1)

     * Used to iterate over the nsIContent object's primary language tag and
     * its fallbacks tags. The following sources of language tag information
     * are tried in turn:
     * 1) the "lang" of the nsIContent object (which is based on the 'lang'/
     *    'xml:lang' attribute on itself or the nearest ancestor to have such
     *    an attribute, if any);
     * 2) the Content-Language HTTP pragma directive or HTTP header;
     * 3) the configured language tag of the user-agent.
     * Once all fallbacks have been exhausted then this function will set
     * aBCP47LangTag to the empty string.
    void GetNext(nsACString& aBCP47LangTag);

    bool IsAtStart() const {
      return mCurrentFallbackIndex < 0;

    nsIContent* mContent;
    int8_t mCurrentFallbackIndex;

   * Attempts to localize aValue and return the result via the aLocalizedValue
   * outparam. Returns true on success. Returns false on failure, in which
   * case aLocalizedValue will be untouched.
  static bool LocalizeNumber(double aValue,
                             LanguageTagIterForContent& aLangTags,
                             nsAString& aLocalizedValue);

   * Parses the localized number that is serialized in aValue using aLangTags
   * and returns the result as a double. Returns NaN on failure.
  static double ParseNumber(nsAString& aValue,
                            LanguageTagIterForContent& aLangTags);

  static void AssignUCharArrayToString(UChar* aICUString,
                                       int32_t aLength,
                                       nsAString& aMozString);

#if 0
  // Currently disabled because using C++ API doesn't play nicely with enabling
  // system ICU.

   * Converts an IETF BCP 47 language code to an ICU Locale.
  static Locale BCP47CodeToLocale(const nsAString& aBCP47Code);

  static void ToMozString(UnicodeString& aICUString, nsAString& aMozString);
  static void ToICUString(nsAString& aMozString, UnicodeString& aICUString);

#endif /* ENABLE_INTL_API */

#endif /* mozilla_ICUUtils_h__ */