1 /** \file lvstring16collection.h
2     \brief collection of strings
3 
4     CoolReader Engine
5 
6     (c) Vadim Lopatin, 2000-2006
7     This source code is distributed under the terms of
8     GNU General Public License.
9 
10     See LICENSE file for details.
11 */
12 
13 #ifndef __LV_STRING8COLLECTION_H_INCLUDED__
14 #define __LV_STRING8COLLECTION_H_INCLUDED__
15 
16 #include "lvstring.h"
17 
18 /// collection of strings
19 class lString8Collection
20 {
21 private:
22     lstring8_chunk_t * * chunks;
23     int count;
24     int size;
25 public:
lString8Collection()26     lString8Collection()
27         : chunks(NULL), count(0), size(0)
28     { }
lString8Collection(const lString8Collection & src)29     lString8Collection(const lString8Collection & src)
30         : chunks(NULL), count(0), size(0)
31     { reserve(src.size); addAll(src); }
lString8Collection(const lString8 & str,const lString8 & delimiter)32     lString8Collection(const lString8 & str, const lString8 & delimiter)
33         : chunks(NULL), count(0), size(0)
34     {
35         split(str, delimiter);
36     }
37     void reserve(int space);
38     int add(const lString8 & str);
add(const char * str)39     int add(const char * str) { return add(lString8(str)); }
addAll(const lString8Collection & src)40     void addAll(const lString8Collection & src) {
41     	for (int i = 0; i < src.length(); i++)
42     		add(src[i]);
43     }
44     /// calculate hash
45     lUInt32 getHash() const;
46     /// split string by delimiters, and add all substrings to collection
47     void split(const lString8 & str, const lString8 & delimiter);
48     void erase(int offset, int count);
at(int index)49     const lString8 & at(int index)
50     {
51         return ((lString8 *)chunks)[index];
52     }
53     const lString8 & operator [] (int index) const
54     {
55         return ((lString8 *)chunks)[index];
56     }
57     lString8 & operator [] (int index)
58     {
59         return ((lString8 *)chunks)[index];
60     }
61     lString8Collection& operator=(const lString8Collection& other)
62     {
63         clear();
64         reserve(other.size);
65         addAll(other);
66         return *this;
67     }
68     bool operator==(const lString8Collection& other) const;
69     bool operator!=(const lString8Collection& other) const;
length()70     int length() const { return count; }
71     void clear();
~lString8Collection()72     ~lString8Collection()
73     {
74         clear();
75     }
empty()76     bool empty() const { return 0 == count; }
77 };
78 
79 #endif // __LV_STRING8COLLECTION_H_INCLUDED__
80