Coverage Report

Created: 2023-12-08 06:59

/src/aspell/common/convert.hpp
Line
Count
Source (jump to first uncovered line)
1
// This file is part of The New Aspell
2
// Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license
3
// version 2.0 or 2.1.  You should have received a copy of the LGPL
4
// license along with this library if you did not you can find
5
// it at http://www.gnu.org/.
6
7
#ifndef ASPELL_CONVERT__HPP
8
#define ASPELL_CONVERT__HPP
9
10
#include "settings.h"
11
12
#include "string.hpp"
13
#include "posib_err.hpp"
14
#include "char_vector.hpp"
15
#include "filter_char.hpp"
16
#include "filter_char_vector.hpp"
17
#include "stack_ptr.hpp"
18
#include "filter.hpp"
19
#include "cache.hpp"
20
21
namespace acommon {
22
23
  class OStream;
24
  class Config;
25
26
  struct ConvKey {
27
    ParmString val;
28
    bool allow_ucs;
29
2.07k
    ConvKey() : val(), allow_ucs() {}
30
    template <typename T>
31
27.1k
    ConvKey(const T & v, bool a = false) : val(v), allow_ucs(a) {}
acommon::ConvKey::ConvKey<acommon::ParmString>(acommon::ParmString const&, bool)
Line
Count
Source
31
9.24k
    ConvKey(const T & v, bool a = false) : val(v), allow_ucs(a) {}
acommon::ConvKey::ConvKey<char [6]>(char const (&) [6], bool)
Line
Count
Source
31
7.16k
    ConvKey(const T & v, bool a = false) : val(v), allow_ucs(a) {}
acommon::ConvKey::ConvKey<char const*>(char const* const&, bool)
Line
Count
Source
31
6.39k
    ConvKey(const T & v, bool a = false) : val(v), allow_ucs(a) {}
acommon::ConvKey::ConvKey<acommon::String>(acommon::String const&, bool)
Line
Count
Source
31
4.30k
    ConvKey(const T & v, bool a = false) : val(v), allow_ucs(a) {}
32
  };
33
34
  struct ConvBase : public Cacheable {
35
    typedef const Config CacheConfig;
36
    typedef ConvKey CacheKey;
37
    String key;
38
    int type_width; // type width in bytes
39
6.19k
    bool is_ucs() const {return type_width != 1;}
40
9.27k
    bool cache_key_eq(CacheKey k) const  {return k.allow_ucs ? key == k.val : key == k.val && !is_ucs();}
41
10.9k
    ConvBase() : type_width(1) {}
42
  private:
43
    ConvBase(const ConvBase &);
44
    void operator=(const ConvBase &);
45
  };
46
47
  struct Decode : public ConvBase {
48
1.45k
    virtual PosibErr<void> init(ParmStr code, const Config &) {return no_err;}
49
    virtual void decode(const char * in, int size,
50
      FilterCharVector & out) const = 0;
51
    virtual PosibErr<void> decode_ec(const char * in, int size,
52
                                     FilterCharVector & out, ParmStr orig) const = 0;
53
    static PosibErr<Decode *> get_new(const ConvKey &, const Config *);
54
0
    virtual ~Decode() {}
55
  };
56
  struct Encode : public ConvBase {
57
    // null characters should be treated like any other character
58
    // by the encoder.
59
1.48k
    virtual PosibErr<void> init(ParmStr, const Config &) {return no_err;}
60
    virtual void encode(const FilterChar * in, const FilterChar * stop, 
61
                        CharVector & out) const = 0;
62
    virtual PosibErr<void> encode_ec(const FilterChar * in, const FilterChar * stop, 
63
                                     CharVector & out, ParmStr orig) const = 0;
64
    // may convert inplace
65
    virtual bool encode(FilterChar * & in, FilterChar * & stop, 
66
0
                        FilterCharVector & buf) const {return false;}
67
    static PosibErr<Encode *> get_new(const ConvKey &, const Config *);
68
0
    virtual ~Encode() {}
69
  };
70
  struct DirectConv { // convert directly from in_code to out_code.
71
    int type_width; // type width in bytes
72
30
    DirectConv() : type_width(1) {}
73
    // should not take ownership of decode and encode.
74
    // decode and encode guaranteed to stick around for the life
75
    // of the object.
76
    virtual PosibErr<void> init(const Decode *, const Encode *, 
77
30
        const Config &) {return no_err;}
78
    virtual void convert(const char * in, int size, 
79
       CharVector & out) const = 0;
80
    virtual PosibErr<void> convert_ec(const char * in, int size, 
81
                                      CharVector & out, ParmStr orig) const = 0;
82
30
    virtual ~DirectConv() {}
83
  };
84
  template <class T> struct NormTable;
85
  struct FromUniNormEntry;
86
  struct ToUniNormEntry;
87
  struct NormTables : public Cacheable {
88
    typedef const Config CacheConfig;
89
    typedef const char * CacheKey;
90
    String key;
91
7.30k
    bool cache_key_eq(const char * l) const  {return key == l;}
92
    static PosibErr<NormTables *> get_new(const String &, const Config *);
93
    NormTable<FromUniNormEntry> * internal;
94
    NormTable<FromUniNormEntry> * strict_d;
95
    NormTable<FromUniNormEntry> * strict;
96
    struct ToUniTable {
97
      String name;
98
      NormTable<ToUniNormEntry> * data;
99
      NormTable<ToUniNormEntry> * ptr;
100
2.00k
      ToUniTable() : data(), ptr() {}
101
    };
102
    typedef Vector<ToUniTable> ToUni;
103
    Vector<ToUniTable> to_uni;
104
    ~NormTables();
105
  };
106
107
  typedef FilterCharVector ConvertBuffer;
108
109
  class Convert {
110
  private:
111
    CachePtr<Decode> decode_c;
112
    StackPtr<Decode> decode_s;
113
    Decode * decode_;
114
    CachePtr<Encode> encode_c;
115
    StackPtr<Encode> encode_s;
116
    Encode * encode_;
117
    CachePtr<NormTables> norm_tables_;
118
    StackPtr<DirectConv> conv_;
119
120
    ConvertBuffer buf_;
121
122
    static const unsigned int null_len_ = 4; // POSIB FIXME: Be more precise
123
124
    Convert(const Convert &);
125
    void operator=(const Convert &);
126
127
  public:
128
8.56k
    Convert() {}
129
    ~Convert();
130
131
    // This filter is used when the convert method is called.  It must
132
    // be set up by an external entity as this class does not set up
133
    // this class in any way.
134
    Filter filter;
135
136
    PosibErr<void> init(const Config &, const ConvKey & in, const ConvKey & out);
137
    PosibErr<void> init_norm_to(const Config &, const ConvKey & in, const ConvKey & out);
138
    PosibErr<void> init_norm_from(const Config &, const ConvKey & in, const ConvKey & out);
139
    
140
0
    const char * in_code() const   {return decode_->key.c_str();}
141
0
    const char * out_code() const  {return encode_->key.c_str();}
142
143
11.2k
    int in_type_width() const {return decode_->type_width;}
144
0
    int out_type_width() const {return encode_->type_width;}
145
146
    void append_null(CharVector & out) const
147
627k
    {
148
627k
      const char nul[4] = {0,0,0,0}; // 4 should be enough
149
627k
      out.write(nul, null_len_);
150
627k
    }
151
152
0
    unsigned int null_len() const {return null_len_;}
153
  
154
    // this filters will generally not translate null characters
155
    // if you need a null character at the end, add it yourself
156
    // with append_null
157
158
    void decode(const char * in, int size, FilterCharVector & out) const 
159
694
      {decode_->decode(in,size,out);}
160
    
161
    void encode(const FilterChar * in, const FilterChar * stop, 
162
    CharVector & out) const
163
0
      {encode_->encode(in,stop,out);}
164
165
    bool encode(FilterChar * & in, FilterChar * & stop, 
166
                FilterCharVector & buf) const
167
694
      {return encode_->encode(in,stop,buf);}
168
169
    // does NOT pass it through filters
170
    // DOES NOT use an internal state
171
    void convert(const char * in, int size, CharVector & out, ConvertBuffer & buf) const
172
637k
    {
173
637k
      if (conv_) {
174
17.5k
  conv_->convert(in,size,out);
175
620k
      } else {
176
620k
        buf.clear();
177
620k
        decode_->decode(in, size, buf);
178
620k
        encode_->encode(buf.pbegin(), buf.pend(), out);
179
620k
      }
180
637k
    }
181
182
    // does NOT pass it through filters
183
    // DOES NOT use an internal state
184
    PosibErr<void> convert_ec(const char * in, int size, CharVector & out, 
185
                              ConvertBuffer & buf, ParmStr orig) const
186
19.9k
    {
187
19.9k
      if (conv_) {
188
0
  RET_ON_ERR(conv_->convert_ec(in,size,out, orig));
189
19.9k
      } else {
190
19.9k
        buf.clear();
191
19.9k
        RET_ON_ERR(decode_->decode_ec(in, size, buf, orig));
192
19.9k
       RET_ON_ERR(encode_->encode_ec(buf.pbegin(), buf.pend(), 
193
19.9k
                                      out, orig));
194
19.9k
      }
195
19.9k
      return no_err;
196
19.9k
    }
197
198
199
    // convert has the potential to use internal buffers and
200
    // is therefore not const.  It is also not thread safe
201
    // and I have no intention to make it thus.
202
203
638k
    void convert(const char * in, int size, CharVector & out) {
204
638k
      if (filter.empty()) {
205
637k
        convert(in,size,out,buf_);
206
637k
      } else {
207
640
        generic_convert(in,size,out);
208
640
      }
209
638k
    }
210
211
0
    void convert(const void * in, int size, CharVector & out) {
212
0
      convert(static_cast<const char *>(in), size, out);
213
0
    }
214
215
    void generic_convert(const char * in, int size, CharVector & out);
216
    
217
  };
218
219
  bool operator== (const Convert & rhs, const Convert & lhs);
220
221
  const char * fix_encoding_str(ParmStr enc, String & buf);
222
223
  // also returns true if the encoding is unknown
224
  bool ascii_encoding(const Config & c, ParmStr enc0);
225
226
  enum Normalize {NormNone, NormFrom, NormTo};
227
228
  PosibErr<Convert *> internal_new_convert(const Config & c, 
229
                                           ConvKey in, ConvKey out,
230
                                           bool if_needed,
231
                                           Normalize n);
232
  
233
  static inline PosibErr<Convert *> new_convert(const Config & c,
234
                                                const ConvKey & in, const ConvKey & out,
235
                                                Normalize n)
236
1.42k
  {
237
1.42k
    return internal_new_convert(c,in,out,false,n);
238
1.42k
  }
Unexecuted instantiation: string_enumeration-c.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: speller-c.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: new_checker.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: config.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: convert.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: document_checker.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: basic.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: find_speller.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: email.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: tex.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: tokenizer.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
speller_impl.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Line
Count
Source
236
1.42k
  {
237
1.42k
    return internal_new_convert(c,in,out,false,n);
238
1.42k
  }
Unexecuted instantiation: language.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: affix.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: speller.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: suggest.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: data.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: multi_ws.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: phonetic.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: writable.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: phonet.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: typo_editdist.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: readonly_ws.cpp:acommon::new_convert(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
239
  
240
  static inline PosibErr<Convert *> new_convert_if_needed(const Config & c,
241
                                                          const ConvKey & in, const ConvKey & out,
242
                                                          Normalize n)
243
12.8k
  {
244
12.8k
    return internal_new_convert(c,in,out,true,n);
245
12.8k
  }
Unexecuted instantiation: string_enumeration-c.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: speller-c.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: new_checker.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
config.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Line
Count
Source
243
12.8k
  {
244
12.8k
    return internal_new_convert(c,in,out,true,n);
245
12.8k
  }
Unexecuted instantiation: convert.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: document_checker.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: basic.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: find_speller.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: email.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: tex.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: tokenizer.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: speller_impl.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: language.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: affix.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: speller.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: suggest.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: data.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: multi_ws.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: phonetic.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: writable.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: phonet.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: typo_editdist.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
Unexecuted instantiation: readonly_ws.cpp:acommon::new_convert_if_needed(acommon::Config const&, acommon::ConvKey const&, acommon::ConvKey const&, acommon::Normalize)
246
247
  struct ConvObj {
248
    Convert * ptr;
249
13.6k
    ConvObj(Convert * c = 0) : ptr(c) {}
250
13.6k
    ~ConvObj() {delete ptr;}
251
    PosibErr<void> setup(const Config & c, const ConvKey & from, const ConvKey & to, Normalize norm)
252
12.8k
    {
253
12.8k
      delete ptr;
254
12.8k
      ptr = 0;
255
12.8k
      PosibErr<Convert *> pe = new_convert_if_needed(c, from, to, norm);
256
12.8k
      if (pe.has_err()) return pe;
257
12.8k
      ptr = pe.data;
258
12.8k
      return no_err;
259
12.8k
    }
260
4.27k
    operator const Convert * () const {return ptr;}
261
  private:
262
    ConvObj(const ConvObj &);
263
    void operator=(const ConvObj &);
264
  };
265
266
  struct ConvP {
267
    const Convert * conv;
268
    ConvertBuffer buf0;
269
    CharVector buf;
270
0
    operator bool() const {return conv;}
271
31.5k
    ConvP(const Convert * c = 0) : conv(c) {}
272
0
    ConvP(const ConvObj & c) : conv(c.ptr) {}
273
0
    ConvP(const ConvP & c) : conv(c.conv) {}
274
0
    void operator=(const ConvP & c) { conv = c.conv; }
275
    PosibErr<void> setup(const Config & c, const ConvKey & from, const ConvKey & to, 
276
                         Normalize norm)
277
0
    {
278
0
      delete conv;
279
0
      conv = 0;
280
0
      PosibErr<Convert *> pe = new_convert_if_needed(c, from, to, norm);
281
0
      if (pe.has_err()) return pe;
282
0
      conv = pe.data;
283
0
      return no_err;
284
0
    }
285
    char * operator() (char * str, size_t sz)
286
2.20M
    {
287
2.20M
      if (conv) {
288
0
        buf.clear();
289
0
        conv->convert(str, sz, buf, buf0);
290
0
        return buf.mstr();
291
2.20M
      } else {
292
2.20M
        return str;
293
2.20M
      }
294
2.20M
    }
295
    const char * operator() (const char * str, size_t sz)
296
0
    {
297
0
      if (conv) {
298
0
        buf.clear();
299
0
        conv->convert(str, sz, buf, buf0);
300
0
        return buf.str();
301
0
      } else {
302
0
        return str;
303
0
      }
304
0
    }
305
    char * operator() (MutableString str)
306
2.20M
    {
307
2.20M
      return operator()(str.str, str.size);
308
2.20M
    }
309
    char * operator() (char * str)
310
0
    {
311
0
      if (conv) {
312
0
        buf.clear();
313
0
        conv->convert(str, -1, buf, buf0);
314
0
        return buf.mstr();
315
0
      } else {
316
0
        return str;
317
0
      }
318
0
    }
319
    const char * operator() (ParmStr str)
320
12.5k
    {
321
12.5k
      if (conv) {
322
0
        buf.clear();
323
0
        conv->convert(str, -1, buf, buf0);
324
0
        return buf.mstr();
325
12.5k
      } else {
326
12.5k
        return str;
327
12.5k
      }
328
12.5k
    }
329
    char * operator() (char c)
330
12.5k
    {
331
12.5k
      buf.clear();
332
12.5k
      if (conv) {
333
0
        char str[2] = {c, 0};
334
0
        conv->convert(str, 1, buf, buf0);
335
12.5k
      } else {
336
12.5k
        buf.append(c);
337
12.5k
      }
338
12.5k
      return buf.mstr();
339
12.5k
    }
340
  };
341
342
  struct Conv : public ConvP
343
  {
344
    ConvObj conv_obj;
345
6.47k
    Conv(Convert * c = 0) : ConvP(c), conv_obj(c) {}
346
    PosibErr<void> setup(const Config & c, const ConvKey & from, const ConvKey & to, Normalize norm)
347
5.68k
    {
348
5.68k
      RET_ON_ERR(conv_obj.setup(c,from,to,norm));
349
5.68k
      conv = conv_obj.ptr;
350
5.68k
      return no_err;
351
5.68k
    }
352
  };
353
354
  struct ConvECP {
355
    const Convert * conv;
356
    ConvertBuffer buf0;
357
    CharVector buf;
358
0
    operator bool() const {return conv;}
359
733
    ConvECP(const Convert * c = 0) : conv(c) {}
360
0
    ConvECP(const ConvObj & c) : conv(c.ptr) {}
361
0
    ConvECP(const ConvECP & c) : conv(c.conv) {}
362
0
    void operator=(const ConvECP & c) { conv = c.conv; }
363
    PosibErr<void> setup(const Config & c, const ConvKey & from, const ConvKey & to, Normalize norm)
364
0
    {
365
0
      delete conv;
366
0
      conv = 0;
367
0
      PosibErr<Convert *> pe = new_convert_if_needed(c, from, to, norm);
368
0
      if (pe.has_err()) return pe;
369
0
      conv = pe.data;
370
0
      return no_err;
371
0
    }
372
    PosibErr<char *> operator() (char * str, size_t sz)
373
15.9k
    {
374
15.9k
      if (conv) {
375
15.9k
        buf.clear();
376
15.9k
        RET_ON_ERR(conv->convert_ec(str, sz, buf, buf0, str));
377
15.9k
        return buf.mstr();
378
15.9k
      } else {
379
0
        return str;
380
0
      }
381
15.9k
    }
382
    PosibErr<char *> operator() (MutableString str)
383
0
    {
384
0
      return operator()(str.str, str.size);
385
0
    }
386
    PosibErr<char *> operator() (char * str)
387
0
    {
388
0
      if (conv) {
389
0
        buf.clear();
390
0
        RET_ON_ERR(conv->convert_ec(str, -1, buf, buf0, str));
391
0
        return buf.mstr();
392
0
      } else {
393
0
        return str;
394
0
      }
395
0
    }
396
397
    PosibErr<const char *> operator() (ParmStr str)
398
4.01k
    {
399
4.01k
      if (conv) {
400
4.01k
        buf.clear();
401
4.01k
        RET_ON_ERR(conv->convert_ec(str, -1, buf, buf0, str));
402
4.01k
        return buf.mstr();
403
4.01k
      } else {
404
0
        return str.str();
405
0
      }
406
4.01k
    }
407
    PosibErr<const char *> operator() (char c)
408
0
    {
409
0
      char buf2[2] = {c, 0};
410
0
      return operator()(ParmString(buf2,1));
411
0
    }
412
  };
413
414
  struct ConvEC : public ConvECP
415
  {
416
    ConvObj conv_obj;
417
733
    ConvEC(Convert * c = 0) : ConvECP(c), conv_obj(c) {}
418
    PosibErr<void> setup(const Config & c, const ConvKey & from, const ConvKey & to, Normalize norm)
419
733
    {
420
733
      RET_ON_ERR(conv_obj.setup(c,from,to,norm));
421
733
      conv = conv_obj.ptr;
422
733
      return no_err;
423
733
    }
424
  };
425
426
  struct MBLen 
427
  {
428
    enum Encoding {Other, UTF8, UCS2, UCS4} encoding;
429
0
    MBLen() : encoding(Other) {}
430
    PosibErr<void> setup(const Config &, ParmStr enc);
431
    unsigned operator()(const char * str, const char * stop);
432
0
    unsigned operator()(const char * str, unsigned byte_size) {
433
0
      return operator()(str, str + byte_size);}
434
  };
435
436
#ifdef SLOPPY_NULL_TERM_STRINGS
437
  static const bool sloppy_null_term_strings = true;
438
#else
439
  static const bool sloppy_null_term_strings = false;
440
#endif
441
  
442
  PosibErr<void> unsupported_null_term_wide_string_err_(const char * func);
443
  void unsupported_null_term_wide_string_abort_(const char * func);
444
    
445
11.2k
  static inline PosibErr<int> get_correct_size(const char * func, int conv_type_width, int size) {
446
11.2k
    if (sloppy_null_term_strings && size <= -1)
447
0
      return -conv_type_width;
448
11.2k
    if (size <= -1 && -conv_type_width != size)
449
0
      return unsupported_null_term_wide_string_err_(func);
450
11.2k
    return size;
451
11.2k
  }
Unexecuted instantiation: string_enumeration-c.cpp:acommon::get_correct_size(char const*, int, int)
speller-c.cpp:acommon::get_correct_size(char const*, int, int)
Line
Count
Source
445
10.5k
  static inline PosibErr<int> get_correct_size(const char * func, int conv_type_width, int size) {
446
10.5k
    if (sloppy_null_term_strings && size <= -1)
447
0
      return -conv_type_width;
448
10.5k
    if (size <= -1 && -conv_type_width != size)
449
0
      return unsupported_null_term_wide_string_err_(func);
450
10.5k
    return size;
451
10.5k
  }
Unexecuted instantiation: new_checker.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: config.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: convert.cpp:acommon::get_correct_size(char const*, int, int)
document_checker.cpp:acommon::get_correct_size(char const*, int, int)
Line
Count
Source
445
694
  static inline PosibErr<int> get_correct_size(const char * func, int conv_type_width, int size) {
446
694
    if (sloppy_null_term_strings && size <= -1)
447
0
      return -conv_type_width;
448
694
    if (size <= -1 && -conv_type_width != size)
449
0
      return unsupported_null_term_wide_string_err_(func);
450
694
    return size;
451
694
  }
Unexecuted instantiation: basic.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: find_speller.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: email.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: tex.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: tokenizer.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: speller_impl.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: language.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: affix.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: speller.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: suggest.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: data.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: multi_ws.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: phonetic.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: writable.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: phonet.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: typo_editdist.cpp:acommon::get_correct_size(char const*, int, int)
Unexecuted instantiation: readonly_ws.cpp:acommon::get_correct_size(char const*, int, int)
452
0
  static inline int get_correct_size(const char * func, int conv_type_width, int size, int type_width) {
453
0
    if ((sloppy_null_term_strings || type_width <= -1) && size <= -1)
454
0
      return -conv_type_width;
455
0
    if (size <= -1 && conv_type_width != type_width)
456
0
      unsupported_null_term_wide_string_abort_(func);
457
0
    return size;
458
0
  }
Unexecuted instantiation: string_enumeration-c.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: speller-c.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: new_checker.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: config.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: convert.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: document_checker.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: basic.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: find_speller.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: email.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: tex.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: tokenizer.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: speller_impl.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: language.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: affix.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: speller.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: suggest.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: data.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: multi_ws.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: phonetic.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: writable.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: phonet.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: typo_editdist.cpp:acommon::get_correct_size(char const*, int, int, int)
Unexecuted instantiation: readonly_ws.cpp:acommon::get_correct_size(char const*, int, int, int)
459
460
}
461
462
#endif