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 <iostream>
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 
00233     int rfind(const String &s, int offset = -1) const;
00234 
00238     bool startsWith(const String &s) const;
00239 
00244     String substr(uint position, uint n = 0xffffffff) const;
00245 
00250     String &append(const String &s);
00251 
00257     String upper() const;
00258 
00262     uint size() const;
00263 
00267     uint length() const;
00268 
00274     bool isEmpty() const;
00275 
00283     bool isNull() const;
00284 
00290     ByteVector data(Type t) const;
00291 
00298     // BIC: merge with the method below
00299     int toInt() const;
00300 
00308     int toInt(bool *ok) const;
00309 
00313     String stripWhiteSpace() const;
00314 
00318     bool isLatin1() const;
00319 
00323     bool isAscii() const;
00324 
00328     static String number(int n);
00329 
00333     wchar &operator[](int i);
00334 
00338     const wchar &operator[](int i) const;
00339 
00344     bool operator==(const String &s) const;
00345 
00349     String &operator+=(const String &s);
00350 
00354     String &operator+=(const wchar_t* s);
00355 
00359     String &operator+=(const char* s);
00360 
00364     String &operator+=(wchar_t c);
00365 
00369     String &operator+=(char c);
00370 
00375     String &operator=(const String &s);
00376 
00380     String &operator=(const std::string &s);
00381 
00385     String &operator=(const wstring &s);
00386 
00390     String &operator=(const wchar_t *s);
00391 
00395     String &operator=(char c);
00396 
00400     String &operator=(wchar_t c);
00401 
00405     String &operator=(const char *s);
00406 
00410     String &operator=(const ByteVector &v);
00411 
00417     bool operator<(const String &s) const;
00418 
00422     static String null;
00423 
00424   protected:
00430     void detach();
00431 
00432   private:
00439     void prepare(Type t);
00440 
00441     class StringPrivate;
00442     StringPrivate *d;
00443   };
00444 
00445 }
00446 
00452 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00453 
00459 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00460 
00466 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00467 
00468 
00474 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00475 
00476 #endif