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 
00045 #if defined(QT_VERSION) && (QT_VERSION >= 0x040000)
00046 #define QStringToTString(s) TagLib::String(s.toUtf8().data(), TagLib::String::UTF8)
00047 #else
00048 #define QStringToTString(s) TagLib::String(s.utf8().data(), TagLib::String::UTF8)
00049 #endif
00050 
00061 #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
00062 
00063 namespace TagLib {
00064 
00065   class StringList;
00066 
00068 
00084   class TAGLIB_EXPORT String
00085   {
00086   public:
00087 
00088 #ifndef DO_NOT_DOCUMENT
00089     typedef TagLib::wstring::iterator Iterator;
00090     typedef TagLib::wstring::const_iterator ConstIterator;
00091 #endif
00092 
00097     enum Type {
00101       Latin1 = 0,
00105       UTF16 = 1,
00110       UTF16BE = 2,
00114       UTF8 = 3,
00118       UTF16LE = 4
00119     };
00120 
00124     String();
00125 
00131     String(const String &s);
00132 
00139     String(const std::string &s, Type t = Latin1);
00140 
00148     String(const wstring &s, Type t = UTF16BE);
00149 
00157     String(const wchar_t *s, Type t = UTF16BE);
00158 
00165     String(char c, Type t = Latin1);
00166 
00170     String(wchar_t c, Type t = Latin1);
00171 
00178     String(const char *s, Type t = Latin1);
00179 
00183     String(const ByteVector &v, Type t = Latin1);
00184 
00188     virtual ~String();
00189 
00196     std::string to8Bit(bool unicode = false) const;
00197 
00205     wstring toWString() const;
00206 
00225     const char *toCString(bool unicode = false) const;
00226 
00243     const wchar_t *toCWString() const;
00244 
00248     Iterator begin();
00249 
00253     ConstIterator begin() const;
00254 
00259     Iterator end();
00260 
00265     ConstIterator end() const;
00266 
00271     int find(const String &s, int offset = 0) const;
00272 
00278     int rfind(const String &s, int offset = -1) const;
00279 
00283     StringList split(const String &separator = " ") const;
00284 
00288     bool startsWith(const String &s) const;
00289 
00294     String substr(unsigned int position, unsigned int n = 0xffffffff) const;
00295 
00300     String &append(const String &s);
00301 
00305     String &clear();
00306 
00312     String upper() const;
00313 
00317     unsigned int size() const;
00318 
00322     unsigned int length() const;
00323 
00329     bool isEmpty() const;
00330 
00342      // BIC: remove
00343     bool isNull() const;
00344 
00355     ByteVector data(Type t) const;
00356 
00363     // BIC: merge with the method below
00364     int toInt() const;
00365 
00373     int toInt(bool *ok) const;
00374 
00378     String stripWhiteSpace() const;
00379 
00383     bool isLatin1() const;
00384 
00388     bool isAscii() const;
00389 
00393     static String number(int n);
00394 
00398     wchar_t &operator[](int i);
00399 
00403     const wchar_t &operator[](int i) const;
00404 
00409     bool operator==(const String &s) const;
00410 
00415     bool operator!=(const String &s) const;
00416 
00421     bool operator==(const char *s) const;
00422 
00427     bool operator!=(const char *s) const;
00428 
00433     bool operator==(const wchar_t *s) const;
00434 
00439     bool operator!=(const wchar_t *s) const;
00440 
00444     String &operator+=(const String &s);
00445 
00449     String &operator+=(const wchar_t* s);
00450 
00454     String &operator+=(const char* s);
00455 
00459     String &operator+=(wchar_t c);
00460 
00464     String &operator+=(char c);
00465 
00470     String &operator=(const String &s);
00471 
00475     String &operator=(const std::string &s);
00476 
00480     String &operator=(const wstring &s);
00481 
00485     String &operator=(const wchar_t *s);
00486 
00490     String &operator=(char c);
00491 
00495     String &operator=(wchar_t c);
00496 
00500     String &operator=(const char *s);
00501 
00505     String &operator=(const ByteVector &v);
00506 
00510     void swap(String &s);
00511 
00517     bool operator<(const String &s) const;
00518 
00527      // BIC: remove
00528     static String null;
00529 
00530   protected:
00536     void detach();
00537 
00538   private:
00539     class StringPrivate;
00540     StringPrivate *d;
00541   };
00542 }
00543 
00549 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2);
00550 
00556 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
00557 
00563 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
00564 
00565 
00571 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
00572 
00573 #endif