]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | Cache - Structure definitions for the cache file | |
7 | ||
8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of | |
9 | this format. Also be sure to keep that file up-to-date!! | |
10 | ||
11 | Clients should always use the CacheIterators classes for access to the | |
12 | cache. They provide a simple STL-like method for traversing the links | |
13 | of the datastructure. | |
14 | ||
15 | See pkgcachegen.h for information about generating cache structures. | |
16 | ||
17 | ##################################################################### */ | |
18 | /*}}}*/ | |
19 | #ifndef PKGLIB_PKGSTRING_H | |
20 | #define PKGLIB_PKGSTRING_H | |
21 | ||
22 | #include <string> | |
23 | ||
24 | class srkString | |
25 | { | |
26 | public: | |
27 | const char *Start; | |
28 | size_t Size; | |
29 | ||
30 | srkString() : Start(NULL), Size(0) {} | |
31 | ||
32 | srkString(const char *Start, size_t Size) : Start(Start), Size(Size) {} | |
33 | srkString(const char *Start, const char *Stop) : Start(Start), Size(Stop - Start) {} | |
34 | srkString(const std::string &string) : Start(string.c_str()), Size(string.size()) {} | |
35 | ||
36 | bool empty() const { return Size == 0; } | |
37 | void clear() { Start = NULL; Size = 0; } | |
38 | ||
39 | void assign(const char *nStart, const char *nStop) { Start = nStart; Size = nStop - nStart; } | |
40 | void assign(const char *nStart, size_t nSize) { Start = nStart; Size = nSize; } | |
41 | ||
42 | size_t length() const { return Size; } | |
43 | size_t size() const { return Size; } | |
44 | ||
45 | typedef const char *const_iterator; | |
46 | const char *begin() const { return Start; } | |
47 | const char *end() const { return Start + Size; } | |
48 | ||
49 | char operator [](size_t index) const { return Start[index]; } | |
50 | ||
51 | operator std::string() { std::string Str; Str.assign(Start, Size); return Str; } | |
52 | }; | |
53 | ||
54 | int stringcmp(const std::string &lhs, const char *rhsb, const char *rhse); | |
55 | inline bool operator ==(const std::string &lhs, const srkString &rhs) { | |
56 | return stringcmp(lhs, rhs.begin(), rhs.end()) == 0; | |
57 | } | |
58 | ||
59 | #endif |