tor-browser

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

mozHunspellRLBoxSandbox.cpp (2185B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozHunspellRLBoxSandbox.h"
      8 #include "mozHunspellRLBoxGlue.h"
      9 
     10 FileMgr::FileMgr(const char* aFilename, const char* aKey) : mFd(0) {
     11  // The key is not used in firefox
     12  mFd = moz_glue_hunspell_create_filemgr(aFilename);
     13 }
     14 
     15 bool FileMgr::getline(std::string& aResult) {
     16  char* line = nullptr;
     17  bool ok = moz_glue_hunspell_get_line(mFd, &line);
     18  if (ok && line) {
     19    aResult = line;
     20    free(line);
     21  }
     22  return ok;
     23 }
     24 
     25 int FileMgr::getlinenum() const { return moz_glue_hunspell_get_line_num(mFd); }
     26 
     27 FileMgr::~FileMgr() { moz_glue_hunspell_destruct_filemgr(mFd); }
     28 
     29 // Glue code to set global callbacks
     30 
     31 hunspell_create_filemgr_t* moz_glue_hunspell_create_filemgr = nullptr;
     32 hunspell_get_line_t* moz_glue_hunspell_get_line = nullptr;
     33 hunspell_get_line_num_t* moz_glue_hunspell_get_line_num = nullptr;
     34 hunspell_destruct_filemgr_t* moz_glue_hunspell_destruct_filemgr = nullptr;
     35 hunspell_ToUpperCase_t* moz_hunspell_ToUpperCase = nullptr;
     36 hunspell_ToLowerCase_t* moz_hunspell_ToLowerCase = nullptr;
     37 hunspell_get_current_cs_t* moz_hunspell_GetCurrentCS = nullptr;
     38 
     39 void RegisterHunspellCallbacks(
     40    hunspell_create_filemgr_t* aHunspellCreateFilemgr,
     41    hunspell_get_line_t* aHunspellGetLine,
     42    hunspell_get_line_num_t* aHunspellGetLine_num,
     43    hunspell_destruct_filemgr_t* aHunspellDestructFilemgr,
     44    hunspell_ToUpperCase_t* aHunspellToUpperCase,
     45    hunspell_ToLowerCase_t* aHunspellToLowerCase,
     46    hunspell_get_current_cs_t* aHunspellGetCurrentCS) {
     47  moz_glue_hunspell_create_filemgr = aHunspellCreateFilemgr;
     48  moz_glue_hunspell_get_line = aHunspellGetLine;
     49  moz_glue_hunspell_get_line_num = aHunspellGetLine_num;
     50  moz_glue_hunspell_destruct_filemgr = aHunspellDestructFilemgr;
     51  moz_hunspell_ToUpperCase = aHunspellToUpperCase;
     52  moz_hunspell_ToLowerCase = aHunspellToLowerCase;
     53  moz_hunspell_GetCurrentCS = aHunspellGetCurrentCS;
     54 }