3 FILE : string.hh -- declare String
5 Rehacked by HWN 3/nov/95
7 introduced Class String_handle
14 #include "arithmetic-operator.hh"
15 #include "flower-proto.hh"
16 #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.*/
67 String (char const* source);
68 String (Byte const* byte_C, int length_i);
70 /// return "new"-ed copy of contents
71 Byte* copy_byte_p () const;
72 char* copy_ch_p() const;
74 char const* ch_C () const;
75 Byte const* byte_C () const;
79 String &operator =(String const & source);
82 void operator += (char const* s) { strh_ += s; }
83 void operator += (String s);
85 bool empty_b () const;
88 void prepend (String);
91 Return a char. UNSAFE because it may change strlen () result
93 char &operator [](int n);
94 char operator [](int n) const;
96 /// return n leftmost chars
97 String left_str (int n) const;
99 /// return n rightmost chars
100 String right_str (int n) const;
102 /// return uppercase of *this
103 String upper_str () const;
105 /// return lowercase of *this
106 String lower_str () const;
108 /// return the "esrever" of *this
109 String reversed_str () const;
111 /// return a piece starting at index_i (first char = index_i 0), length n
112 String cut_str (int index_i, int n) const;
114 /// cut out a middle piece, return remainder
115 String nomid_str (int index_i, int n) const;
117 /// signed comparison, analogous to memcmp;
118 static int compare_i (String const & s1,const String& s2);
120 /// index of rightmost c
121 int index_last_i (char c) const;
123 /// index of rightmost element of string (???)
124 int index_last_i (char const* string) const;
126 int index_i (char c) const;
128 /// index of leftmost occurance of STRING
129 int index_i (String) const;
132 int index_any_i (String) const;
137 /// provide Stream output
138 void print_on (ostream& os) const;
140 /// the length of the string
141 int length_i () const;
143 /// convert to an integer
144 int value_i () const;
146 /// convert to a double
147 double value_f () const;
151 better to clutter global namespace, than suffer *ugh, ugh, ugh*
152 implicit conversions.
154 it might be cool to have no type-checking at all in a language,
155 but once there is, having this silently circumvented is a nightmare.
157 whenever implicit conversions seem necessary (e.g. operator << ()),
158 use Scalar as the generic type iso String.
161 /// for completeness (=handy)
162 inline String to_str (String s) { return s; }
164 String to_str (char c, int n = 1);
165 String to_str (int i, char const* format = 0);
166 String to_str (double f , char const* format = 0);
167 String to_str (long b);
168 String to_str (bool b);
169 String to_str (char const* format, ... );
172 technically incorrect, but lets keep it here: this is a
173 catch all place for this stuff.
176 #include "international.hh"
179 #include "compare.hh"
180 INSTANTIATE_COMPARE(String const &, String::compare_i);
182 #ifdef STRING_UTILS_INLINED
184 #define INLINE inline
186 #include "string.icc"
187 /* we should be resetting INLINE. oh well. */
191 // because char const* also has an operator ==, this is for safety:
192 inline bool operator==(String s1, char const* s2)
194 return s1 == String (s2);
196 inline bool operator==(char const* s1, String s2)
198 return String (s1)==s2;
200 inline bool operator!=(String s1, char const* s2 ) {
201 return s1!=String (s2);
203 inline bool operator!=(char const* s1,String s2) {
204 return String (s2) !=s1;
207 IMPLEMENT_ARITHMETIC_OPERATOR (String, +);
209 ostream &operator << (ostream& os, String d);