tor-browser

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

nsHyphenator.h (1751B)


      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 #ifndef nsHyphenator_h__
      7 #define nsHyphenator_h__
      8 
      9 #include "mozilla/ipc/SharedMemoryHandle.h"
     10 #include "mozilla/ipc/SharedMemoryMapping.h"
     11 #include "mozilla/Span.h"
     12 #include "mozilla/UniquePtr.h"
     13 #include "mozilla/Variant.h"
     14 #include "nsCOMPtr.h"
     15 #include "nsString.h"
     16 #include "nsTArray.h"
     17 
     18 class nsIURI;
     19 struct HyphDic;
     20 struct CompiledData;
     21 
     22 namespace std {
     23 template <>
     24 struct default_delete<const HyphDic> {
     25  void operator()(const HyphDic* ptr) const;
     26 };
     27 
     28 template <>
     29 struct default_delete<const CompiledData> {
     30  void operator()(const CompiledData* ptr) const;
     31 };
     32 }  // namespace std
     33 
     34 class nsHyphenator {
     35 public:
     36  nsHyphenator(nsIURI* aURI, bool aHyphenateCapitalized);
     37 
     38  NS_INLINE_DECL_REFCOUNTING(nsHyphenator)
     39 
     40  bool IsValid();
     41 
     42  nsresult Hyphenate(const nsAString& aText, nsTArray<bool>& aHyphens);
     43 
     44  mozilla::ipc::ReadOnlySharedMemoryHandle CloneHandle();
     45 
     46 private:
     47  ~nsHyphenator() = default;
     48 
     49  void HyphenateWord(const nsAString& aString, uint32_t aStart, uint32_t aLimit,
     50                     nsTArray<bool>& aHyphens);
     51 
     52  mozilla::Variant<
     53      mozilla::Span<const uint8_t>,  // raw pointer to uncompressed omnijar data
     54      mozilla::ipc::ReadOnlySharedMemoryHandle,   // shmem handle, in the parent
     55      mozilla::ipc::ReadOnlySharedMemoryMapping,  // mapped shmem, in the child
     56      mozilla::UniquePtr<const HyphDic>           // loaded by mapped_hyph
     57      >
     58      mDict;
     59  bool mHyphenateCapitalized;
     60 };
     61 
     62 #endif  // nsHyphenator_h__