Mercurial > ~dholland > hg > ag > index.cgi
diff anagram/support/agstring.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/support/agstring.h Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,134 @@ +/********************************************************** + +The AnaGram Class Library + +The AgString Class +Copyright 1997 Parsifal Software. All Rights Reserved. +See the file COPYING for license and usage terms. + +***********************************************************/ + +#ifndef AGSTRING_H +#define AGSTRING_H + +#include <string.h> +#include "port.h" + +#include "agcontainer.h" + + +class AgString : public AgIndexedContainer<char> { +protected: + char *store; + + void lock(); + void unlock(); + void allocate(unsigned n); + +public: + class Cut { + char *store; + int index; + + void lock(); + void unlock(); + + public: + Cut() : store(0), index(0) {} + Cut(const AgString &s, const int x); + ~Cut() { unlock(); } + int exists() const { return store != 0; } + + char &character() const; + + AgString leftI() const; + AgString leftX() const; + AgString rightI() const; + AgString rightX() const; + + //AgString insertLeft(const AgString &s) const; + //AgString insertLeft(const char *s) const; + //AgString insertRight(const AgString &s) const; + //AgString insertRight(const char *s) const; + //String replace(const AgString &s) const; + //String replace(const char *s) const; + }; + + inline AgString() : store(0) {} + AgString(const unsigned n); + + AgString(const char *s); + AgString(const char *s, const unsigned n); + AgString(const AgString &s, const unsigned n); + AgString(const AgString &s); + AgString &operator = (const AgString &s); + AgString &operator = (const char *s); + + char &operator [] (const unsigned x); + + const char &operator [] (const unsigned x) const; + AgString &discardData(); + ~AgString(); + + AgString concat(const char *s) const; + AgString concat(const AgString s) const; + + inline int exists() const { return store != 0; } + inline unsigned size() const { return store ? strlen(store) : 0; } + + AgString &toUpper(); + //AgString &toLower(); + + inline char *pointer() const { + return store; + } + inline unsigned char *unsignedPointer() const { + return (unsigned char *) store; + } + + int operator < (const AgString &s) const; + int operator <= (const AgString &s) const; + int operator > (const AgString &s) const; + int operator >= (const AgString &s) const; + int operator == (const AgString &s) const; + int operator != (const AgString &s) const; + int iEq(const AgString &s) const; + + int operator < (const char *s) const; + int operator <= (const char *s) const; + int operator > (const char *s) const; + int operator >= (const char *s) const; + int operator == (const char *s) const; + int operator != (const char *s) const; + int iEq(const char *s) const; + + static AgString format(const char *fs, ...) PRINTFFY(1,2); + + Cut firstCut(const char c) const; + Cut lastCut(const char c) const; + Cut firstCut(const char* s) const; + Cut lastCut(const char* s) const; +}; + +inline AgString::AgString(const AgString &s) + : AgIndexedContainer<char>() +{ + store = s.store; + lock(); +} + +inline AgString::~AgString() { + unlock(); +} + +inline AgString &AgString::discardData() { + unlock(); + store = 0; + return *this; +} + +inline AgString &AgString::operator = (const char *s) { + return *this = AgString(s); +} + +#endif /* AGSTRING_H */