Coverage Report

Created: 2025-07-18 06:42

/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
984
    : status_fun_(0), speller_(0) {}
17
  DocumentChecker::~DocumentChecker() 
18
984
  {
19
984
  }
20
21
  PosibErr<void> DocumentChecker
22
  ::setup(Tokenizer * tokenizer, Speller * speller, Filter * filter)
23
980
  {
24
980
    tokenizer_.reset(tokenizer);
25
980
    filter_.reset(filter);
26
980
    speller_ = speller;
27
980
    conv_ = speller->to_internal_;
28
980
    return no_err;
29
980
  }
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
980
  {
46
980
    proc_str_.clear();
47
980
    PosibErr<int> fixed_size = get_correct_size("aspell_document_checker_process", conv_->in_type_width(), size);
48
980
    if (!fixed_size.has_err())
49
980
      conv_->decode(str, fixed_size, proc_str_);
50
980
    proc_str_.append(0);
51
980
    FilterChar * begin = proc_str_.pbegin();
52
980
    FilterChar * end   = proc_str_.pend() - 1;
53
980
    if (filter_)
54
980
      filter_->process(begin, end);
55
980
    tokenizer_->reset(begin, end);
56
980
  }
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
18.8k
  {
73
18.8k
    bool correct;
74
18.8k
    Token tok;
75
37.1k
    do {
76
37.1k
      if (!tokenizer_->advance()) {
77
980
  tok.offset = proc_str_.size();
78
980
  tok.len = 0;
79
980
  return tok;
80
980
      }
81
36.2k
      correct = speller_->check(MutableString(tokenizer_->word.data(),
82
36.2k
                tokenizer_->word.size() - 1));
83
36.2k
      tok.len  = tokenizer_->end_pos - tokenizer_->begin_pos;
84
36.2k
      tok.offset = tokenizer_->begin_pos;
85
36.2k
      if (status_fun_)
86
0
  (*status_fun_)(status_fun_data_, tok, correct);
87
36.2k
    } while (correct);
88
17.9k
    return tok;
89
18.8k
  }
90
91
}
92