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       Latin1 = 0,
00084       UTF16 = 1,
00089       UTF16BE = 2,
00093       UTF8 = 3,
00097       UTF16LE = 4
00098     };
00099 
00103     String();
00104 
00110     String(const String &s);
00111 
00118     String(const std::string &s, Type t = Latin1);
00119 
00123     String(const wstring &s, Type t = UTF16BE);
00124 
00128     String(const wchar_t *s, Type t = UTF16BE);
00129 
00136     String(char c, Type t = Latin1);
00137 
00141     String(wchar_t c, Type t = Latin1);
00142 
00143 
00150     String(const char *s, Type t = Latin1);
00151 
00158     String(const ByteVector &v, Type t = Latin1);
00159 
00163     virtual ~String();
00164 
00170     std::string to8Bit(bool unicode = false) const;
00171 
00187     const char *toCString(bool unicode = false) const;
00188 
00192     Iterator begin();
00193 
00197     ConstIterator begin() const;
00198 
00203     Iterator end();
00204 
00209     ConstIterator end() const;
00210 
00215     int find(const String &s, int offset = 0) const;
00216 
00221     String substr(uint position, uint n = 0xffffffff) const;
00222 
00227     String &append(const String &s);
00228 
00234     String upper() const;
00235 
00239     uint size() const;
00240 
00246     bool isEmpty() const;
00247 
00255     bool isNull() const;
00256 
00262     ByteVector data(Type t) const;
00263 
00267     int toInt() const;
00268 
00272     String stripWhiteSpace() const;
00273 
00277     static String number(int n);
00278 
00282     wchar &operator[](int i);
00283 
00287     const wchar &operator[](int i) const;
00288 
00293     bool operator==(const String &s) const;
00294 
00298     String &operator+=(const String &s);
00299 
00303     String &operator+=(const wchar_t* s);
00304 
00308     String &operator+=(const char* s);
00309 
00313     String &operator+=(wchar_t c);
00314 
00318     String &operator+=(char c);
00319 
00324     String &operator=(const String &s);
00325 
00329     String &operator=(const std::string &s);
00330 
00334     String &operator=(const wstring &s);
00335 
00339     String &operator=(const wchar_t *s);
00340 
00344     String &operator=(char c);
00345 
00349     String &operator=(wchar_t c);
00350 
00354     String &operator=(const char *s);
00355 
00359     String &operator=(const ByteVector &v);
00360 
00366     bool operator<(const String &s) const;
00367 
00371     static String null;
00372 
00373   protected:
00379     void detach();
00380 
00381   private:
00388     void prepare(Type t);
00389 
00390     class StringPrivate;
00391     StringPrivate *d;
00392   };
00393 
00394 }
00395 
00399 const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00400 
00404 const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00405 
00409 const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00410 
00411 
00416 std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00417 
00418 #endif