1 //========================================================================
5 // Simple variable-length string type.
7 // Copyright 1996-2003 Glyph & Cog, LLC
9 //========================================================================
16 #ifdef USE_GCC_PRAGMAS
25 // Create an empty string.
28 // Create a string from a C string.
29 GString(const char *sA
);
31 // Create a string from <lengthA> chars at <sA>. This string
32 // can contain null characters.
33 GString(const char *sA
, int lengthA
);
35 // Create a string from <lengthA> chars at <idx> in <str>.
36 GString(GString
*str
, int idx
, int lengthA
);
39 GString(GString
*str
);
40 GString
*copy() { return new GString(this); }
42 // Concatenate two strings.
43 GString(GString
*str1
, GString
*str2
);
45 // Convert an integer to a string.
46 static GString
*fromInt(int x
);
52 int getLength() { return length
; }
55 char *getCString() { return s
; }
57 // Get <i>th character.
58 char getChar(int i
) { return s
[i
]; }
60 // Change <i>th character.
61 void setChar(int i
, char c
) { s
[i
] = c
; }
63 // Clear string to zero length.
66 // Append a character or string.
67 GString
*append(char c
);
68 GString
*append(GString
*str
);
69 GString
*append(const char *str
);
70 GString
*append(const char *str
, int lengthA
);
72 // Insert a character or string.
73 GString
*insert(int i
, char c
);
74 GString
*insert(int i
, GString
*str
);
75 GString
*insert(int i
, const char *str
);
76 GString
*insert(int i
, const char *str
, int lengthA
);
78 // Delete a character or range of characters.
79 GString
*del(int i
, int n
= 1);
81 // Convert string to all-upper/all-lower case.
85 // Compare two strings: -1:< 0:= +1:>
86 // These functions assume the strings do not contain null characters.
87 int cmp(GString
*str
) { return strcmp(s
, str
->getCString()); }
88 int cmpN(GString
*str
, int n
) { return strncmp(s
, str
->getCString(), n
); }
89 int cmp(const char *sA
) { return strcmp(s
, sA
); }
90 int cmpN(const char *sA
, int n
) { return strncmp(s
, sA
, n
); }
97 void resize(int length1
);