tor-browser

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

bug1653659.patch (5365B)


      1 diff --git a/src/csutil.cxx b/src/csutil.cxx
      2 --- a/src/csutil.cxx
      3 +++ b/src/csutil.cxx
      4 @@ -90,21 +90,17 @@
      5 #else
      6 #ifndef MOZILLA_CLIENT
      7 #include "utf_info.hxx"
      8 #define UTF_LST_LEN (sizeof(utf_lst) / (sizeof(unicode_info)))
      9 #endif
     10 #endif
     11 
     12 #ifdef MOZILLA_CLIENT
     13 -#include "nsCOMPtr.h"
     14 -#include "nsUnicharUtils.h"
     15 -#include "mozilla/Encoding.h"
     16 -
     17 -using namespace mozilla;
     18 +#include "mozHunspellRLBoxGlue.h"
     19 #endif
     20 
     21 struct unicode_info2 {
     22   char cletter;
     23   unsigned short cupper;
     24   unsigned short clower;
     25 };
     26 
     27 @@ -2277,101 +2273,18 @@ struct cs_info* get_current_cs(const std
     28                      "error: unknown encoding %s: using %s as fallback\n", es.c_str(),
     29                      encds[0].enc_name);
     30     ccs = encds[0].cs_table;
     31   }
     32 
     33   return ccs;
     34 }
     35 #else
     36 -// XXX This function was rewritten for mozilla. Instead of storing the
     37 -// conversion tables static in this file, create them when needed
     38 -// with help the mozilla backend.
     39 struct cs_info* get_current_cs(const std::string& es) {
     40 -  struct cs_info* ccs = new cs_info[256];
     41 -  // Initialze the array with dummy data so that we wouldn't need
     42 -  // to return null in case of failures.
     43 -  for (int i = 0; i <= 0xff; ++i) {
     44 -    ccs[i].ccase = false;
     45 -    ccs[i].clower = i;
     46 -    ccs[i].cupper = i;
     47 -  }
     48 -
     49 -  auto encoding = Encoding::ForLabelNoReplacement(es);
     50 -  if (!encoding) {
     51 -    return ccs;
     52 -  }
     53 -  auto encoder = encoding->NewEncoder();
     54 -  auto decoder = encoding->NewDecoderWithoutBOMHandling();
     55 -
     56 -  for (unsigned int i = 0; i <= 0xff; ++i) {
     57 -    bool success = false;
     58 -    // We want to find the upper/lowercase equivalents of each byte
     59 -    // in this 1-byte character encoding.  Call our encoding/decoding
     60 -    // APIs separately for each byte since they may reject some of the
     61 -    // bytes, and we want to handle errors separately for each byte.
     62 -    uint8_t lower, upper;
     63 -    do {
     64 -      if (i == 0)
     65 -        break;
     66 -      uint8_t source = uint8_t(i);
     67 -      char16_t uni[2];
     68 -      char16_t uniCased;
     69 -      uint8_t destination[4];
     70 -      auto src1 = MakeSpan(&source, 1);
     71 -      auto dst1 = MakeSpan(uni);
     72 -      auto src2 = MakeSpan(&uniCased, 1);
     73 -      auto dst2 = MakeSpan(destination);
     74 -
     75 -      uint32_t result;
     76 -      size_t read;
     77 -      size_t written;
     78 -      Tie(result, read, written) =
     79 -        decoder->DecodeToUTF16WithoutReplacement(src1, dst1, true);
     80 -      if (result != kInputEmpty || read != 1 || written != 1) {
     81 -        break;
     82 -      }
     83 -
     84 -      uniCased = ToLowerCase(uni[0]);
     85 -      Tie(result, read, written) =
     86 -        encoder->EncodeFromUTF16WithoutReplacement(src2, dst2, true);
     87 -      if (result != kInputEmpty || read != 1 || written != 1) {
     88 -        break;
     89 -      }
     90 -      lower = destination[0];
     91 -
     92 -      uniCased = ToUpperCase(uni[0]);
     93 -      Tie(result, read, written) =
     94 -        encoder->EncodeFromUTF16WithoutReplacement(src2, dst2, true);
     95 -      if (result != kInputEmpty || read != 1 || written != 1) {
     96 -        break;
     97 -      }
     98 -      upper = destination[0];
     99 -
    100 -      success = true;
    101 -    } while (0);
    102 -
    103 -    encoding->NewEncoderInto(*encoder);
    104 -    encoding->NewDecoderWithoutBOMHandlingInto(*decoder);
    105 -
    106 -    if (success) {
    107 -      ccs[i].cupper = upper;
    108 -      ccs[i].clower = lower;
    109 -    } else {
    110 -      ccs[i].cupper = i;
    111 -      ccs[i].clower = i;
    112 -    }
    113 -
    114 -    if (ccs[i].clower != (unsigned char)i)
    115 -      ccs[i].ccase = true;
    116 -    else
    117 -      ccs[i].ccase = false;
    118 -  }
    119 -
    120 -  return ccs;
    121 +  return moz_hunspell_GetCurrentCS(es.c_str());
    122 }
    123 #endif
    124 
    125 // primitive isalpha() replacement for tokenization
    126 std::string get_casechars(const char* enc) {
    127   struct cs_info* csconv = get_current_cs(enc);
    128   std::string expw;
    129   for (int i = 0; i <= 255; ++i) {
    130 @@ -2455,34 +2368,34 @@ unsigned short unicodetoupper(unsigned s
    131   // There are a dotless lower case i pair of upper `I',
    132   // and an upper I with dot pair of lower `i'.
    133   if (c == 0x0069 && ((langnum == LANG_az) || (langnum == LANG_tr) || (langnum == LANG_crh)))
    134     return 0x0130;
    135 #ifdef OPENOFFICEORG
    136   return static_cast<unsigned short>(u_toupper(c));
    137 #else
    138 #ifdef MOZILLA_CLIENT
    139 -  return ToUpperCase((char16_t)c);
    140 +  return moz_hunspell_ToUpperCase((char16_t)c);
    141 #else
    142   return (utf_tbl) ? utf_tbl[c].cupper : c;
    143 #endif
    144 #endif
    145 }
    146 
    147 unsigned short unicodetolower(unsigned short c, int langnum) {
    148   // In Azeri and Turkish, I and i dictinct letters:
    149   // There are a dotless lower case i pair of upper `I',
    150   // and an upper I with dot pair of lower `i'.
    151   if (c == 0x0049 && ((langnum == LANG_az) || (langnum == LANG_tr) || (langnum == LANG_crh)))
    152     return 0x0131;
    153 #ifdef OPENOFFICEORG
    154   return static_cast<unsigned short>(u_tolower(c));
    155 #else
    156 #ifdef MOZILLA_CLIENT
    157 -  return ToLowerCase((char16_t)c);
    158 +  return moz_hunspell_ToLowerCase((char16_t)c);
    159 #else
    160   return (utf_tbl) ? utf_tbl[c].clower : c;
    161 #endif
    162 #endif
    163 }
    164 
    165 int unicodeisalpha(unsigned short c) {
    166 #ifdef OPENOFFICEORG
    167 diff --git a/src/csutil.hxx b/src/csutil.hxx
    168 --- a/src/csutil.hxx
    169 +++ b/src/csutil.hxx
    170 @@ -77,20 +77,16 @@
    171 
    172 #include <fstream>
    173 #include <string>
    174 #include <vector>
    175 #include <string.h>
    176 #include "w_char.hxx"
    177 #include "htypes.hxx"
    178 
    179 -#ifdef MOZILLA_CLIENT
    180 -#include "nscore.h"  // for mozalloc headers
    181 -#endif
    182 -
    183 // casing
    184 #define NOCAP 0
    185 #define INITCAP 1
    186 #define ALLCAP 2
    187 #define HUHCAP 3
    188 #define HUHINITCAP 4
    189 
    190 // default encoding and keystring