Coverage Report

Created: 2025-10-10 06:18

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