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., 51 Franklin Street, Fifth Floor, Boston, MA         *
00019  *   02110-1301  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 
00044 #define QStringToTString(s) TagLib::String(s.utf8().data(), TagLib::String::UTF8)
00045 
00055 #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
00056 
00057 namespace TagLib {
00058 
00059   class StringList;
00060 
00062 
00078   class TAGLIB_EXPORT String
00079   {
00080   public:
00081 
00082 #ifndef DO_NOT_DOCUMENT
00083     typedef std::basic_string<wchar>::iterator Iterator;
00084     typedef std::basic_string<wchar>::const_iterator ConstIterator;
00085 #endif
00086 
00091     enum Type {
00095       Latin1 = 0,
00099       UTF16 = 1,
00104       UTF16BE = 2,
00108       UTF8 = 3,
00112       UTF16LE = 4
00113     };
00114 
00118     String();
00119 
00125     String(const String &s);
00126 
00133     String(const std::string &s, Type t = Latin1);
00134 
00138     String(const wstring &s, Type t = WCharByteOrder);
00139 
00143     String(const wchar_t *s, Type t = WCharByteOrder);
00144 
00151     String(char c, Type t = Latin1);
00152 
00156     String(wchar_t c, Type t = Latin1);
00157 
00158 
00165     String(const char *s, Type t = Latin1);
00166 
00173     String(const ByteVector &v, Type t = Latin1);
00174 
00178     virtual ~String();
00179 
00186     std::string to8Bit(bool unicode = false) const;
00187 
00194     wstring toWString() const;
00195 
00214     const char *toCString(bool unicode = false) const;
00215     
00232     const wchar_t *toCWString() const;
00233     
00237     Iterator begin();
00238 
00242     ConstIterator begin() const;
00243 
00248     Iterator end();
00249 
00254     ConstIterator end() const;
00255 
00260     int find(const String &s, int offset = 0) const;
00261 
00267     int rfind(const String &s, int offset = -1) const;
00268 
00272     StringList split(const String &separator = " ") const;
00273 
00277     bool startsWith(const String &s) const;
00278 
00283     String substr(uint position, uint n = 0xffffffff) const;
00284 
00289     String &append(const String &s);
00290 
00296     String upper() const;
00297 
00301     uint size() const;
00302 
00306     uint length() const;
00307 
00313     bool isEmpty() const;
00314 
00322     bool isNull() const;
00323 
00329     ByteVector data(Type t) const;
00330 
00337     // BIC: merge with the method below
00338     int toInt() const;
00339 
00347     int toInt(bool *ok) const;
00348 
00352     String stripWhiteSpace() const;
00353 
00357     bool isLatin1() const;
00358 
00362     bool isAscii() const;
00363 
00367     static String number(int n);
00368 
00372     wchar &operator[](int i);
00373 
00377     const wchar &operator[](int i) const;
00378 
00383     bool operator==(const String &s) const;
00384 
00389     bool operator!=(const String &s) const;
00390 
00394     String &operator+=(const String &s);
00395 
00399     String &operator+=(const wchar_t* s);
00400 
00404     String &operator+=(const char* s);
00405 
00409     String &operator+=(wchar_t c);
00410 
00414     String &operator+=(char c);
00415 
00420     String &operator=(const String &s);
00421 
00425     String &operator=(const std::string &s);
00426 
00430     String &operator=(const wstring &s);
00431 
00435     String &operator=(const wchar_t *s);
00436 
00440     String &operator=(char c);
00441 
00445     String &operator=(wchar_t c);
00446 
00450     String &operator=(const char *s);
00451 
00455     String &operator=(const ByteVector &v);
00456 
00462     bool operator<(const String &s) const;
00463 
00467     static String null;
00468 
00469   protected:
00475     void detach();
00476 
00477   private:
00482     void copyFromLatin1(const char *s, size_t length);
00483 
00488     void copyFromUTF8(const char *s, size_t length);
00489 
00494     void copyFromUTF16(const wchar_t *s, size_t length, Type t);
00495 
00500     void copyFromUTF16(const char *s, size_t length, Type t);
00501     
00507     static const Type WCharByteOrder;
00508 
00509     class StringPrivate;
00510     StringPrivate *d;
00511   };
00512 }
00513 
00519 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00520 
00526 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00527 
00533 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00534 
00535 
00541 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00542 
00543 #endif