17 int numsegs = k.right - k.left;
25 result = WvHash(k.store->segments[k.left]);
28 result = WvHash(k.store->segments[k.left])
29 ^ WvHash(k.store->segments[k.right - 1])
38UniConfKey::Store UniConfKey::EMPTY_store(1, 1);
39UniConfKey::Store UniConfKey::ANY_store(1, 1,
"*");
40UniConfKey::Store UniConfKey::RECURSIVE_ANY_store(1, 1,
"...");
47UniConfKey::Store::Store(
int size,
int _ref_count,
56 parts.
split(key,
"/");
58 segments.resize(parts.count());
59 WvStringList::Iter part(parts);
60 for (part.rewind(); part.next(); )
64 segments.append(*part);
66 if (!!key && key[key.len()-1] ==
'/' && segments.used() > 0)
67 segments.append(Segment());
73 if ((right - left == 1 && !store->segments[right-1])
76 if (--store->ref_count == 0)
86void UniConfKey::unique()
88 if (store->ref_count == 1)
91 Store *old_store = store;
92 store =
new Store(right - left, 1);
93 for (
int i=left; i<right; ++i)
94 store->segments.append(old_store->segments[i]);
100 store(new Store(_path.numsegments() + _key.numsegments() + 1, 1)),
105 for (
int i=_path.left; i<_path.right; ++i)
107 const Segment &
segment = _path.store->segments[i];
110 store->segments.append(
segment);
113 for (
int j=_key.left; j<_key.right; ++j)
115 const Segment &
segment = _key.store->segments[j];
118 store->segments.append(
segment);
123 store->segments.append(
"");
134 store->segments.resize(right - left + _key.right - _key.left + 1);
135 for (
int j=_key.left; j<_key.right; ++j)
137 const Segment &
segment = _key.store->segments[j];
140 store->segments.replace(right,
segment);
145 store->segments.replace(right,
"");
156 for (
int j=_key.left; j<_key.right; ++j)
158 if (!!_key.store->segments[j])
161 store->segments.resize(shift + right - left, shift);
162 for (
int j=_key.left; j<_key.right; ++j)
164 const Segment &
segment = _key.store->segments[j];
167 store->segments.replace(left + j - _key.left,
segment);
176 for (
int i=left; i<right; ++i)
177 if (store->segments[i].iswild())
188 if (n > right - left)
196 return result.collapse();
202 if (j > right - left)
208 return UniConfKey(store, left + i, left + j).collapse();
214 switch (right - left)
217 return WvString::empty;
219 return store->segments[left];
223 for (
int i=left; i<right; ++i)
225 buf.
putstr(store->segments[i]);
238 for (i=left, j=other.left; i<right && j<other.right; ++i, ++j)
240 int val = strcasecmp(store->segments[i], other.store->segments[j]);
246 if (j == other.right)
259 if (*
this == pattern)
278 for (
int n = 0; ; ++n)
328 "this = '%s'\nkey = '%s'",
printable(), key);
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
UniConfKey()
Constructs an empty UniConfKey (the 'root').
UniConfKey subkey(const UniConfKey &key) const
If this UniConfKey is a subkey of 'key', then return the subkey portion.
UniConfKey removefirst(int n=1) const
Returns the path formed by removing the first n segments of this path.
WvString printable() const
Returns the canonical string representation of the path.
bool matches(const UniConfKey &pattern) const
Determines if the key matches a pattern.
UniConfKey range(int i, int j) const
Returns a range of segments.
int compareto(const UniConfKey &other) const
Compares two paths lexicographically.
void prepend(const UniConfKey &other)
Prepends a path to this path.
UniConfKey pop(int n=1)
Returns the path formed by the first n segments of this path and removes them from the key.
bool iswild() const
Returns true if the key contains a wildcard.
static UniConfKey RECURSIVE_ANY
bool hastrailingslash() const
Returns true if the key has a trailing slash.
int numsegments() const
Returns the number of segments in this path.
UniConfKey segment(int n) const
Returns the specified segment of the path.
void append(const UniConfKey &other)
Appends a path to this path.
bool isempty() const
Returns true if this path has zero segments (also known as root).
UniConfKey first(int n=1) const
Returns the path formed by the n first segments of this path.
bool suborsame(const UniConfKey &key) const
Returns true if 'key' is a the same, or a subkey, of this UniConfKey.
WvString getstr()
Returns the entire buffer as a null-terminated WvString.
void putstr(WvStringParm str)
Copies a WvString into the buffer, excluding the null-terminator.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
This is a WvList of WvStrings, and is a really handy way to parse strings.
void split(WvStringParm s, const char *splitchars=" \t\r\n", int limit=0)
split s and form a list ignoring splitchars (except at beginning and end) ie.
WvString is an implementation of a simple and efficient printable-string class.