3 FILE : string.hh -- declare String
5 Rehacked by HWN 3/nov/95
7 introduced Class String_handle
16 #include "arithmetic-operator.hh"
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.*/
81 String (char const* source);
82 String (Byte const* byte_C, int length_i);
85 String (char c, int n = 1);
87 String (int i , char const *fmt=0);
88 String (double f , char const* fmt =0);
92 /// return a "new"-ed copy of contents
93 Byte* copy_byte_p () const; // return a "new"-ed copy of contents
95 char const* ch_C () const;
96 Byte const* byte_C () const;
100 String &operator =(String const & source);
103 void operator += (char const* s) { strh_ += s; }
104 void operator += (String s);
106 bool empty_b () const;
108 /** is the string empty?
110 Ugh-ugh-thank-you-cygnus. W32 barfs on this
112 operator bool () const;
117 void append (String);
118 void prepend (String);
121 Return a char. UNSAFE because it may change strlen () result
123 char &operator [](int n);
124 char operator [](int n) const;
126 /// return n leftmost chars
127 String left_str (int n) const;
129 /// return n rightmost chars
130 String right_str (int n) const;
132 /// return uppercase of *this
133 String upper_str () const;
135 /// return lowercase of *this
136 String lower_str () const;
138 /// return the "esrever" of *this
139 String reversed_str () const;
142 /// return a piece starting at index_i (first char = index_i 0), length n
143 String cut (int index_i, int n) const;
145 /// cut out a middle piece, return remainder
146 String nomid_str (int index_i, int n) const;
148 /// signed comparison, analogous to memcmp;
149 static int compare_i (String const & s1,const String& s2);
151 /// index of rightmost c
152 int index_last_i (char c) const;
154 /// index of rightmost element of string (???)
155 int index_last_i (char const* string) const;
157 /// index of leftmost #c#
158 int index_i (char c) const;
161 /// index of leftmost occurance of STRING
162 int index_i (String) const;
163 int index_any_i (String) const;
167 /// provide Stream output
168 void print_on (ostream& os) const;
170 /// the length of the string
171 int length_i () const;
173 /// convert to an integer
174 int value_i () const;
176 /// convert to a double
177 double value_f () const;
180 #include "compare.hh"
181 INSTANTIATE_COMPARE(String const &, String::compare_i);
183 #ifdef STRING_UTILS_INLINED
185 #define INLINE inline
187 #include "string.icc"
188 /* we should be resetting INLINE. oh well. */
192 // because char const* also has an operator ==, this is for safety:
193 inline bool operator==(String s1, char const* s2)
195 return s1 == String (s2);
197 inline bool operator==(char const* s1, String s2)
199 return String (s1)==s2;
201 inline bool operator!=(String s1, char const* s2 ) {
202 return s1!=String (s2);
204 inline bool operator!=(char const* s1,String s2) {
205 return String (s2) !=s1;
208 IMPLEMENT_ARITHMETIC_OPERATOR (String, +);
211 operator << (ostream& os, String d)