/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 | 37.0k | { |
14 | 37.0k | StringListNode * * cur = &first; |
15 | 37.0k | StringListNode * other_cur = other.first; |
16 | 1.43M | while (other_cur != 0) { |
17 | 1.39M | *cur = new StringListNode(other_cur->data.c_str()); |
18 | 1.39M | cur = &(*cur)->next; |
19 | 1.39M | other_cur = other_cur->next; |
20 | 1.39M | } |
21 | 37.0k | *cur = 0; |
22 | 37.0k | } |
23 | | |
24 | | void StringList::destroy() |
25 | 91.0k | { |
26 | 1.55M | while (first != 0) { |
27 | 1.46M | StringListNode * next = first->next; |
28 | 1.46M | delete first; |
29 | 1.46M | first = next; |
30 | 1.46M | } |
31 | 91.0k | } |
32 | | |
33 | | bool operator==(const StringList & rhs, |
34 | | const StringList & lhs) |
35 | 12.5k | { |
36 | 12.5k | StringListNode * rhs_cur = rhs.first; |
37 | 12.5k | StringListNode * lhs_cur = lhs.first; |
38 | 50.3k | while (rhs_cur != 0 && lhs_cur != 0 && rhs_cur->data == lhs_cur->data) { |
39 | 37.7k | rhs_cur = rhs_cur->next; |
40 | 37.7k | lhs_cur = lhs_cur->next; |
41 | 37.7k | } |
42 | 12.5k | return rhs_cur == 0 && lhs_cur == 0; |
43 | 12.5k | } |
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 | 99.5k | { |
68 | | //CERR.printf("ADD %s\n", str.str()); |
69 | 99.5k | StringListNode * * cur = &first; |
70 | 8.92M | while (*cur != 0 && strcmp((*cur)->data.c_str(), str) != 0) { |
71 | 8.82M | cur = &(*cur)->next; |
72 | 8.82M | } |
73 | 99.5k | if (*cur == 0) { |
74 | 93.5k | *cur = new StringListNode(str); |
75 | 93.5k | return true; |
76 | 93.5k | } else { |
77 | 5.98k | return false; |
78 | 5.98k | } |
79 | 99.5k | } |
80 | | |
81 | | PosibErr<bool> StringList::remove(ParmStr str) |
82 | 66.9k | { |
83 | | //CERR.printf("REM %s\n", str.str()); |
84 | 66.9k | StringListNode * * cur = &first; |
85 | 170k | while (*cur != 0 && strcmp((*cur)->data.c_str(), str)!=0 ) { |
86 | 103k | cur = &(*cur)->next; |
87 | 103k | } |
88 | 66.9k | if (*cur == 0) { |
89 | 66.4k | return false; |
90 | 66.4k | } else { |
91 | 566 | StringListNode * tmp = *cur; |
92 | 566 | *cur = (*cur)->next; |
93 | 566 | delete tmp; |
94 | 566 | return true; |
95 | 566 | } |
96 | 66.9k | } |
97 | | |
98 | | PosibErr<void> StringList::clear() |
99 | 762 | { |
100 | | //CERR.printf("CLEAR\n"); |
101 | 762 | StringListNode * temp; |
102 | 762 | while (first != 0) { |
103 | 0 | temp = first; |
104 | 0 | first = temp->next; |
105 | 0 | delete temp; |
106 | 0 | } |
107 | 762 | first = 0; |
108 | 762 | return no_err; |
109 | 762 | } |
110 | | |
111 | | StringEnumeration * StringList::elements() const |
112 | 1.12k | { |
113 | 1.12k | return new StringListEnumeration(first); |
114 | 1.12k | } |
115 | | |
116 | 0 | StringList * new_string_list() { |
117 | 0 | return new StringList; |
118 | 0 | } |
119 | | |
120 | | } |