filters

GString.h

00001 //========================================================================
00002 //
00003 // GString.h
00004 //
00005 // Simple variable-length string type.
00006 //
00007 // Copyright 1996-2002 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef GSTRING_H
00012 #define GSTRING_H
00013 
00014 #include <aconf.h>
00015 
00016 
00017 #include <string.h>
00018 
00019 class GString {
00020 public:
00021 
00022   // Create an empty string.
00023   GString();
00024 
00025   // Create a string from a C string.
00026   GString(const char *sA);
00027 
00028   // Create a string from <lengthA> chars at <sA>.  This string
00029   // can contain null characters.
00030   GString(const char *sA, int lengthA);
00031 
00032   // Create a string from <lengthA> chars at <idx> in <str>.
00033   GString(GString *str, int idx, int lengthA);
00034 
00035   // Copy a string.
00036   GString(GString *str);
00037   GString *copy() { return new GString(this); }
00038 
00039   // Concatenate two strings.
00040   GString(GString *str1, GString *str2);
00041 
00042   // Convert an integer to a string.
00043   static GString *fromInt(int x);
00044 
00045   // Destructor.
00046   ~GString();
00047 
00048   // Get length.
00049   int getLength() const { return length; }
00050 
00051   // Get C string.
00052   const char *getCString() const { return s; }
00053   char *getCString() { return s; }
00054 
00055   // Get <i>th character.
00056   char getChar(int i) const { return s[i]; }
00057 
00058   // Change <i>th character.
00059   void setChar(int i, char c) { s[i] = c; }
00060 
00061   // Clear string to zero length.
00062   GString *clear();
00063 
00064   // Append a character or string.
00065   GString *append(char c);
00066   GString *append(GString *str);
00067   GString *append(const char *str);
00068   GString *append(const char *str, int lengthA);
00069 
00070   // Insert a character or string.
00071   GString *insert(int i, char c);
00072   GString *insert(int i, GString *str);
00073   GString *insert(int i, const char *str);
00074   GString *insert(int i, const char *str, int lengthA);
00075 
00076   // Delete a character or range of characters.
00077   GString *del(int i, int n = 1);
00078 
00079   // Convert string to all-upper/all-lower case.
00080   GString *upperCase();
00081   GString *lowerCase();
00082 
00083   // Compare two strings:  -1:<  0:=  +1:>
00084   // These functions assume the strings do not contain null characters.
00085   int cmp(const GString *str) const { return strcmp(s, str->getCString()); }
00086   int cmpN(const GString *str, int n) const { return strncmp(s, str->getCString(), n); }
00087   int cmp(const char *sA) const { return strcmp(s, sA); }
00088   int cmpN(const char *sA, int n) const { return strncmp(s, sA, n); }
00089 
00090 private:
00091 
00092   int length;
00093   char *s;
00094 
00095   void resize(int length1);
00096 };
00097 
00098 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys