summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorlordjaxom <lordjaxom>2005-02-10 22:24:26 +0000
committerlordjaxom <lordjaxom>2005-02-10 22:24:26 +0000
commitab8f0c75f39b57cd1e28545259fb08bb7b4925b3 (patch)
tree7b640887ef77c02bc09ffa0156684d76afa2492a /tools
parentc1cb77c3f8c7c0b3469e1d110f4e9a96bac16178 (diff)
downloadvdr-plugin-streamdev-ab8f0c75f39b57cd1e28545259fb08bb7b4925b3.tar.gz
vdr-plugin-streamdev-ab8f0c75f39b57cd1e28545259fb08bb7b4925b3.tar.bz2
- implemented audio track selection for http
Diffstat (limited to 'tools')
-rw-r--r--tools/file.c96
-rw-r--r--tools/file.h100
-rw-r--r--tools/shared.c90
-rw-r--r--tools/shared.h65
-rw-r--r--tools/string.c454
-rw-r--r--tools/string.h353
6 files changed, 0 insertions, 1158 deletions
diff --git a/tools/file.c b/tools/file.c
deleted file mode 100644
index 6ca3ac3..0000000
--- a/tools/file.c
+++ /dev/null
@@ -1,96 +0,0 @@
-#include "tools/file.h"
-
-#include <vdr/tools.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-cTBFile::cTBFile(void) {
-}
-
-cTBFile::~cTBFile() {
- Close();
-}
-
-bool cTBFile::Open(const std::string &Filename, int Mode, mode_t Attribs) {
- int filed;
-
- if (IsOpen()) Close();
-
- if ((filed = ::open(Filename.c_str(), Mode, Attribs)) == -1)
- return false;
-
- if (!cTBSource::Open(filed))
- return false;
-
- m_Filename = Filename;
- m_Anonymous = false;
- return true;
-}
-
-bool cTBFile::Open(uint Fileno) {
- if (IsOpen()) Close();
-
- if (!cTBSource::Open(Fileno))
- return false;
-
- m_Filename = (std::string)"<&" + (const char*)itoa(Fileno) + ">";
- m_Anonymous = true;
- return true;
-}
-
-bool cTBFile::Close(void) {
- bool ret = true;
-
- if (!IsOpen())
- ERRNUL(EBADF);
-
- if (::close(*this) == -1)
- ret = false;
-
- if (!cTBSource::Close())
- ret = false;
-
- m_Filename = "";
- return ret;
-}
-
-bool cTBFile::Unlink(void) const {
- if (m_Filename == "")
- ERRNUL(ENOENT);
-
- if (!IsOpen())
- ERRNUL(EBADF);
-
- if (m_Anonymous)
- ERRNUL(EINVAL);
-
- return cTBFile::Unlink(m_Filename);
-}
-
-bool cTBFile::Unlink(const std::string &Filename) {
- return (::unlink(Filename.c_str()) != -1);
-}
-
-ssize_t cTBFile::Size(void) const {
- struct stat buf;
-
- if (!IsOpen())
- ERRSYS(EBADF);
-
- if (fstat(*this, &buf) == -1)
- return -1;
-
- return buf.st_size;
-}
-
-ssize_t cTBFile::Size(const std::string &Filename) {
- struct stat buf;
-
- if (stat(Filename.c_str(), &buf) == -1)
- return -1;
-
- return buf.st_size;
-}
diff --git a/tools/file.h b/tools/file.h
deleted file mode 100644
index c46c94e..0000000
--- a/tools/file.h
+++ /dev/null
@@ -1,100 +0,0 @@
-#ifndef TOOLBOX_FILE_H
-#define TOOLBOX_FILE_H
-
-#include "tools/tools.h"
-#include "tools/source.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string>
-
-/* cTBFile provides a cTBSource-derived interface for input and output on UNIX
- files. */
-
-class cTBFile: public cTBSource {
-private:
- bool m_Anonymous;
- std::string m_Filename;
-
- /* Unhide and forbid baseclass method */
- virtual bool Open(int Fd, bool IsUnixFd = false) { return false; }
-
-public:
- cTBFile(void);
- virtual ~cTBFile();
-
- /* enum eFileType represents the modes a file can be opened with. The full
- open mode is one of the first three, maybe or'ed with one of the others.
- */
- enum eFileType {
- ReadOnly = O_RDONLY,
- WriteOnly = O_WRONLY,
- ReadWrite = O_RDWR,
-
- Create = O_CREAT,
- Exclude = O_EXCL,
- Truncate = O_TRUNC,
- Append = O_APPEND
- };
-
- /* See cTBSource::SysRead()
- Reimplemented for UNIX files. */
- virtual ssize_t SysRead(void *Buffer, size_t Length) const;
-
- /* See cTBSource::SysWrite()
- Reimplemented for UNIX files. */
- virtual ssize_t SysWrite(const void *Buffer, size_t Length) const;
-
- /* Open() opens the file referred to by Filename according to the given
- Mode. If the file is created, it receives the attributes given by
- Attribs, defaulting to rw-------. Returns true on success and false on
- error, setting errno appropriately. */
- virtual bool Open(const std::string &Filename, int Mode,
- mode_t Attribs = S_IRUSR + S_IWUSR);
-
- /* Open() associates this file object with Fileno. Fileno must refer to a
- previously opened file descriptor, which will be set non-blocking by
- this call. If successful, true is returned, false otherwise and errno
- is set appropriately. */
- virtual bool Open(uint Fileno);
-
- /* Close() closes the associated file descriptor and releases all
- structures. Returns true on success and false otherwise, setting errno
- appropriately. The object is in the closed state afterwards, even if
- an error occured. */
- virtual bool Close(void);
-
- /* Unlink() unlinks (deletes) the associated file from the underlying
- filesystem. Returns true on success and false otherwise, setting errno
- appropriately. The file must be opened by filename to use this. */
- virtual bool Unlink(void) const;
-
- /* Unlink() unlinks (deletes) the file referred to by Filename from the
- underlying filesystem. Returns true on success and false otherwise,
- setting errno appropriately. */
- static bool Unlink(const std::string &Filename);
-
- /* Size() returns the current size of the associated file. Returns the
- exact size of the file in bytes. Returns -1 on error, setting errno to
- an appropriate value. */
- virtual ssize_t Size(void) const;
-
- /* Size() returns the current size of the file referred to by Filename.
- Symbolic links are followed (the size of the link-target is returned).
- Returns the exact size of the file in bytes. Returns -1 on error,
- setting errno to an appropriate value. */
- static ssize_t Size(const std::string &Filename);
-};
-
-inline ssize_t cTBFile::SysRead(void *Buffer, size_t Length) const {
- return ::read(*this, Buffer, Length);
-}
-
-inline ssize_t cTBFile::SysWrite(const void *Buffer, size_t Length) const {
- return ::write(*this, Buffer, Length);
-}
-
-
-#endif // TOOLBOX_FILE_H
diff --git a/tools/shared.c b/tools/shared.c
deleted file mode 100644
index ef20969..0000000
--- a/tools/shared.c
+++ /dev/null
@@ -1,90 +0,0 @@
-#include "tools/shared.h"
-
-#include <errno.h>
-#include <stddef.h>
-#include <string.h>
-
-cSharedData *cSharedData::Construct (size_t Length) {
- size_t reallength = sizeof(cSharedData) + Length;
- cSharedData *ret = (cSharedData*)new char[reallength];
-
- ret->m_Length = Length;
- ret->m_NumRefs = 0;
- return ret;
-}
-
-cTBShared::cTBShared(void) {
- m_Buffer = NULL;
-}
-
-cTBShared::cTBShared (const cTBShared &src) {
- m_Buffer = src.m_Buffer;
- if (m_Buffer)
- ++*m_Buffer;
-}
-
-cTBShared::~cTBShared () {
- if (m_Buffer)
- Release();
-}
-
-void cTBShared::Clear () {
- if (m_Buffer)
- Release();
- m_Buffer = 0;
-}
-
-void cTBShared::Set (const cTBShared &src) {
- if (m_Buffer)
- Release();
-
- m_Buffer = src.m_Buffer;
- if (m_Buffer)
- ++*m_Buffer;
-}
-
-void cTBShared::Release () {
- CHECK_PTR(m_Buffer);
-
- if (--*m_Buffer == 0)
- delete[] (char*)m_Buffer;
-
- m_Buffer = 0;
-}
-
-void cTBShared::Release(uint newsize) {
- CHECK_PTR(m_Buffer);
-
- Allocate(newsize, true);
-}
-
-void cTBShared::Exclusive () {
- CHECK_PTR(m_Buffer);
-
- if (m_Buffer->Refs() == 1)
- return;
-
- cSharedData *copy = cSharedData::Construct(m_Buffer->Size());
- memcpy(*copy, *m_Buffer, m_Buffer->Size());
-
- Release();
-
- m_Buffer = copy;
- ++*m_Buffer;
-}
-
-void cTBShared::Allocate (size_t len, bool keep /* = false */) {
- if (m_Buffer && (m_Buffer->Refs() == 1) && (m_Buffer->Size() == len))
- return;
-
- cSharedData *newBuffer = cSharedData::Construct(len);
- if (m_Buffer) {
- if (keep)
- memcpy(*newBuffer, *m_Buffer, len < m_Buffer->Size() ? len : m_Buffer->Size());
-
- Release();
- }
- m_Buffer = newBuffer;
- ++*m_Buffer;
-}
-
diff --git a/tools/shared.h b/tools/shared.h
deleted file mode 100644
index bacb708..0000000
--- a/tools/shared.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef TOOLBOX_SHARED_H
-#define TOOLBOX_SHARED_H
-
-#include "tools/tools.h"
-
-struct cSharedData {
-private:
- uint m_Length;
- uint m_NumRefs;
-
-public:
- static cSharedData *Construct (size_t Length);
-
- operator char * () { return this ? (char*)(this+1) : 0; }
-
- uint operator++ () { return ++m_NumRefs; }
- uint operator-- () { return --m_NumRefs; }
-
- size_t Size() const { return m_Length; }
-
- uint Refs () const { return m_NumRefs; }
-};
-
-class cTBShared {
-private:
- cSharedData *m_Buffer;
-
-protected:
- void Release();
- void Exclusive();
- void Allocate(size_t len, bool keep = false);
-
- char *Buffer() const { return m_Buffer ? (char*)*m_Buffer : (char*)0; }
-
-public:
- cTBShared (void);
- cTBShared (const cTBShared &src);
- virtual ~cTBShared ();
-
- virtual void Clear ();
- virtual void Set (const cTBShared &src);
-
- virtual char *Buffer (uint size);
- virtual void Release (uint newsize);
-
- cTBShared &operator= (const cTBShared &src) { Set(src); return *this; }
-
- operator const void * () const { return m_Buffer ? (const void*)*m_Buffer : (const void*)0; }
- operator void * () const { return m_Buffer ? (void*)*m_Buffer : (void*)0; }
-
- operator const char * () const { return m_Buffer ? (const char*)*m_Buffer : (const char*)0; }
-
- size_t Size() const { return m_Buffer ? m_Buffer->Size() : 0; }
- size_t Length() const { return m_Buffer ? m_Buffer->Size() : 0; }
-
- // friend cSource &operator>> (cSource &dest, cTBShared &str);
-};
-
-inline char *cTBShared::Buffer(uint size) {
- if ((!m_Buffer) || (m_Buffer->Refs() > 1) || (size > m_Buffer->Size()))
- Allocate(size, true);
- return Buffer();
-}
-
-#endif // TOOLBOX_SHARED_H
diff --git a/tools/string.c b/tools/string.c
deleted file mode 100644
index 0897ece..0000000
--- a/tools/string.c
+++ /dev/null
@@ -1,454 +0,0 @@
-#include "tools/string.h"
-#ifdef TOOLBOX_REGEX
-# include "tools/regex.h"
-#endif
-
-#include <string.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <limits.h>
-#include <math.h>
-#include <errno.h>
-
-const cTBString cTBString::Null;
-
-cTBString::cTBString():
- cTBShared(),
- m_StringLen(0) {
-}
-
-cTBString::cTBString(const cTBString &src):
- cTBShared(src),
- m_StringLen(src.m_StringLen) {
-}
-
-cTBString::cTBString(const char *src) {
- Set(src);
-}
-
-cTBString::cTBString(const uchar *src) {
- Set(src);
-}
-
-cTBString::cTBString(char src) {
- Set(src);
-}
-
-cTBString::~cTBString () {
-}
-
-void cTBString::Release(uint newsize) {
- m_StringLen = newsize;
- cTBShared::Release(m_StringLen + 1);
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Clear() {
- cTBShared::Clear();
- m_StringLen = 0;
-}
-
-void cTBString::Set(const cTBString &String) {
- cTBShared::Set(String);
- m_StringLen = String.m_StringLen;
-}
-
-void cTBString::Set (const char *String) {
- m_StringLen = strlen(String);
- Allocate(m_StringLen + 1);
-
- memcpy(Buffer(), String, m_StringLen);
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Set (const uchar *String) {
- Set((const char*)String);
-}
-
-void cTBString::Set (char Character) {
- m_StringLen = 1;
- Allocate(m_StringLen + 1);
-
- Buffer()[0] = Character;
- Buffer()[1] = 0;
-}
-
-void cTBString::Fill(char Character, int Length) {
- if (Length != -1) {
- m_StringLen = Length;
- Allocate(m_StringLen + 1);
- }
- memset(Buffer(), Character, m_StringLen);
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Append(const cTBString &src) {
- Allocate(m_StringLen + src.m_StringLen + 1, true);
-
- memcpy(Buffer() + m_StringLen, src.Buffer(), src.m_StringLen);
- m_StringLen += src.m_StringLen;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Append(const char *src) {
- uint len = strlen(src);
- Allocate(m_StringLen + len + 1, true);
-
- memcpy(Buffer() + m_StringLen, src, len);
- m_StringLen += len;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Append(char src) {
- Allocate(m_StringLen + 2, true);
-
- Buffer()[m_StringLen] = src;
- ++m_StringLen;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Prepend(const cTBString &src) {
- Allocate(m_StringLen + src.m_StringLen + 1, true);
-
- memmove(Buffer() + src.m_StringLen, Buffer(), m_StringLen);
- memcpy(Buffer(), src.Buffer(), src.m_StringLen);
- m_StringLen += src.m_StringLen;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Prepend(const char *src) {
- uint len = strlen(src);
- Allocate(m_StringLen + len + 1, true);
-
- memmove(Buffer() + len, Buffer(), m_StringLen);
- memcpy(Buffer(), src, len);
- m_StringLen += len;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Prepend(char src) {
- Allocate(m_StringLen + 2, true);
-
- memmove(Buffer() + 1, Buffer(), m_StringLen);
- Buffer()[0] = src;
- Buffer()[++m_StringLen] = 0;
-}
-
-void cTBString::Insert(uint Index, const cTBString &String) {
- Allocate(m_StringLen + String.m_StringLen + 1, true);
-
- memmove(Buffer() + Index + String.m_StringLen, Buffer() + Index, m_StringLen - Index);
- memcpy(Buffer() + Index, String.Buffer(), String.m_StringLen);
- m_StringLen += String.m_StringLen;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Insert(uint Index, const char *String) {
- uint len = strlen(String);
- Allocate(m_StringLen + len + 1, true);
-
- memmove(Buffer() + Index + len, Buffer() + Index, m_StringLen - Index);
- memcpy(Buffer() + Index, String, len);
- m_StringLen += len;
- Buffer()[m_StringLen] = 0;
-}
-
-void cTBString::Insert(uint Index, char Character) {
- Allocate(m_StringLen + 2, true);
-
- memmove(Buffer() + Index + 1, Buffer() + Index, m_StringLen - Index);
- Buffer()[Index] = Character;
- Buffer()[++m_StringLen] = 0;
-}
-
-RETURNS(cTBString, cTBString::Left(uint count) const, ret)
- if (count > m_StringLen)
- count = m_StringLen;
-
- ret.Allocate(count + 1);
- memcpy(ret.Buffer(), Buffer(), count);
- ret.Buffer()[count] = 0;
- ret.m_StringLen = count;
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Right(uint count) const, ret)
- if (count > m_StringLen)
- count = m_StringLen;
-
- ret.Allocate(count + 1);
- memcpy(ret.Buffer(), Buffer() + m_StringLen - count, count);
- ret.Buffer()[count] = 0;
- ret.m_StringLen = count;
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Mid(int idx, int count) const, ret)
- if (idx < 0)
- idx = m_StringLen + idx;
-
- if ((count < 0) || (count > (int)m_StringLen - idx))
- count = m_StringLen - idx;
-
- ret.Allocate(count + 1);
- memcpy(ret.Buffer(), Buffer() + idx, count);
- ret.Buffer()[count] = 0;
- ret.m_StringLen = count;
-RETURN(ret)
-
-int cTBString::Find (const cTBString &String, uint Offset) const {
- if (Offset >= m_StringLen)
- return -1;
-
- char *pos = strstr(Buffer() + Offset, String.Buffer());
- if (pos) return (pos - Buffer());
- else return -1;
-}
-
-int cTBString::Find (const char *String, uint Offset) const {
- if (Offset >= m_StringLen)
- return -1;
-
- char *pos = strstr(Buffer() + Offset, String);
- if (pos) return (pos - Buffer());
- else return -1;
-}
-
-int cTBString::Find (char Character, uint Offset) const {
- if (Offset >= m_StringLen)
- return -1;
-
- char *pos = strchr(Buffer() + Offset, Character);
- if (pos) return (pos - Buffer());
- else return -1;
-}
-
-#ifdef TOOLBOX_REGEX
-bool cTBString::Find (cTBRegEx &Regex, uint Offset) const {
- return Regex.Match(Buffer(), Offset);
-}
-#endif
-
-void cTBString::Format (const char *fmt, ...) {
- int n, size = 128;
- va_list ap;
-
- char *buf = Buffer(size);
-
- while (1) {
- va_start(ap, fmt);
- n = vsnprintf(buf, size, fmt, ap);
- va_end(ap);
-
- if ((n > -1) && (n < size))
- break;
-
- if (n > -1)
- size = n + 1;
- else
- size *= 2;
-
- buf = Buffer(size);
- }
- Release(n);
-}
-
-void cTBString::Format(const cTBString &fmt, ...) {
- int n, size = 128;
- va_list ap;
-
- char *buf = Buffer(size);
-
- while (1) {
- va_start(ap, &fmt);
- n = vsnprintf(buf, size, fmt, ap);
- va_end(ap);
-
- if ((n > -1) && (n < size))
- break;
-
- if (n > -1)
- size = n + 1;
- else
- size *= 2;
-
- buf = Buffer(size);
- }
- Release(n);
-}
-
-template<cTBString::TOFUNC F>
-cTBString cTBString::ToAnything(void) const {
- const char *src;
- char *dest;
- cTBString ret;
-
- src = Buffer();
- dest = ret.Buffer(m_StringLen + 1);
-
- for (; src < Buffer() + m_StringLen; ++src, ++dest)
- *dest = F(*src);
-
- *dest = '\0';
-
- ret.Release(m_StringLen);
- return ret;
-}
-
-template<cTBString::ISFUNC F>
-bool cTBString::IsAnything(void) const {
- const char *ptr = Buffer();
-
- for (; ptr < Buffer() + m_StringLen; ++ptr)
- if (!F(*ptr)) return false;
-
- return true;
-}
-
-short cTBString::ToShort(bool *Ok) const {
- long ret;
- char *endptr;
- bool res = false;
-
- ret = strtol(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && ret >= SHRT_MIN && ret <= SHRT_MAX)
- res = true;
-
- if (Ok) *Ok = res;
- return (short)ret;
-}
-
-ushort cTBString::ToUShort(bool *Ok) const {
- ulong ret;
- char *endptr;
- bool res = false;
-
- ret = strtoul(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && ret <= USHRT_MAX)
- res = true;
-
- if (Ok) *Ok = res;
- return (ushort)ret;
-}
-
-int cTBString::ToInt(bool *Ok) const {
- long ret;
- char *endptr;
- bool res = false;
-
- ret = strtol(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && ret >= INT_MIN && ret <= INT_MAX)
- res = true;
-
- if (Ok) *Ok = res;
- return (int)ret;
-}
-
-uint cTBString::ToUInt(bool *Ok) const {
- ulong ret;
- char *endptr;
- bool res = false;
-
- ret = strtoul(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && ret <= UINT_MAX)
- res = true;
-
- if (Ok) *Ok = res;
- return (uint)ret;
-}
-
-long cTBString::ToLong(bool *Ok) const {
- long ret;
- char *endptr;
- bool res = false;
-
- errno = 0;
- ret = strtol(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && errno != ERANGE)
- res = true;
-
- if (Ok) *Ok = res;
- return (long)ret;
-}
-
-ulong cTBString::ToULong(bool *Ok) const {
- ulong ret;
- char *endptr;
- bool res = false;
-
- errno = 0;
- ret = strtoul(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && errno != ERANGE)
- res = true;
-
- if (Ok) *Ok = res;
- return (ulong)ret;
-}
-
-float cTBString::ToFloat(bool *Ok) const {
- double ret;
- char *endptr;
- bool res = false;
-
- ret = strtod(Buffer(), &endptr);
-
- if (!IsEmpty() && *endptr == '\0' && errno != ERANGE)
- res = true;
-
- if (Ok) *Ok = res;
- return (float)ret;
-}
-
-double cTBString::ToDouble(bool *Ok) const {
- double ret;
- char *endptr;
- bool res = false;
-
- errno = 0;
- ret = strtol(Buffer(), &endptr, 0);
-
- if (!IsEmpty() && *endptr == '\0' && errno != ERANGE)
- res = true;
-
- if (Ok) *Ok = res;
- return (double)ret;
-}
-
-RETURNS(cTBString, cTBString::Number(short Num), ret)
- ret.Format("%hd", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(ushort Num), ret)
- ret.Format("%hu", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(int Num), ret)
- ret.Format("%d", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(uint Num), ret)
- ret.Format("%u", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(long Num), ret)
- ret.Format("%ld", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(ulong Num), ret)
- ret.Format("%lu", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(float Num), ret)
- ret.Format("%f", Num);
-RETURN(ret)
-
-RETURNS(cTBString, cTBString::Number(double Num), ret)
- ret.Format("%f", Num);
-RETURN(ret)
-
diff --git a/tools/string.h b/tools/string.h
deleted file mode 100644
index 2e81929..0000000
--- a/tools/string.h
+++ /dev/null
@@ -1,353 +0,0 @@
-#ifndef TOOLBOX_STRING_H
-#define TOOLBOX_STRING_H
-
-#include "tools/tools.h"
-#include "tools/shared.h"
-//#include "tools/source.h"
-
-#include <ctype.h>
-#include <stddef.h>
-#include <string.h>
-
-#ifdef TOOLBOX_REGEX
-class cTBRegEx;
-#endif
-
-class cTBString: public cTBShared {
-private:
- uint m_StringLen;
-
- /* Unhide and forbid baseclass method */
- virtual void Set (const cTBShared &src) {}
-
-public:
- cTBString ();
- cTBString (const cTBString &src);
- cTBString (const uchar *src);
- cTBString (const char *src);
- cTBString (char src);
- virtual ~cTBString ();
-
- static const cTBString Null;
-
- void Clear ();
- void Set (const cTBString &String);
- void Set (const uchar *String);
- void Set (const char *String);
- void Set (char Character);
-
- void Fill (char Character, int Length = -1);
-
- void Release (uint newsize);
-
- cTBString &operator= (const cTBString &src) { Set(src); return *this; }
- cTBString &operator= (const char *src) { Set(src); return *this; }
- cTBString &operator= (char src) { Set(src); return *this; }
-
- void Append (const cTBString &src);
- void Append (const char *src);
- void Append (char src);
-
- friend cTBString operator+ (const cTBString &a, const cTBString &b);
- friend cTBString operator+ (const cTBString &a, const char *b);
- friend cTBString operator+ (const char *a, const cTBString &b);
- friend cTBString operator+ (const cTBString &a, char b);
- friend cTBString operator+ (char a, const cTBString &b);
-
- friend cTBString &operator+= (cTBString &a, const cTBString &b);
- friend cTBString &operator+= (cTBString &a, const char *b);
- friend cTBString &operator+= (cTBString &a, char b);
-
- void Prepend (const cTBString &src);
- void Prepend (const char *src);
- void Prepend (char src);
-
- void Insert (uint Index, const cTBString &src);
- void Insert (uint Index, const char *src);
- void Insert (uint Index, char src);
-
- char At (uint i) const;
- char operator[] (int i) const { return At((uint)i); }
-
- char &At (uint i);
- char &operator[] (int i) { return At(i); }
-
- cTBString Left (uint Count) const;
- cTBString Right (uint Count) const;
- cTBString Mid (int idx, int Count = -1) const;
-
- int Find (const cTBString &String, uint Offset = 0) const;
- int Find (const char *String, uint Offset = 0) const;
- int Find (char Character, uint Offset = 0) const;
-#ifdef TOOLBOX_REGEX
- bool Find (cTBRegEx &Regex, uint Offset = 0) const;
-#endif
-
- void Format (const char *fmt, ...)
-#if defined(__GNUC__)
- __attribute__ ((format (printf, 2, 3)))
-#endif
- ;
- void Format (const cTBString &fmt, ...);
-
- typedef int(*TOFUNC)(int);
- template<TOFUNC F> cTBString ToAnything(void) const;
-
- cTBString ToUpper (void) const { return ToAnything<toupper>(); }
- cTBString ToLower (void) const { return ToAnything<tolower>(); }
-
- typedef int(*ISFUNC)(int);
- template<ISFUNC F> bool IsAnything(void) const;
-
- bool IsAlnum(void) const { return IsAnything<isalnum>(); }
- bool IsAlpha(void) const { return IsAnything<isalpha>(); }
- bool IsAscii(void) const { return IsAnything<isascii>(); }
- bool IsCntrl(void) const { return IsAnything<iscntrl>(); }
- bool IsDigit(void) const { return IsAnything<isdigit>(); }
- bool IsGraph(void) const { return IsAnything<isgraph>(); }
- bool IsLower(void) const { return IsAnything<islower>(); }
- bool IsPrint(void) const { return IsAnything<isprint>(); }
- bool IsPunct(void) const { return IsAnything<ispunct>(); }
- bool IsSpace(void) const { return IsAnything<isspace>(); }
- bool IsUpper(void) const { return IsAnything<isupper>(); }
- bool IsXdigit(void) const { return IsAnything<isxdigit>(); }
-
-#if defined(_GNU_SOURCE)
- bool IsBlank(void) const { return IsAnything<isblank>(); }
-#endif
-
- uint Length (void) const { return m_StringLen; }
- bool IsEmpty (void) const { return m_StringLen == 0; }
- bool IsNull (void) const { return Buffer() == 0; }
-
- short ToShort(bool *Ok = NULL) const;
- ushort ToUShort(bool *Ok = NULL) const;
- int ToInt(bool *Ok = NULL) const;
- uint ToUInt(bool *Ok = NULL) const;
- long ToLong(bool *Ok = NULL) const;
- ulong ToULong(bool *Ok = NULL) const;
- float ToFloat(bool *Ok = NULL) const;
- double ToDouble(bool *Ok = NULL) const;
-
- static cTBString Number(short Num);
- static cTBString Number(ushort Num);
- static cTBString Number(int Num);
- static cTBString Number(uint Num);
- static cTBString Number(long Num);
- static cTBString Number(ulong Num);
- static cTBString Number(float Num);
- static cTBString Number(double Num);
-
- friend bool operator== (const cTBString &str1, const cTBString &str2);
- friend bool operator== (const cTBString &str1, const char *str2);
- friend bool operator== (const char *str1, const cTBString &str2);
-
- friend bool operator!= (const cTBString &str1, const cTBString &str2);
- friend bool operator!= (const cTBString &str1, const char *str2);
- friend bool operator!= (const char *str1, const cTBString &str2);
-
- friend bool operator< (const cTBString &str1, const cTBString &str2);
- friend bool operator< (const cTBString &str1, const char *str2);
- friend bool operator< (const char *str1, const cTBString &str2);
-
- friend bool operator> (const cTBString &str1, const cTBString &str2);
- friend bool operator> (const cTBString &str1, const char *str2);
- friend bool operator> (const char *str1, const cTBString &str2);
-
- friend bool operator<= (const cTBString &str1, const cTBString &str2);
- friend bool operator<= (const cTBString &str1, const char *str2);
- friend bool operator<= (const char *str1, const cTBString &str2);
-
- friend bool operator>= (const cTBString &str1, const cTBString &str2);
- friend bool operator>= (const cTBString &str1, const char *str2);
- friend bool operator>= (const char *str1, const cTBString &str2);
-};
-
-inline char cTBString::At(uint idx) const {
- ASSERT(idx >= m_StringLen);
- return Buffer() ? Buffer()[idx] : 0;
-}
-
-inline char &cTBString::At(uint idx) {
- static char null = 0;
- ASSERT(idx >= m_StringLen);
- if (Buffer()) {
- Exclusive();
- return Buffer()[idx];
- } else
- return (null = 0);
-}
-
-inline
-RETURNS(cTBString, operator+(const cTBString &a, const cTBString &b), ret(a))
- ret.Append(b);
-RETURN(ret)
-
-inline
-RETURNS(cTBString, operator+ (const cTBString &a, const char *b), ret(a))
- ret.Append(b);
-RETURN(ret)
-
-inline
-RETURNS(cTBString, operator+ (const char *a, const cTBString &b), ret(a))
- ret.Append(b);
-RETURN(ret)
-
-inline
-RETURNS(cTBString, operator+ (const cTBString &a, char b), ret(a))
- ret.Append(b);
-RETURN(ret)
-
-inline
-RETURNS(cTBString, operator+ (char a, const cTBString &b), ret(a))
- ret.Append(b);
-RETURN(ret)
-
-inline cTBString &operator+= (cTBString &a, const cTBString &b) {
- a.Append(b);
- return a;
-}
-
-inline cTBString &operator+= (cTBString &a, const char *b) {
- a.Append(b);
- return a;
-}
-
-inline cTBString &operator+= (cTBString &a, char b) {
- a.Append(b);
- return a;
-}
-
-inline bool operator== (const cTBString &str1, const cTBString &str2) {
- if (str1.Length() != str2.Length())
- return false;
- return memcmp(str1.Buffer(), str2.Buffer(), str1.Length()) == 0;
-}
-
-inline bool operator== (const cTBString &str1, const char *str2) {
- uint len = strlen(str2);
- if (str1.Length() != len)
- return false;
- return memcmp(str1.Buffer(), str2, len) == 0;
-}
-
-inline bool operator== (const char *str1, const cTBString &str2) {
- uint len = strlen(str1);
- if (len != str2.Length())
- return false;
- return memcmp(str1, str2.Buffer(), len) == 0;
-}
-
-inline bool operator!= (const cTBString &str1, const cTBString &str2) {
- if (str1.Length() != str2.Length())
- return true;
- return memcmp(str1.Buffer(), str2.Buffer(), str1.Length()) != 0;
-}
-
-inline bool operator!= (const cTBString &str1, const char *str2) {
- uint len = strlen(str2);
- if (str1.Length() != len)
- return true;
- return memcmp(str1.Buffer(), str2, len) != 0;
-}
-
-inline bool operator!= (const char *str1, const cTBString &str2) {
- uint len = strlen(str1);
- if (len != str2.Length())
- return true;
- return memcmp(str1, str2.Buffer(), len) != 0;
-}
-
-inline bool operator< (const cTBString &str1, const cTBString &str2) {
- int ret = memcmp(str1.Buffer(), str2.Buffer(), str1.Length() < str2.Length() ? str1.Length() : str2.Length());
- if ((ret < 0) || ((ret == 0) && (str1.Length() < str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator< (const cTBString &str1, const char *str2) {
- uint len = strlen(str2);
- int ret = memcmp(str1.Buffer(), str2, str1.Length() < len ? str1.Length() : len);
- if ((ret < 0) || ((ret == 0) && (str1.Length() < len)))
- return true;
- return false;
-}
-
-inline bool operator< (const char *str1, const cTBString &str2) {
- uint len = strlen(str1);
- int ret = memcmp(str1, str2.Buffer(), len < str2.Length() ? len : str2.Length());
- if ((ret < 0) || ((ret == 0) && (len < str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator> (const cTBString &str1, const cTBString &str2) {
- int ret = memcmp(str1.Buffer(), str2.Buffer(), str1.Length() < str2.Length() ? str1.Length() : str2.Length());
- if ((ret > 0) || ((ret == 0) && (str1.Length() < str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator> (const cTBString &str1, const char *str2) {
- uint len = strlen(str2);
- int ret = memcmp(str1.Buffer(), str2, str1.Length() < len ? str1.Length() : len);
- if ((ret > 0) || ((ret == 0) && (str1.Length() < len)))
- return true;
- return false;
-}
-
-inline bool operator> (const char *str1, const cTBString &str2) {
- uint len = strlen(str1);
- int ret = memcmp(str1, str2.Buffer(), len < str2.Length() ? len : str2.Length());
- if ((ret > 0) || ((ret == 0) && (len < str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator<= (const cTBString &str1, const cTBString &str2) {
- int ret = memcmp(str1.Buffer(), str2.Buffer(), str1.Length() < str2.Length() ? str1.Length() : str2.Length());
- if ((ret < 0) || ((ret == 0) && (str1.Length() <= str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator<= (const cTBString &str1, const char *str2) {
- uint len = strlen(str2);
- int ret = memcmp(str1.Buffer(), str2, str1.Length() < len ? str1.Length() : len);
- if ((ret < 0) || ((ret == 0) && (str1.Length() <= len)))
- return true;
- return false;
-}
-
-inline bool operator<= (const char *str1, const cTBString &str2) {
- uint len = strlen(str1);
- int ret = memcmp(str1, str2.Buffer(), len < str2.Length() ? len : str2.Length());
- if ((ret < 0) || ((ret == 0) && (len <= str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator>= (const cTBString &str1, const cTBString &str2) {
- int ret = memcmp(str1.Buffer(), str2.Buffer(), str1.Length() < str2.Length() ? str1.Length() : str2.Length());
- if ((ret > 0) || ((ret == 0) && (str1.Length() >= str2.Length())))
- return true;
- return false;
-}
-
-inline bool operator>= (const cTBString &str1, const char *str2) {
- uint len = strlen(str2);
- int ret = memcmp(str1.Buffer(), str2, str1.Length() < len ? str1.Length() : len);
- if ((ret > 0) || ((ret == 0) && (str1.Length() >= len)))
- return true;
- return false;
-}
-
-inline bool operator>= (const char *str1, const cTBString &str2) {
- uint len = strlen(str1);
- int ret = memcmp(str1, str2.Buffer(), len < str2.Length() ? len : str2.Length());
- if ((ret > 0) || ((ret == 0) && (len >= str2.Length())))
- return true;
- return false;
-}
-
-#endif // TOOLBOX_STRING_H