tstring.h
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2002 - 2008 by Scott Wheeler
3  email : wheeler@kde.org
4  ***************************************************************************/
5 
6 /***************************************************************************
7  * This library is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU Lesser General Public License version *
9  * 2.1 as published by the Free Software Foundation. *
10  * *
11  * This library is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the Free Software *
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19  * 02110-1301 USA *
20  * *
21  * Alternatively, this file is available under the Mozilla Public *
22  * License Version 1.1. You may obtain a copy of the License at *
23  * http://www.mozilla.org/MPL/ *
24  ***************************************************************************/
25 
26 #ifndef TAGLIB_STRING_H
27 #define TAGLIB_STRING_H
28 
29 #include "taglib_export.h"
30 #include "taglib.h"
31 #include "tbytevector.h"
32 
33 #include <string>
34 #include <iostream>
35 
45 #if defined(QT_VERSION) && (QT_VERSION >= 0x040000)
46 #define QStringToTString(s) TagLib::String(s.toUtf8().data(), TagLib::String::UTF8)
47 #else
48 #define QStringToTString(s) TagLib::String(s.utf8().data(), TagLib::String::UTF8)
49 #endif
50 
61 #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
62 
63 namespace TagLib {
64 
65  class StringList;
66 
68 
85  {
86  public:
87 
88 #ifndef DO_NOT_DOCUMENT
89  typedef TagLib::wstring::iterator Iterator;
90  typedef TagLib::wstring::const_iterator ConstIterator;
91 #endif
92 
97  enum Type {
101  Locale = -1,
105  Latin1ID3 = 65,
109  Latin1ID3V2 = 66,
113  Latin1 = 0,
117  UTF16 = 1,
122  UTF16BE = 2,
126  UTF8 = 3,
130  UTF16LE = 4
131  };
132 
133  static Type ID3Type(int i);
134  static Type ID3WType(Type type);
135  static Type ID3RealType(Type type);
136 
141 
147  String(const String &s);
148 
155  String(const std::string &s, Type t = Latin1);
156 
164  String(const wstring &s, Type t = UTF16BE);
165 
173  String(const wchar_t *s, Type t = UTF16BE);
174 
181  String(char c, Type t = Latin1);
182 
186  String(wchar_t c, Type t = Latin1);
187 
194  String(const char *s, Type t = Latin1);
195 
199  String(const ByteVector &v, Type t = Latin1);
200 
204  virtual ~String();
205 
212  std::string to8Bit(bool unicode = false) const;
213 
222 
241  const char *toCString(bool unicode = false) const;
242 
259  const wchar_t *toCWString() const;
260 
264  Iterator begin();
265 
269  ConstIterator begin() const;
270 
275  Iterator end();
276 
281  ConstIterator end() const;
282 
287  int find(const String &s, int offset = 0) const;
288 
294  int rfind(const String &s, int offset = -1) const;
295 
299  StringList split(const String &separator = " ") const;
300 
304  bool startsWith(const String &s) const;
305 
310  String substr(unsigned int position, unsigned int n = 0xffffffff) const;
311 
316  String &append(const String &s);
317 
322 
328  String upper() const;
329 
333  unsigned int size() const;
334 
338  unsigned int length() const;
339 
345  bool isEmpty() const;
346 
358  // BIC: remove
359  bool isNull() const;
360 
371  ByteVector data(Type t) const;
372 
379  // BIC: merge with the method below
380  int toInt() const;
381 
389  int toInt(bool *ok) const;
390 
395 
399  bool isLatin1() const;
400 
404  bool isAscii() const;
405 
409  static String number(int n);
410 
414  wchar_t &operator[](int i);
415 
419  const wchar_t &operator[](int i) const;
420 
425  bool operator==(const String &s) const;
426 
431  bool operator!=(const String &s) const;
432 
437  bool operator==(const char *s) const;
438 
443  bool operator!=(const char *s) const;
444 
449  bool operator==(const wchar_t *s) const;
450 
455  bool operator!=(const wchar_t *s) const;
456 
461 
465  String &operator+=(const wchar_t* s);
466 
470  String &operator+=(const char* s);
471 
475  String &operator+=(wchar_t c);
476 
480  String &operator+=(char c);
481 
486  String &operator=(const String &s);
487 
491  String &operator=(const std::string &s);
492 
497 
501  String &operator=(const wchar_t *s);
502 
506  String &operator=(char c);
507 
511  String &operator=(wchar_t c);
512 
516  String &operator=(const char *s);
517 
522 
526  void swap(String &s);
527 
533  bool operator<(const String &s) const;
534 
543  // BIC: remove
544  static String null;
545 
546  protected:
552  void detach();
553 
554  private:
559  // BIC: remove
560  static const Type WCharByteOrder;
561 
562  class StringPrivate;
563  StringPrivate *d;
564  };
565 }
566 
573 
579 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
580 
586 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
587 
588 
594 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
595 
596 #endif
String & operator=(const ByteVector &v)
static Type ID3RealType(Type type)
String(const wchar_t *s, Type t=UTF16BE)
int toInt(bool *ok) const
String & clear()
String & operator+=(const String &s)
String(wchar_t c, Type t=Latin1)
String(const char *s, Type t=Latin1)
A list of strings.
Definition: tstringlist.h:46
TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2)
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41
wchar_t & operator[](int i)
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::String &str)
bool operator==(const char *s) const
String(const ByteVector &v, Type t=Latin1)
bool operator!=(const wchar_t *s) const
unsigned int size() const
bool operator<(const String &s) const
const char * toCString(bool unicode=false) const
int rfind(const String &s, int offset=-1) const
virtual ~String()
String(const std::string &s, Type t=Latin1)
String substr(unsigned int position, unsigned int n=0xffffffff) const
StringList split(const String &separator=" ") const
void swap(String &s)
std::string to8Bit(bool unicode=false) const
ConstIterator begin() const
Type
Definition: tstring.h:97
bool operator!=(const String &s) const
Iterator begin()
const wchar_t * toCWString() const
String & append(const String &s)
String & operator=(const char *s)
String & operator+=(wchar_t c)
String & operator=(const wstring &s)
ConstIterator end() const
Iterator end()
String & operator=(const wchar_t *s)
void detach()
bool operator==(const String &s) const
String(char c, Type t=Latin1)
int find(const String &s, int offset=0) const
bool operator!=(const char *s) const
String & operator=(const std::string &s)
int toInt() const
bool isEmpty() const
static Type ID3Type(int i)
String & operator=(char c)
String upper() const
String & operator=(wchar_t c)
ByteVector data(Type t) const
A byte vector.
Definition: tbytevector.h:46
std::basic_string< wchar_t > wstring
Definition: taglib.h:76
String(const String &s)
TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2)
String & operator+=(char c)
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
String(const wstring &s, Type t=UTF16BE)
String stripWhiteSpace() const
bool operator==(const wchar_t *s) const
bool startsWith(const String &s) const
const wchar_t & operator[](int i) const
static Type ID3WType(Type type)
bool isNull() const
wstring toWString() const
String & operator=(const String &s)
bool isAscii() const
String()
TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2)
A wide string class suitable for unicode.
Definition: tstring.h:85
unsigned int length() const
static String number(int n)
String & operator+=(const char *s)
String & operator+=(const wchar_t *s)
bool isLatin1() const