summaryrefslogtreecommitdiff
path: root/tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools.h')
-rw-r--r--tools.h52
1 files changed, 45 insertions, 7 deletions
diff --git a/tools.h b/tools.h
index 5d04807..8911967 100644
--- a/tools.h
+++ b/tools.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.h 1.98 2007/06/10 08:46:23 kls Exp $
+ * $Id: tools.h 1.102 2007/06/17 11:00:20 kls Exp $
*/
#ifndef __TOOLS_H
@@ -92,7 +92,15 @@ int Utf8CharSet(uint c, char *s = NULL);
///< is given, only the number of bytes is returned and nothing is copied.
int Utf8SymChars(const char *s, int Symbols);
///< Returns the number of character bytes at the beginning of the given
- ///< string that form at most the given number of UTF-8 Symbols.
+ ///< string that form at most the given number of UTF-8 symbols.
+int Utf8StrLen(const char *s);
+ ///< Returns the number of UTF-8 symbols formed by the given string of
+ ///< character bytes.
+char *Utf8Strn0Cpy(char *Dest, const char *Src, int n);
+ ///< Copies at most n character bytes from Src to Dst, making sure that the
+ ///< resulting copy ends with a complete UTF-8 symbol. The copy is guaranteed
+ ///< to be zero terminated.
+ ///< Returns a pointer to Dest.
int Utf8ToArray(const char *s, uint *a, int Size);
///< Converts the given character bytes (including the terminating 0) into an
///< array of UTF-8 symbols of the given Size. Returns the number of symbols
@@ -394,7 +402,17 @@ private:
mutable int allocated;
mutable int size;
mutable T *data;
- void Realloc(int NewAllocated) const { data = (T *)realloc(data, (allocated = NewAllocated) * sizeof(T)); }
+ cVector(const cVector &Vector) {} // don't copy...
+ cVector &operator=(const cVector &Vector) { return *this; } // ...or assign this!
+ void Realloc(int Index) const
+ {
+ if (++Index > allocated) {
+ data = (T *)realloc(data, Index * sizeof(T));
+ for (int i = allocated; i < Index; i++)
+ data[i] = T(0);
+ allocated = Index;
+ }
+ }
public:
cVector(int Allocated = 10)
{
@@ -406,8 +424,9 @@ public:
virtual ~cVector() { free(data); }
T& At(int Index) const
{
+ Realloc(Index);
if (Index >= size)
- Realloc(size = Index + 1);
+ size = Index + 1;
return data[Index];
}
const T& operator[](int Index) const
@@ -419,12 +438,24 @@ public:
return At(Index);
}
int Size(void) const { return size; }
+ virtual void Insert(T Data, int Before = 0)
+ {
+ if (Before < size) {
+ Realloc(size);
+ memmove(&data[Before + 1], &data[Before], (size - Before) * sizeof(T));
+ size++;
+ data[Before] = Data;
+ }
+ else
+ Append(Data);
+ }
virtual void Append(T Data)
{
if (size >= allocated)
Realloc(allocated * 4 / 2); // increase size by 50%
data[size++] = Data;
}
+ virtual void Clear(void) {}
void Sort(__compar_fn_t Compare)
{
qsort(data, size, sizeof(T), Compare);
@@ -436,12 +467,19 @@ inline int CompareStrings(const void *a, const void *b)
return strcmp(*(const char **)a, *(const char **)b);
}
-class cFileNameList : public cVector<char *> {
+class cStringList : public cVector<char *> {
+public:
+ cStringList(int Allocated = 10): cVector<char *>(Allocated) {}
+ virtual ~cStringList();
+ int Find(const char *s) const;
+ void Sort(void) { cVector<char *>::Sort(CompareStrings); }
+ virtual void Clear(void);
+ };
+
+class cFileNameList : public cStringList {
public:
cFileNameList(const char *Directory = NULL);
- virtual ~cFileNameList();
bool Load(const char *Directory);
- int Find(const char *FileName);
};
class cHashObject : public cListObject {