00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _Fl_STRING_H_
00023 #define _Fl_STRING_H_
00024
00025 #include "Enumerations.h"
00026 #include <string.h>
00027
00029 class FL_API Fl_String {
00030 friend FL_API Fl_String operator +(const char*, const Fl_String& rhs);
00031 public:
00032 static Fl_String null_object;
00033
00034
00035 Fl_String(char c,int repeater = 1);
00036 Fl_String(int number);
00037 Fl_String(unsigned number);
00038 Fl_String(const char *s="", int maxlen=0, bool pre_allocated=false);
00039 Fl_String(const Fl_String &s);
00040 ~Fl_String();
00041
00042 void clear();
00043
00044
00045 Fl_String& operator = (const char *s);
00046 Fl_String& operator = (const Fl_String& s);
00047
00048
00049 Fl_String operator + (const char * s) const;
00050 Fl_String operator + (const Fl_String& s) const;
00051 Fl_String operator + (const char s) const;
00052 Fl_String& operator += (const char * s);
00053 Fl_String& operator += (const Fl_String& s);
00054 Fl_String& operator += (const char s);
00055
00056 bool operator ! () const { return empty(); }
00057
00058
00059 Fl_String &append(const char *str, int len);
00060 Fl_String &prepend(const char *str, int len);
00061
00062 bool cmp(Fl_String &s) const;
00063 bool casecmp(Fl_String &s) const;
00064
00065 Fl_String trim_right() const;
00066 Fl_String trim_left() const;
00067 Fl_String trim() const;
00068 Fl_String remove(const char *pattern) const;
00069 Fl_String replace(const char *pattern,const char *replacement) const;
00070 Fl_String lower_case() const;
00071 Fl_String upper_case() const;
00072
00073 Fl_String sub_str(int start, int count) const;
00074 void sub_delete(int start, int count=1);
00075 void sub_delete(const char *s) { sub_replace(s, 0); }
00076 void sub_insert(int start, const char *str);
00077 void sub_insert(int start, char ch);
00078 void sub_replace(const char *s_str, const char *r_str);
00079
00080 int length() const;
00081 int pos(const char *substr, int index=0) const;
00082 int pos(int c, int index=0) const;
00083 int rpos(int c, int index=0) const;
00084
00085 int to_int(int defvalue=0) const;
00086 float to_float(float defvalue=0) const;
00087 double to_double(double defvalue=0) const;
00088
00089 bool empty() const;
00090 void set_length(int new_len);
00091
00092 const char *c_str() const { return str_; }
00093
00094
00095 Fl_String &printf(const char *str, ...);
00096
00097
00098 operator const char *() const { return str_; }
00099 operator char *() const { return str_; }
00100 operator const uchar *() const { return (const uchar*)str_; }
00101 operator uchar *() const { return (uchar*)str_; }
00102
00103
00104 char& operator [] (const int i) { return str_[i]; }
00105 char operator [] (const int i) const { return str_[i]; }
00106
00107
00108 int to_latin1(char *&str);
00109
00110 int to_unicode(unsigned short *&str);
00111
00112 static Fl_String from_latin1(const char *str, int str_len);
00113 static Fl_String from_unicode(const unsigned short *str, int str_len);
00114
00115 static Fl_String from_codeset(int conv_index, const char *str, int str_len);
00116 static Fl_String from_codeset(Fl_String codeset, const char *str, int str_len);
00117
00118 protected:
00119 void assign(const char *str, int len);
00120
00121 char *str_;
00122 unsigned len_;
00123 };
00124
00125 static inline bool operator < (const Fl_String &s1, const Fl_String &s2) { return (strcmp(s1.c_str(),s2.c_str())<0); }
00126 static inline bool operator <= (const Fl_String &s1, const Fl_String &s2) { return (strcmp(s1.c_str(),s2.c_str())<=0); }
00127 static inline bool operator > (const Fl_String &s1, const Fl_String &s2) { return (strcmp(s1.c_str(),s2.c_str())>0); }
00128 static inline bool operator >= (const Fl_String &s1, const Fl_String &s2) { return (strcmp(s1.c_str(),s2.c_str())>=0); }
00129 static inline bool operator == (const Fl_String &s1, const Fl_String &s2) { if(&s1==&s2) return true; return (strcmp(s1.c_str(),s2.c_str())==0); }
00130 static inline bool operator != (const Fl_String &s1, const Fl_String &s2) { return (strcmp(s1.c_str(),s2.c_str())!=0); }
00131
00132 static inline bool operator < (const Fl_String &s1, const char *s2) { return (strcmp(s1.c_str(),s2)<0); }
00133 static inline bool operator <= (const Fl_String &s1, const char *s2) { return (strcmp(s1.c_str(),s2)<=0); }
00134 static inline bool operator > (const Fl_String &s1, const char *s2) { return (strcmp(s1.c_str(),s2)>0); }
00135 static inline bool operator >= (const Fl_String &s1, const char *s2) { return (strcmp(s1.c_str(),s2)>=0); }
00136 static inline bool operator == (const Fl_String &s1, const char *s2) { return (strcmp(s1.c_str(),s2)==0); }
00137 static inline bool operator != (const Fl_String &s1, const char *s2) { return (strcmp(s1.c_str(),s2)!=0); }
00138
00139 static inline bool operator < (const char *s1, const Fl_String &s2) { return (strcmp(s1,s2.c_str())<0); }
00140 static inline bool operator <= (const char *s1, const Fl_String &s2) { return (strcmp(s1,s2.c_str())<=0); }
00141 static inline bool operator > (const char *s1, const Fl_String &s2) { return (strcmp(s1,s2.c_str())>0); }
00142 static inline bool operator >= (const char *s1, const Fl_String &s2) { return (strcmp(s1,s2.c_str())>=0); }
00143 static inline bool operator == (const char *s1, const Fl_String &s2) { return (strcmp(s1,s2.c_str())==0); }
00144 static inline bool operator != (const char *s1, const Fl_String &s2) { return (strcmp(s1,s2.c_str())!=0); }
00145
00146 extern FL_API Fl_String operator +(const char*, const Fl_String& rhs);
00147
00148 #endif