3 FILE : string.hh -- implement String inline helper classes,
4 and declare stringclass.
7 Rehacked by HWN 3/nov/95
9 introduced Class String_handle
20 #include "stringutil.hh"
24 Intuitive string class. provides
27 ref counting through #String_handle#
30 conversion from bool, int, double, char *, char.
33 conversion to int, upcase, downcase
40 indexing (pos, posAny, lastPos)
43 cutting (left, right, mid)
49 signed comparison (<, >, ==, etc)
52 No operator[] is provided, since this would be enormously slow. If needed,
53 convert to const char *.
59 String_handle strh_; // should derive String from String_handle?
63 /** init to "". needed because other constructors are provided.*/
67 String( const char* source );
69 String( Byte const* l_by_c, int length_i );
72 String( char c, int n = 1 );
80 /// String s( 3.14, 6, '#' );
81 String ( double f , const char *fmt =0);
82 String( int i, int n, char c = ' ' );
84 /// return a "new"-ed copy of contents
85 Byte* copy_by_p() const; // return a "new"-ed copy of contents
87 char const* ch_c_l() const;
88 Byte const* by_c_l() const;
92 /// deprecated; use ch_c_l()
93 operator const char *() const { return ch_c_l(); }
95 String operator =( const String & source ) { strh_ = source.strh_; return *this; }
98 void operator += (char const* s) { strh_ += s; }
99 void operator += (String s);
101 char operator []( int n ) const { return strh_[n]; }
103 /// return n leftmost chars
104 String left( int n ) const;
106 /// return n rightmost chars
107 String right( int n ) const;
109 /// convert this to upcase
112 /// convert this to downcase
113 String lower(); // & ??
115 /// return the "esrever" of *this
116 String reversed() const;
119 /// return a piece starting at pos (first char = pos 1), ength n
120 String mid(int pos, int n ) const;
122 /// cut out a middle piece, return remainder
123 String nomid(int pos, int n ) const;
125 /// signed comparison, analogous to memcmp;
126 static int compare(const String& s1,const String& s2);
128 /// index of rightmost c
129 int lastPos( char c) const;
131 /// index of rightmost element of string
132 int lastPos( const char* string ) const;
138 0 if not found, else index + 1
140 int pos(char c ) const;
141 int pos(const char* string ) const;
142 int posAny(const char* string ) const;
145 /// provide Stream output
146 void printOn(ostream& os) const;
148 /// convert to an integer
151 /// convert to a double
152 double fvalue() const;
154 /// the length of the string
155 int length_i() const;
164 #include "compare.hh"
166 instantiate_compare(const String &, String::compare);
168 // because const char* also has an operator ==, this is for safety:
169 inline bool operator==(String s1, const char *s2){
170 return s1 == String(s2);
172 inline bool operator==(const char *s1, String s2)
174 return String(s1)==s2;
176 inline bool operator!=(String s1, const char *s2 ) {
177 return s1!=String(s2);
179 inline bool operator!=(const char *s1,String s2) {
180 return String(s2) !=s1;
185 operator + (String s1, String s2)
192 operator << ( ostream& os, String d )
199 String quoteString(String message, String quote);
201 #include "stringconversion.hh"