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"
29 Intuitive string class. provides
32 ref counting through #String_handle#
34 conversion from bool, int, double, char* , char.
36 to be moved to String_convert:
37 conversion to int, upcase, downcase
43 indexing (index_i, index_any_i, last_index_i)
46 cutting (left_str, right_str, mid_str)
52 signed comparison (<, >, ==, etc)
55 No operator[] is provided, since this would be enormously slow. If needed,
56 convert to char const* .
65 bool null_terminated();
69 /** init to empty string. This is needed because other
70 constructors are provided.*/
75 String (char const* source);
76 String (Byte const* byte_C, int length_i);
79 String (char c, int n = 1);
81 String (int i , char const *fmt=0);
82 String (double f , char const* fmt =0);
86 /// return a "new"-ed copy of contents
87 Byte* copy_byte_p() const; // return a "new"-ed copy of contents
89 char const* ch_C() const;
90 Byte const* byte_C() const;
94 String &operator =(String const & source);
97 void operator += (char const* s) { strh_ += s; }
98 void operator += (String s);
100 bool empty_b () const;
102 /** is the string empty?
104 Ugh-ugh-thank-you-cygnus. W32 barfs on this
106 operator bool () const;
111 void append (String);
112 void prepend (String);
114 char operator [](int n) const { return strh_[n]; }
116 /// return n leftmost chars
117 String left_str (int n) const;
119 /// return n rightmost chars
120 String right_str (int n) const;
122 /// return uppercase of *this
123 String upper_str() const;
125 /// return lowercase of *this
126 String lower_str() const;
128 /// return the "esrever" of *this
129 String reversed_str() const;
132 /// return a piece starting at index_i (first char = index_i 0), length n
133 String mid_str (int index_i, int n) const;
135 /// cut out a middle piece, return remainder
136 String nomid_str (int index_i, int n) const;
138 /// signed comparison, analogous to memcmp;
139 static int compare_i (String const & s1,const String& s2);
141 /// index of rightmost c
142 int index_last_i (char c) const;
144 /// index of rightmost element of string
145 int index_last_i (char const* string) const;
147 int index_i (char c) const;
148 int index_i (String) const;
149 int index_any_i (String) const;
153 /// provide Stream output
154 void print_on (ostream& os) const;
156 /// the length of the string
157 int length_i() const;
164 /// convert to an integer
167 /// convert to a double
168 double value_f() const;
171 #include "compare.hh"
173 INSTANTIATE_COMPARE(String const &, String::compare_i);
175 // because char const* also has an operator ==, this is for safety:
176 inline bool operator==(String s1, char const* s2){
177 return s1 == String (s2);
179 inline bool operator==(char const* s1, String s2)
181 return String (s1)==s2;
183 inline bool operator!=(String s1, char const* s2 ) {
184 return s1!=String (s2);
186 inline bool operator!=(char const* s1,String s2) {
187 return String (s2) !=s1;
192 operator + (String s1, String s2)
199 operator << (ostream& os, String d)