Coverage Report

Created: 2025-05-19 06:51

/src/aspell/common/string_list.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 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
#include "string_list.hpp"
8
//#include "iostream.hpp"
9
10
namespace acommon {
11
12
  void StringList::copy(const StringList & other)
13
52.0k
  {
14
52.0k
    StringListNode * * cur = &first;
15
52.0k
    StringListNode * other_cur = other.first;
16
1.73M
    while (other_cur != 0) {
17
1.68M
      *cur = new StringListNode(other_cur->data.c_str());
18
1.68M
      cur = &(*cur)->next;
19
1.68M
      other_cur = other_cur->next;
20
1.68M
    }
21
52.0k
    *cur = 0;
22
52.0k
  }
23
24
  void StringList::destroy()
25
128k
  {
26
1.88M
    while (first != 0) {
27
1.76M
      StringListNode * next = first->next;
28
1.76M
      delete first;
29
1.76M
      first = next;
30
1.76M
    }
31
128k
  }
32
33
  bool operator==(const StringList & rhs, 
34
      const StringList & lhs)
35
18.4k
  {
36
18.4k
    StringListNode * rhs_cur = rhs.first;
37
18.4k
    StringListNode * lhs_cur = lhs.first;
38
63.7k
    while (rhs_cur != 0 && lhs_cur != 0 && rhs_cur->data == lhs_cur->data) {
39
45.2k
      rhs_cur = rhs_cur->next;
40
45.2k
      lhs_cur = lhs_cur->next;
41
45.2k
    }
42
18.4k
    return rhs_cur == 0 && lhs_cur == 0;
43
18.4k
  }
44
45
  StringEnumeration * StringListEnumeration::clone() const
46
0
  {
47
0
    return new StringListEnumeration(*this);
48
0
  }
49
50
  void StringListEnumeration::assign(const StringEnumeration * other)
51
0
  {
52
0
    *this = *(const StringListEnumeration *)other;
53
0
  }
54
55
56
  StringList * StringList::clone() const
57
0
  {
58
0
    return new StringList(*this);
59
0
  }
60
61
  void StringList::assign(const StringList * other)
62
0
  {
63
0
    *this = *(const StringList *)other;
64
0
  }
65
66
  PosibErr<bool> StringList::add(ParmStr str)
67
111k
  {
68
    //CERR.printf("ADD %s\n", str.str());
69
111k
    StringListNode * * cur = &first;
70
7.66M
    while (*cur != 0 && strcmp((*cur)->data.c_str(), str) != 0) {
71
7.55M
      cur = &(*cur)->next;
72
7.55M
    }
73
111k
    if (*cur == 0) {
74
101k
      *cur = new StringListNode(str);
75
101k
      return true;
76
101k
    } else {
77
10.2k
      return false;
78
10.2k
    }
79
111k
  }
80
81
  PosibErr<bool> StringList::remove(ParmStr str)
82
112k
  {
83
    //CERR.printf("REM %s\n", str.str());
84
112k
    StringListNode  * * cur  = &first;
85
404k
    while (*cur != 0 && strcmp((*cur)->data.c_str(), str)!=0 )  {
86
292k
      cur = &(*cur)->next;
87
292k
    }
88
112k
    if (*cur == 0) {
89
111k
      return false;
90
111k
    } else {
91
924
      StringListNode * tmp = *cur;
92
924
      *cur = (*cur)->next;
93
924
      delete tmp;
94
924
      return true;
95
924
    }
96
112k
  }
97
98
  PosibErr<void> StringList::clear()
99
973
  {
100
    //CERR.printf("CLEAR\n");
101
973
    StringListNode * temp;
102
973
    while (first != 0) {
103
0
      temp = first;
104
0
      first = temp->next;
105
0
      delete temp;
106
0
    }
107
973
    first = 0;
108
973
    return no_err;
109
973
  }
110
111
  StringEnumeration * StringList::elements() const
112
2.56k
  {
113
2.56k
    return new StringListEnumeration(first);
114
2.56k
  }
115
116
0
  StringList * new_string_list() {
117
0
    return new StringList;
118
0
  }
119
120
}