1 //========================================================================
5 // Simple variable-length string type.
7 // Copyright 1996-2002 Glyph & Cog, LLC
9 //========================================================================
23 // Create an empty string.
26 // Create a string from a C string.
27 GString(const char *sA);
29 // Create a string from <lengthA> chars at <sA>. This string
30 // can contain null characters.
31 GString(const char *sA, int lengthA);
33 // Create a string from <lengthA> chars at <idx> in <str>.
34 GString(GString *str, int idx, int lengthA);
37 GString(GString *str);
38 GString *copy() { return new GString(this); }
40 // Concatenate two strings.
41 GString(GString *str1, GString *str2);
43 // Convert an integer to a string.
44 static GString *fromInt(int x);
50 int getLength() { return length; }
53 char *getCString() { return s; }
55 // Get <i>th character.
56 char getChar(int i) { return s[i]; }
58 // Change <i>th character.
59 void setChar(int i, char c) { s[i] = c; }
61 // Clear string to zero length.
64 // Append a character or string.
65 GString *append(char c);
66 GString *append(GString *str);
67 GString *append(const char *str);
68 GString *append(const char *str, int lengthA);
70 // Insert a character or string.
71 GString *insert(int i, char c);
72 GString *insert(int i, GString *str);
73 GString *insert(int i, const char *str);
74 GString *insert(int i, const char *str, int lengthA);
76 // Delete a character or range of characters.
77 GString *del(int i, int n = 1);
79 // Convert string to all-upper/all-lower case.
83 // Compare two strings: -1:< 0:= +1:>
84 // These functions assume the strings do not contain null characters.
85 int cmp(GString *str) { return strcmp(s, str->getCString()); }
86 int cmpN(GString *str, int n) { return strncmp(s, str->getCString(), n); }
87 int cmp(const char *sA) { return strcmp(s, sA); }
88 int cmpN(const char *sA, int n) { return strncmp(s, sA, n); }
95 void resize(int length1);