Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

GString.h

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

Generated on Wed Nov 3 12:58:57 2004 for Lemur Toolkit by doxygen1.2.18