tstring.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     copyright            : (C) 2002 - 2008 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  *   Alternatively, this file is available under the Mozilla Public        *
00022  *   License Version 1.1.  You may obtain a copy of the License at         *
00023  *   http://www.mozilla.org/MPL/                                           *
00024  ***************************************************************************/
00025 
00026 #ifndef TAGLIB_STRING_H
00027 #define TAGLIB_STRING_H
00028 
00029 #include "taglib_export.h"
00030 #include "taglib.h"
00031 #include "tbytevector.h"
00032 
00033 #include <string>
00034 #include <ostream>
00035 
00041 #define QStringToTString(s) TagLib::String(s.utf8().data(), TagLib::String::UTF8)
00042 
00048 #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
00049 
00050 namespace TagLib {
00051 
00053 
00069   class TAGLIB_EXPORT String
00070   {
00071   public:
00072 
00073 #ifndef DO_NOT_DOCUMENT
00074     typedef std::basic_string<wchar>::iterator Iterator;
00075     typedef std::basic_string<wchar>::const_iterator ConstIterator;
00076 #endif
00077 
00082     enum Type {
00086       Latin1 = 0,
00090       UTF16 = 1,
00095       UTF16BE = 2,
00099       UTF8 = 3,
00103       UTF16LE = 4
00104     };
00105 
00109     String();
00110 
00116     String(const String &s);
00117 
00124     String(const std::string &s, Type t = Latin1);
00125 
00129     String(const wstring &s, Type t = UTF16BE);
00130 
00134     String(const wchar_t *s, Type t = UTF16BE);
00135 
00142     String(char c, Type t = Latin1);
00143 
00147     String(wchar_t c, Type t = Latin1);
00148 
00149 
00156     String(const char *s, Type t = Latin1);
00157 
00164     String(const ByteVector &v, Type t = Latin1);
00165 
00169     virtual ~String();
00170 
00176     std::string to8Bit(bool unicode = false) const;
00177 
00181     wstring toWString() 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 
00231     bool startsWith(const String &s) const;
00232 
00237     String substr(uint position, uint n = 0xffffffff) const;
00238 
00243     String &append(const String &s);
00244 
00250     String upper() const;
00251 
00255     uint size() const;
00256 
00260     uint length() const;
00261 
00267     bool isEmpty() const;
00268 
00276     bool isNull() const;
00277 
00283     ByteVector data(Type t) const;
00284 
00288     int toInt() const;
00289 
00293     String stripWhiteSpace() const;
00294 
00298     bool isLatin1() const;
00299 
00303     bool isAscii() const;
00304 
00308     static String number(int n);
00309 
00313     wchar &operator[](int i);
00314 
00318     const wchar &operator[](int i) const;
00319 
00324     bool operator==(const String &s) const;
00325 
00329     String &operator+=(const String &s);
00330 
00334     String &operator+=(const wchar_t* s);
00335 
00339     String &operator+=(const char* s);
00340 
00344     String &operator+=(wchar_t c);
00345 
00349     String &operator+=(char c);
00350 
00355     String &operator=(const String &s);
00356 
00360     String &operator=(const std::string &s);
00361 
00365     String &operator=(const wstring &s);
00366 
00370     String &operator=(const wchar_t *s);
00371 
00375     String &operator=(char c);
00376 
00380     String &operator=(wchar_t c);
00381 
00385     String &operator=(const char *s);
00386 
00390     String &operator=(const ByteVector &v);
00391 
00397     bool operator<(const String &s) const;
00398 
00402     static String null;
00403 
00404   protected:
00410     void detach();
00411 
00412   private:
00419     void prepare(Type t);
00420 
00421     class StringPrivate;
00422     StringPrivate *d;
00423   };
00424 
00425 }
00426 
00432 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00433 
00439 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00440 
00446 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00447 
00448 
00454 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00455 
00456 #endif