3 FILE : string.hh -- declare String
5 Rehacked by HWN 3/nov/95
7 introduced Class String_handle
18 #include "stringhandle.hh"
22 Intuitive string class. provides
25 ref counting through #String_handle#
28 conversion from bool, int, double, char *, char.
31 conversion to int, upcase, downcase
38 indexing (pos, posAny, lastPos)
41 cutting (left, right, mid)
47 signed comparison (<, >, ==, etc)
50 No operator[] is provided, since this would be enormously slow. If needed,
51 convert to const char *.
57 String_handle strh_
; // should derive String from String_handle?
61 /** init to "". needed because other constructors are provided.*/
65 String( const char* source
);
67 String( Byte
const* l_byte_c
, int length_i
);
70 String( char c
, int n
= 1 );
78 /// String s( 3.14, 6, '#' );
79 String ( double f
, const char *fmt
=0);
80 String( int i
, int n
, char c
= ' ' );
82 /// return a "new"-ed copy of contents
83 Byte
* copy_byte_p() const; // return a "new"-ed copy of contents
85 char const* ch_c_l() const;
86 Byte
const* byte_c_l() const;
90 /// deprecated; use ch_c_l()
91 operator const char *() const { return ch_c_l(); }
93 String
operator =( const String
& source
) { strh_
= source
.strh_
; return *this; }
96 void operator += (char const* s
) { strh_
+= s
; }
97 void operator += (String s
);
99 char operator []( int n
) const { return strh_
[n
]; }
101 /// return n leftmost chars
102 String
left( int n
) const;
104 /// return n rightmost chars
105 String
right( int n
) const;
107 /// convert this to upcase
110 /// convert this to downcase
111 String
lower(); // & ??
113 /// return the "esrever" of *this
114 String
reversed() const;
117 /// return a piece starting at pos (first char = pos 1), ength n
118 String
mid(int pos
, int n
) const;
120 /// cut out a middle piece, return remainder
121 String
nomid(int pos
, int n
) const;
123 /// signed comparison, analogous to memcmp;
124 static int compare(const String
& s1
,const String
& s2
);
126 /// index of rightmost c
127 int lastPos( char c
) const;
129 /// index of rightmost element of string
130 int lastPos( const char* string
) const;
136 0 if not found, else index + 1
138 int pos(char c
) const;
139 int pos(const char* string
) const;
140 int posAny(const char* string
) const;
143 /// provide Stream output
144 void printOn(ostream
& os
) const;
146 /// convert to an integer
149 /// convert to a double
150 double fvalue() const;
152 /// the length of the string
153 int length_i() const;
162 #include "compare.hh"
164 instantiate_compare(const String
&, String::compare
);
166 // because const char* also has an operator ==, this is for safety:
167 inline bool operator==(String s1
, const char *s2
){
168 return s1
== String(s2
);
170 inline bool operator==(const char *s1
, String s2
)
172 return String(s1
)==s2
;
174 inline bool operator!=(String s1
, const char *s2
) {
175 return s1
!=String(s2
);
177 inline bool operator!=(const char *s1
,String s2
) {
178 return String(s2
) !=s1
;
183 operator + (String s1
, String s2
)
190 operator << ( ostream
& os
, String d
)
197 String
quoteString(String message
, String quote
);
199 #include "stringconversion.hh"