tor-browser

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

nsLanguageAtomService.h (1679B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 * The nsILanguageAtomService provides a mapping from languages or charsets
      8 * to language groups, and access to the system locale language.
      9 */
     10 
     11 #ifndef nsLanguageAtomService_h_
     12 #define nsLanguageAtomService_h_
     13 
     14 #include "mozilla/NotNull.h"
     15 #include "mozilla/RefPtr.h"
     16 #include "mozilla/RWLock.h"
     17 #include "mozilla/StaticPtr.h"
     18 #include "nsAtomHashKeys.h"
     19 #include "nsTHashMap.h"
     20 
     21 namespace mozilla {
     22 class Encoding;
     23 }
     24 
     25 class nsLanguageAtomService final {
     26  using Encoding = mozilla::Encoding;
     27  template <typename T>
     28  using NotNull = mozilla::NotNull<T>;
     29 
     30 public:
     31  static nsLanguageAtomService* GetService();
     32 
     33  static void Shutdown();
     34 
     35  nsStaticAtom* LookupLanguage(const nsACString& aLanguage);
     36  nsAtom* GetLocaleLanguage();
     37 
     38  // Returns the language group that the specified language is a part of,
     39  // using a cache to avoid repeatedly doing full lookups.
     40  nsStaticAtom* GetLanguageGroup(nsAtom* aLanguage);
     41 
     42 private:
     43  // The core implementation of lang-tag to language-group lookup. (Now used
     44  // only internally by GetLanguageGroup.)
     45  nsStaticAtom* GetUncachedLanguageGroup(nsAtom* aLanguage) const;
     46 
     47  static mozilla::StaticAutoPtr<nsLanguageAtomService> sLangAtomService;
     48 
     49  nsTHashMap<RefPtr<nsAtom>, nsStaticAtom*> mLangToGroup MOZ_GUARDED_BY(mLock);
     50  RefPtr<nsAtom> mLocaleLanguage MOZ_GUARDED_BY(mLock);
     51 
     52  mozilla::RWLock mLock{"LanguageAtomService"};
     53 };
     54 
     55 #endif