/src/aspell/common/string_list.cpp
Line | Count | Source |
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 | 60.0k | { |
14 | 60.0k | StringListNode * * cur = &first; |
15 | 60.0k | StringListNode * other_cur = other.first; |
16 | 1.74M | 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 | 60.0k | *cur = 0; |
22 | 60.0k | } |
23 | | |
24 | | void StringList::destroy() |
25 | 145k | { |
26 | 1.90M | while (first != 0) { |
27 | 1.76M | StringListNode * next = first->next; |
28 | 1.76M | delete first; |
29 | 1.76M | first = next; |
30 | 1.76M | } |
31 | 145k | } |
32 | | |
33 | | bool operator==(const StringList & rhs, |
34 | | const StringList & lhs) |
35 | 21.1k | { |
36 | 21.1k | StringListNode * rhs_cur = rhs.first; |
37 | 21.1k | StringListNode * lhs_cur = lhs.first; |
38 | 76.2k | while (rhs_cur != 0 && lhs_cur != 0 && rhs_cur->data == lhs_cur->data) { |
39 | 55.1k | rhs_cur = rhs_cur->next; |
40 | 55.1k | lhs_cur = lhs_cur->next; |
41 | 55.1k | } |
42 | 21.1k | return rhs_cur == 0 && lhs_cur == 0; |
43 | 21.1k | } |
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 | 121k | { |
68 | | //CERR.printf("ADD %s\n", str.str()); |
69 | 121k | StringListNode * * cur = &first; |
70 | 9.39M | while (*cur != 0 && strcmp((*cur)->data.c_str(), str) != 0) { |
71 | 9.27M | cur = &(*cur)->next; |
72 | 9.27M | } |
73 | 121k | if (*cur == 0) { |
74 | 104k | *cur = new StringListNode(str); |
75 | 104k | return true; |
76 | 104k | } else { |
77 | 17.0k | return false; |
78 | 17.0k | } |
79 | 121k | } |
80 | | |
81 | | PosibErr<bool> StringList::remove(ParmStr str) |
82 | 33.5k | { |
83 | | //CERR.printf("REM %s\n", str.str()); |
84 | 33.5k | StringListNode * * cur = &first; |
85 | 115k | while (*cur != 0 && strcmp((*cur)->data.c_str(), str)!=0 ) { |
86 | 82.2k | cur = &(*cur)->next; |
87 | 82.2k | } |
88 | 33.5k | if (*cur == 0) { |
89 | 33.0k | return false; |
90 | 33.0k | } else { |
91 | 451 | StringListNode * tmp = *cur; |
92 | 451 | *cur = (*cur)->next; |
93 | 451 | delete tmp; |
94 | 451 | return true; |
95 | 451 | } |
96 | 33.5k | } |
97 | | |
98 | | PosibErr<void> StringList::clear() |
99 | 976 | { |
100 | | //CERR.printf("CLEAR\n"); |
101 | 976 | StringListNode * temp; |
102 | 976 | while (first != 0) { |
103 | 0 | temp = first; |
104 | 0 | first = temp->next; |
105 | 0 | delete temp; |
106 | 0 | } |
107 | 976 | first = 0; |
108 | 976 | return no_err; |
109 | 976 | } |
110 | | |
111 | | StringEnumeration * StringList::elements() const |
112 | 2.88k | { |
113 | 2.88k | return new StringListEnumeration(first); |
114 | 2.88k | } |
115 | | |
116 | 0 | StringList * new_string_list() { |
117 | 0 | return new StringList; |
118 | 0 | } |
119 | | |
120 | | } |