Coverage Report

Created: 2025-08-29 06:09

/src/aspell/common/document_checker.cpp
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
3
 * license version 2.0 or 2.1.  You should have received a copy of the
4
 * LGPL license along with this library if you did not you can find it
5
 * at http://www.gnu.org/.                                              */
6
7
#include "document_checker.hpp"
8
#include "tokenizer.hpp"
9
#include "convert.hpp"
10
#include "speller.hpp"
11
#include "config.hpp"
12
13
namespace acommon {
14
15
  DocumentChecker::DocumentChecker() 
16
394
    : status_fun_(0), speller_(0) {}
17
  DocumentChecker::~DocumentChecker() 
18
394
  {
19
394
  }
20
21
  PosibErr<void> DocumentChecker
22
  ::setup(Tokenizer * tokenizer, Speller * speller, Filter * filter)
23
390
  {
24
390
    tokenizer_.reset(tokenizer);
25
390
    filter_.reset(filter);
26
390
    speller_ = speller;
27
390
    conv_ = speller->to_internal_;
28
390
    return no_err;
29
390
  }
30
31
  void DocumentChecker::set_status_fun(void (* sf)(void *, Token, int), 
32
               void * d)
33
0
  {
34
0
    status_fun_ = sf;
35
0
    status_fun_data_ = d;
36
0
  }
37
38
  void DocumentChecker::reset()
39
0
  {
40
0
    if (filter_)
41
0
      filter_->reset();
42
0
  }
43
44
  void DocumentChecker::process(const char * str, int size)
45
390
  {
46
390
    proc_str_.clear();
47
390
    PosibErr<int> fixed_size = get_correct_size("aspell_document_checker_process", conv_->in_type_width(), size);
48
390
    if (!fixed_size.has_err())
49
390
      conv_->decode(str, fixed_size, proc_str_);
50
390
    proc_str_.append(0);
51
390
    FilterChar * begin = proc_str_.pbegin();
52
390
    FilterChar * end   = proc_str_.pend() - 1;
53
390
    if (filter_)
54
390
      filter_->process(begin, end);
55
390
    tokenizer_->reset(begin, end);
56
390
  }
57
58
  void DocumentChecker::process_wide(const void * str, int size, int type_width)
59
0
  {
60
0
    proc_str_.clear();
61
0
    int fixed_size = get_correct_size("aspell_document_checker_process", conv_->in_type_width(), size, type_width);
62
0
    conv_->decode(static_cast<const char *>(str), fixed_size, proc_str_);
63
0
    proc_str_.append(0);
64
0
    FilterChar * begin = proc_str_.pbegin();
65
0
    FilterChar * end   = proc_str_.pend() - 1;
66
0
    if (filter_)
67
0
      filter_->process(begin, end);
68
0
    tokenizer_->reset(begin, end);
69
0
  }
70
  
71
  Token DocumentChecker::next_misspelling()
72
9.28k
  {
73
9.28k
    bool correct;
74
9.28k
    Token tok;
75
23.3k
    do {
76
23.3k
      if (!tokenizer_->advance()) {
77
390
  tok.offset = proc_str_.size();
78
390
  tok.len = 0;
79
390
  return tok;
80
390
      }
81
22.9k
      correct = speller_->check(MutableString(tokenizer_->word.data(),
82
22.9k
                tokenizer_->word.size() - 1));
83
22.9k
      tok.len  = tokenizer_->end_pos - tokenizer_->begin_pos;
84
22.9k
      tok.offset = tokenizer_->begin_pos;
85
22.9k
      if (status_fun_)
86
0
  (*status_fun_)(status_fun_data_, tok, correct);
87
22.9k
    } while (correct);
88
8.89k
    return tok;
89
9.28k
  }
90
91
}
92