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       Locale = -1,
00090       Latin1ID3 = 5,
00094       Latin1 = 0,
00098       UTF16 = 1,
00103       UTF16BE = 2,
00107       UTF8 = 3,
00111       UTF16LE = 4
00112     };
00113 
00114     static Type ID3Type(int i);
00115     static Type ID3WType(Type type);
00116 
00120     String();
00121 
00127     String(const String &s);
00128 
00135     String(const std::string &s, Type t = Latin1);
00136 
00140     String(const wstring &s, Type t = UTF16BE);
00141 
00145     String(const wchar_t *s, Type t = UTF16BE);
00146 
00153     String(char c, Type t = Latin1);
00154 
00158     String(wchar_t c, Type t = Latin1);
00159 
00160 
00167     String(const char *s, Type t = Latin1);
00168 
00175     String(const ByteVector &v, Type t = Latin1);
00176 
00180     virtual ~String();
00181 
00187     std::string to8Bit(bool unicode = false) const;
00188 
00192     wstring toWString() const;
00193 
00209     const char *toCString(bool unicode = false) const;
00210 
00214     Iterator begin();
00215 
00219     ConstIterator begin() const;
00220 
00225     Iterator end();
00226 
00231     ConstIterator end() const;
00232 
00237     int find(const String &s, int offset = 0) const;
00238 
00242     bool startsWith(const String &s) const;
00243 
00248     String substr(uint position, uint n = 0xffffffff) const;
00249 
00254     String &append(const String &s);
00255 
00261     String upper() const;
00262 
00266     uint size() const;
00267 
00271     uint length() const;
00272 
00278     bool isEmpty() const;
00279 
00287     bool isNull() const;
00288 
00294     ByteVector data(Type t) const;
00295 
00299     int toInt() const;
00300 
00304     String stripWhiteSpace() const;
00305 
00309     bool isLatin1() const;
00310 
00314     bool isAscii() const;
00315 
00319     static String number(int n);
00320 
00324     wchar &operator[](int i);
00325 
00329     const wchar &operator[](int i) const;
00330 
00335     bool operator==(const String &s) const;
00336 
00340     String &operator+=(const String &s);
00341 
00345     String &operator+=(const wchar_t* s);
00346 
00350     String &operator+=(const char* s);
00351 
00355     String &operator+=(wchar_t c);
00356 
00360     String &operator+=(char c);
00361 
00366     String &operator=(const String &s);
00367 
00371     String &operator=(const std::string &s);
00372 
00376     String &operator=(const wstring &s);
00377 
00381     String &operator=(const wchar_t *s);
00382 
00386     String &operator=(char c);
00387 
00391     String &operator=(wchar_t c);
00392 
00396     String &operator=(const char *s);
00397 
00401     String &operator=(const ByteVector &v);
00402 
00408     bool operator<(const String &s) const;
00409 
00413     static String null;
00414 
00415   protected:
00421     void detach();
00422 
00423   private:
00430     void prepare(Type t);
00431 
00432     class StringPrivate;
00433     StringPrivate *d;
00434   };
00435 
00436 }
00437 
00443 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00444 
00450 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00451 
00457 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00458 
00459 
00465 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00466 
00467 #endif