tstring.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     copyright            : (C) 2002, 2003 by Scott Wheeler
00003     email                : wheeler@kde.org
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *   This library is free software; you can redistribute it and/or modify  *
00008  *   it  under the terms of the GNU Lesser General Public License version  *
00009  *   2.1 as published by the Free Software Foundation.                     *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful, but   *
00012  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the Free Software   *
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00019  *   USA                                                                   *
00020  ***************************************************************************/
00021 
00022 #ifndef TAGLIB_STRING_H
00023 #define TAGLIB_STRING_H
00024 
00025 #include "taglib.h"
00026 #include "tbytevector.h"
00027 
00028 #include <string>
00029 
00035 #define QStringToTString(s) TagLib::String(s.utf8().data(), TagLib::String::UTF8)
00036 
00042 #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
00043 
00044 namespace TagLib {
00045 
00047 
00063   class String
00064   {
00065   public:
00066 
00067 #ifndef DO_NOT_DOCUMENT
00068     typedef std::basic_string<wchar>::iterator Iterator;
00069     typedef std::basic_string<wchar>::const_iterator ConstIterator;
00070 #endif
00071 
00076     enum Type {
00080       Locale = -1,
00084       Latin1ID3 = 5,
00088       Latin1 = 0,
00092       UTF16 = 1,
00097       UTF16BE = 2,
00101       UTF8 = 3,
00105       UTF16LE = 4
00106     };
00107 
00108     static Type ID3Type(int i);
00109     static Type ID3WType(Type type);
00110 
00114     String();
00115 
00121     String(const String &s);
00122 
00129     String(const std::string &s, Type t = Latin1);
00130 
00134     String(const wstring &s, Type t = UTF16BE);
00135 
00139     String(const wchar_t *s, Type t = UTF16BE);
00140 
00147     String(char c, Type t = Latin1);
00148 
00152     String(wchar_t c, Type t = Latin1);
00153 
00154 
00161     String(const char *s, Type t = Latin1);
00162 
00169     String(const ByteVector &v, Type t = Latin1);
00170 
00174     virtual ~String();
00175 
00181     std::string to8Bit(bool unicode = false) const;
00182 
00198     const char *toCString(bool unicode = false) const;
00199 
00203     Iterator begin();
00204 
00208     ConstIterator begin() const;
00209 
00214     Iterator end();
00215 
00220     ConstIterator end() const;
00221 
00226     int find(const String &s, int offset = 0) const;
00227 
00232     String substr(uint position, uint n = 0xffffffff) const;
00233 
00238     String &append(const String &s);
00239 
00245     String upper() const;
00246 
00250     uint size() const;
00251 
00257     bool isEmpty() const;
00258 
00266     bool isNull() const;
00267 
00273     ByteVector data(Type t) const;
00274 
00278     int toInt() const;
00279 
00283     String stripWhiteSpace() const;
00284 
00288     static String number(int n);
00289 
00293     wchar &operator[](int i);
00294 
00298     const wchar &operator[](int i) const;
00299 
00304     bool operator==(const String &s) const;
00305 
00309     String &operator+=(const String &s);
00310 
00314     String &operator+=(const wchar_t* s);
00315 
00319     String &operator+=(const char* s);
00320 
00324     String &operator+=(wchar_t c);
00325 
00329     String &operator+=(char c);
00330 
00335     String &operator=(const String &s);
00336 
00340     String &operator=(const std::string &s);
00341 
00345     String &operator=(const wstring &s);
00346 
00350     String &operator=(const wchar_t *s);
00351 
00355     String &operator=(char c);
00356 
00360     String &operator=(wchar_t c);
00361 
00365     String &operator=(const char *s);
00366 
00370     String &operator=(const ByteVector &v);
00371 
00377     bool operator<(const String &s) const;
00378 
00382     static String null;
00383 
00384   protected:
00390     void detach();
00391 
00392   private:
00399     void prepare(Type t);
00400 
00401     class StringPrivate;
00402     StringPrivate *d;
00403   };
00404 
00405 }
00406 
00410 const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00411 
00415 const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00416 
00420 const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00421 
00422 
00427 std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00428 
00429 #endif