faithtools/faith/string.h

Go to the documentation of this file.
00001 #ifndef KDE__STRING_H
00002 #define KDE__STRING_H
00003 
00004 #include <faith/cstring.h>
00005 #include <faith/char.h>
00006 #include <faith/tools.h>
00007 
00008 #include <string>
00009 
00015 #ifndef U_ICU_NAMESPACE
00016 #define U_ICU_NAMESPACE KDEInternalAwfulHack
00017 #endif
00018 
00019 namespace U_ICU_NAMESPACE
00020 {
00021 class UnicodeString; // icu
00022 }
00023 
00024 
00025 namespace Faith
00026 {
00027 
00028 class Char;
00029 class CharRef;
00030 
00043 class FAITH_TOOLS_EXPORT String
00044 {
00045         U_ICU_NAMESPACE::UnicodeString *mUnicode;
00046         friend class ::Faith::CharRef;
00047 public:
00051         String();
00052         
00056         String(const String &s);
00057         
00061         String(const std::string &s);
00062         
00067         String(const char *s);
00068 
00069         ~String();
00070 
00077         bool isNull() const;
00078 
00084         bool isEmpty() const { return length() ? false : true; }
00085 
00093         bool operator ==(const String &other) const;
00094 
00100         int compare(const String &text) const;
00101 
00102 
00103         bool operator <(const ::Faith::String &b) const
00104         {
00105                 return compare(b) > 0;
00106         }
00107 
00108         bool operator >(const ::Faith::String &b) const
00109         {
00110                 return compare(b) < 0;
00111         }
00112 
00113         String &operator =(const String &set);
00114         String &operator =(const Char &set);
00115 
00121         String &operator +=(const String &append);
00122 
00128         String &operator +=(char c);
00129         
00135         String &operator +=(const Char &c);
00136 
00137         inline Faith::String operator + (const char *b)
00138         {
00139                 Faith::String s(*this);
00140                 s += b;
00141                 return s;
00142         }
00143 
00149         Char operator[] (int at) const;
00150 
00160         CharRef operator[] (int at);
00161 
00168         int find(const String &other, int start=0) const;
00169 
00176         int find(const Char &other, int start=0) const;
00177 
00184         int find(char other, int start=0) const;
00185 
00202         int find(bool (Char::*test)() const, int start=0) const
00203         {
00204                 return find(true, test, start);
00205         }
00206 
00212         int find(bool uninverted, bool (Char::*test)() const, int start=0) const;
00213 
00219         String mid(int start, int length=-1) const;
00220 
00225         void insert(int offset, const String &str);
00226 
00231         void replace(int start, int len, const String &str);
00232 
00233 
00240         void replace(const String &other, const String &replace, int start=0);
00241 
00248         void replace(const Char &other, const String &replace, int start=0);
00249 
00256         void replace(char other, const String &replace, int start=0);
00257         
00258         
00262         int length() const;
00263 
00270         static String fromLocal8Bit(const char *str)
00271         {
00272                 return fromLocal8Bit(CString(str));
00273         }
00277         static String fromLocal8Bit(const CString &);
00278 
00284         static String fromLatin1(const char *);
00285         static String fromLatin1(const CString &);
00286 
00287         void setLocal8Bit(const CString &str);
00288         void setLocal8Bit(const char *str);
00289 
00290         void setUtf8(const CString &str);
00291         void setUtf8(const char *str);
00292 
00293         static String fromUtf8(const char *str) { String s; s.setUtf8(str); return s; }
00294 
00295         void setLatin1(const CString &str);
00296         void setLatin1(const char *str);
00297 
00303         CString exportTo(const CString &codepage) const;
00304 
00308         CString local8Bit() const;
00309 
00313         CString latin1() const;
00314 
00315         static String number(int n, int base=10);
00316         static String number(long n, int base=10) { return number(int(n), base); }
00321         static String number(double n, char format='g', int precision=6);
00322 
00326         Faith::String left(int n) const;
00327         
00328         void setCharAt(int offset, const Char &ch);
00329         
00330         int toInt(int base=10) const;
00331         
00337         bool beginsWith(const String &str) const;
00338         
00343         String simplifiedWhiteSpace() const;
00344         
00348         String removedWhiteSpace() const;
00349 };
00350 
00351 }
00352 
00353 inline std::ostream &operator << (std::ostream &out, const Faith::String &str)
00354 {
00355         out << str.latin1();
00356         return out;
00357 }
00358 
00359 inline std::istream &operator >> (std::istream &in, Faith::String &str)
00360 {
00361         std::string s;
00362         in >> s;
00363         str = s.c_str();
00364         return in;
00365 }
00366 
00367 inline Faith::String operator + (const Faith::String &a, const Faith::String &b)
00368 {
00369         Faith::String s(a);
00370         s += b;
00371         return s;
00372 }
00373 
00374 inline bool operator ==(const char *a, const Faith::String &b)
00375 {
00376         return b == a;
00377 }
00378 
00379 
00380 #endif

Generated on Fri Sep 1 00:23:07 2006 for Faith by  doxygen 1.4.7