]> www.fi.muni.cz Git - evince.git/blob - pdf/goo/GString.h
Break everything except bonobo-image-x-pdf :-)
[evince.git] / pdf / goo / GString.h
1 //========================================================================
2 //
3 // GString.h
4 //
5 // Simple variable-length string type.
6 //
7 // Copyright 1996 Derek B. Noonburg
8 //
9 //========================================================================
10
11 #ifndef GSTRING_H
12 #define GSTRING_H
13
14 #ifdef __GNUC__
15 #pragma interface
16 #endif
17
18 #include <string.h>
19
20 class GString {
21 public:
22
23   // Create an empty string.
24   GString();
25
26   // Create a string from a C string.
27   GString(char *s1);
28
29   // Create a string from <length1> chars at <s1>.  This string
30   // can contain null characters.
31   GString (char *s1, int length1);
32
33   // Copy a string.
34   GString(GString *str);
35   GString *copy() { return new GString(this); }
36
37   // Concatenate two strings.
38   GString(GString *str1, GString *str2);
39
40   // Destructor.
41   ~GString();
42
43   // Get length.
44   int getLength() { return length; }
45
46   // Get C string.
47   char *getCString() { return s; }
48
49   // Get <i>th character.
50   char getChar(int i) { return s[i]; }
51
52   // Change <i>th character.
53   void setChar(int i, char c) { s[i] = c; }
54
55   // Clear string to zero length.
56   GString *clear();
57
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);
63
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);
69
70   // Delete a character or range of characters.
71   GString *del(int i, int n = 1);
72
73   // Convert string to all-upper/all-lower case.
74   GString *upperCase();
75   GString *lowerCase();
76
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); }
83
84 private:
85
86   int length;
87   char *s;
88
89   void resize(int length1);
90 };
91
92 #endif