3 FILE : string.hh -- declare String
5 Rehacked by HWN 3/nov/95
7 introduced Class String_handle
18 #include "string-handle.hh"
22 Intuitive string class. provides
25 ref counting through #String_handle#
27 conversion from bool, int, double, char* , char.
29 to be moved to String_convert:
30 conversion to int, upcase, downcase
36 indexing (index_i, index_any_i, last_index_i)
39 cutting (left_str, right_str, mid_str)
45 signed comparison (<, >, ==, etc)
48 No operator[] is provided, since this would be enormously slow. If needed,
49 convert to char const* .
58 bool null_terminated();
62 /** init to empty string. This is needed because other
63 constructors are provided.*/
68 String (char const* source);
69 String (Byte const* byte_C, int length_i);
72 String (char c, int n = 1);
74 String (int i , char const *fmt=0);
75 String (double f , char const* fmt =0);
79 /// return a "new"-ed copy of contents
80 Byte* copy_byte_p() const; // return a "new"-ed copy of contents
82 char const* ch_C() const;
83 Byte const* byte_C() const;
87 String &operator =(String const & source);
90 void operator += (char const* s) { strh_ += s; }
91 void operator += (String s);
93 bool empty_b () const;
95 /** is the string empty?
97 Ugh-ugh-thank-you-cygnus. W32 barfs on this
99 operator bool () const;
104 void append (String);
105 void prepend (String);
107 char operator [](int n) const { return strh_[n]; }
109 /// return n leftmost chars
110 String left_str (int n) const;
112 /// return n rightmost chars
113 String right_str (int n) const;
115 /// return uppercase of *this
116 String upper_str() const;
118 /// return lowercase of *this
119 String lower_str() const;
121 /// return the "esrever" of *this
122 String reversed_str() const;
125 /// return a piece starting at index_i (first char = index_i 0), length n
126 String mid_str (int index_i, int n) const;
128 /// cut out a middle piece, return remainder
129 String nomid_str (int index_i, int n) const;
131 /// signed comparison, analogous to memcmp;
132 static int compare_i (String const & s1,const String& s2);
134 /// index of rightmost c
135 int index_last_i (char c) const;
137 /// index of rightmost element of string
138 int index_last_i (char const* string) const;
140 int index_i (char c) const;
141 int index_i (String) const;
142 int index_any_i (String) const;
146 /// provide Stream output
147 void print_on (ostream& os) const;
149 /// the length of the string
150 int length_i() const;
157 /// convert to an integer
160 /// convert to a double
161 double value_f() const;
164 #include "compare.hh"
166 INSTANTIATE_COMPARE(String const &, String::compare_i);
168 // because char const* also has an operator ==, this is for safety:
169 inline bool operator==(String s1, char const* s2){
170 return s1 == String (s2);
172 inline bool operator==(char const* s1, String s2)
174 return String (s1)==s2;
176 inline bool operator!=(String s1, char const* s2 ) {
177 return s1!=String (s2);
179 inline bool operator!=(char const* s1,String s2) {
180 return String (s2) !=s1;
185 operator + (String s1, String s2)
192 operator << (ostream& os, String d)