3 FILE : string.hh -- declare String
5 Rehacked by HWN 3/nov/95
7 introduced Class String_handle
18 #include "string-handle.hh"
21 technically incorrect, but lets keep it here: this is a
22 catch all place for this stuff.
25 #include "international.hh"
27 /* Libg++ also has a String class. Programming errors can lead to
28 confusion about which String is in use. Uncomment the following if you have
29 unexplained crashes after mucking with String
32 // #define String FlowerString
36 Intuitive string class. provides
39 ref counting through #String_handle#
41 conversion from bool, int, double, char* , char.
43 to be moved to String_convert:
44 conversion to int, upcase, downcase
50 indexing (index_i, index_any_i, last_index_i)
53 cutting (left_str, right_str, mid_str)
59 signed comparison (<, >, ==, etc)
62 No operator[] is provided, since this would be enormously slow. If needed,
63 convert to char const* .
72 bool null_terminated ();
76 /** init to empty string. This is needed because other
77 constructors are provided.*/
82 String (char const* source);
83 String (Byte const* byte_C, int length_i);
86 String (char c, int n = 1);
88 String (int i , char const *fmt=0);
89 String (double f , char const* fmt =0);
93 /// return a "new"-ed copy of contents
94 Byte* copy_byte_p () const; // return a "new"-ed copy of contents
96 char const* ch_C () const;
97 Byte const* byte_C () const;
101 String &operator =(String const & source);
104 void operator += (char const* s) { strh_ += s; }
105 void operator += (String s);
107 bool empty_b () const;
109 /** is the string empty?
111 Ugh-ugh-thank-you-cygnus. W32 barfs on this
113 operator bool () const;
118 void append (String);
119 void prepend (String);
122 Return a char. UNSAFE because it may change strlen () result
124 char &operator [](int n);
125 char operator [](int n) const;
127 /// return n leftmost chars
128 String left_str (int n) const;
130 /// return n rightmost chars
131 String right_str (int n) const;
133 /// return uppercase of *this
134 String upper_str () const;
136 /// return lowercase of *this
137 String lower_str () const;
139 /// return the "esrever" of *this
140 String reversed_str () const;
143 /// return a piece starting at index_i (first char = index_i 0), length n
144 String cut (int index_i, int n) const;
146 /// cut out a middle piece, return remainder
147 String nomid_str (int index_i, int n) const;
149 /// signed comparison, analogous to memcmp;
150 static int compare_i (String const & s1,const String& s2);
152 /// index of rightmost c
153 int index_last_i (char c) const;
155 /// index of rightmost element of string (???)
156 int index_last_i (char const* string) const;
158 /// index of leftmost #c#
159 int index_i (char c) const;
162 /// index of leftmost occurance of STRING
163 int index_i (String) const;
164 int index_any_i (String) const;
168 /// provide Stream output
169 void print_on (ostream& os) const;
171 /// the length of the string
172 int length_i () const;
174 /// convert to an integer
175 int value_i () const;
177 /// convert to a double
178 double value_f () const;
181 #include "compare.hh"
182 INSTANTIATE_COMPARE(String const &, String::compare_i);
184 #ifdef STRING_UTILS_INLINED
186 #define INLINE inline
188 #include "string.icc"
189 /* we should be resetting INLINE. oh well. */
193 // because char const* also has an operator ==, this is for safety:
194 inline bool operator==(String s1, char const* s2)
196 return s1 == String (s2);
198 inline bool operator==(char const* s1, String s2)
200 return String (s1)==s2;
202 inline bool operator!=(String s1, char const* s2 ) {
203 return s1!=String (s2);
205 inline bool operator!=(char const* s1,String s2) {
206 return String (s2) !=s1;
211 operator + (String s1, String s2)
218 operator << (ostream& os, String d)