1 //========================================================================
5 // Simple variable-length string type.
7 // Copyright 1996 Derek B. Noonburg
9 //========================================================================
23 // Create an empty string.
26 // Create a string from a C string.
29 // Create a string from <length1> chars at <s1>. This string
30 // can contain null characters.
31 GString (char *s1, int length1);
34 GString(GString *str);
35 GString *copy() { return new GString(this); }
37 // Concatenate two strings.
38 GString(GString *str1, GString *str2);
44 int getLength() { return length; }
47 char *getCString() { return s; }
49 // Get <i>th character.
50 char getChar(int i) { return s[i]; }
52 // Change <i>th character.
53 void setChar(int i, char c) { s[i] = c; }
55 // Clear string to zero length.
58 // Append a character or string.
59 GString *append(char c);
60 GString *append(GString *str);
61 GString *append(char *str);
62 GString *append(char *str, int length1);
64 // Insert a character or string.
65 GString *insert(int i, char c);
66 GString *insert(int i, GString *str);
67 GString *insert(int i, char *str);
68 GString *insert(int i, char *str, int length1);
70 // Delete a character or range of characters.
71 GString *del(int i, int n = 1);
73 // Convert string to all-upper/all-lower case.
77 // Compare two strings: -1:< 0:= +1:>
78 // These functions assume the strings do not contain null characters.
79 int cmp(GString *str) { return strcmp(s, str->getCString()); }
80 int cmpN(GString *str, int n) { return strncmp(s, str->getCString(), n); }
81 int cmp(char *s1) { return strcmp(s, s1); }
82 int cmpN(char *s1, int n) { return strncmp(s, s1, n); }
89 void resize(int length1);