Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_String.h

00001 /*
00002  * $Id: Fl_String.h,v 1.11 2003/03/15 16:09:55 laza2000 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Alexey Parshin
00016  * Email  : alexey@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
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     // constructors & destructors
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     // assignments
00045     Fl_String& operator = (const char *s);
00046     Fl_String& operator = (const Fl_String& s);
00047 
00048     // operations
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     // usefull methods
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     // Returns reference to this
00095     Fl_String &printf(const char *str, ...);
00096 
00097     // auto conversion to char* and uchar* when needed
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     // element access
00104     char& operator [] (const int i) { return str_[i]; }
00105     char operator [] (const int i) const { return str_[i]; }
00106 
00107     // Convert string to latin1. 'str' is allocated by Fl_String, caller must call free() for it. 
00108     int to_latin1(char *&str);
00109     // Convert string to unicode. 'str' is allocated by Fl_String, caller must call free() for it. 
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

Generated on Thu Jul 31 15:33:45 2003 for eFLTK by doxygen1.2.15