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  Latin1 = 0,
105  UTF16 = 1,
110  UTF16BE = 2,
114  UTF8 = 3,
118  UTF16LE = 4
119  };
120 
125 
131  String(const String &s);
132 
139  String(const std::string &s, Type t = Latin1);
140 
148  String(const wstring &s, Type t = UTF16BE);
149 
157  String(const wchar_t *s, Type t = UTF16BE);
158 
165  String(char c, Type t = Latin1);
166 
170  String(wchar_t c, Type t = Latin1);
171 
178  String(const char *s, Type t = Latin1);
179 
183  String(const ByteVector &v, Type t = Latin1);
184 
188  virtual ~String();
189 
196  std::string to8Bit(bool unicode = false) const;
197 
206 
225  const char *toCString(bool unicode = false) const;
226 
243  const wchar_t *toCWString() const;
244 
248  Iterator begin();
249 
253  ConstIterator begin() const;
254 
259  Iterator end();
260 
265  ConstIterator end() const;
266 
271  int find(const String &s, int offset = 0) const;
272 
278  int rfind(const String &s, int offset = -1) const;
279 
283  StringList split(const String &separator = " ") const;
284 
288  bool startsWith(const String &s) const;
289 
294  String substr(unsigned int position, unsigned int n = 0xffffffff) const;
295 
300  String &append(const String &s);
301 
306 
312  String upper() const;
313 
317  unsigned int size() const;
318 
322  unsigned int length() const;
323 
329  bool isEmpty() const;
330 
342  // BIC: remove
343  TAGLIB_DEPRECATED bool isNull() const;
344 
355  ByteVector data(Type t) const;
356 
363  // BIC: merge with the method below
364  int toInt() const;
365 
373  int toInt(bool *ok) const;
374 
379 
383  bool isLatin1() const;
384 
388  bool isAscii() const;
389 
393  static String number(int n);
394 
398  wchar_t &operator[](int i);
399 
403  const wchar_t &operator[](int i) const;
404 
409  bool operator==(const String &s) const;
410 
415  bool operator!=(const String &s) const;
416 
421  bool operator==(const char *s) const;
422 
427  bool operator!=(const char *s) const;
428 
433  bool operator==(const wchar_t *s) const;
434 
439  bool operator!=(const wchar_t *s) const;
440 
445 
449  String &operator+=(const wchar_t* s);
450 
454  String &operator+=(const char* s);
455 
459  String &operator+=(wchar_t c);
460 
464  String &operator+=(char c);
465 
470  String &operator=(const String &s);
471 
475  String &operator=(const std::string &s);
476 
481 
485  String &operator=(const wchar_t *s);
486 
490  String &operator=(char c);
491 
495  String &operator=(wchar_t c);
496 
500  String &operator=(const char *s);
501 
506 
510  void swap(String &s);
511 
517  bool operator<(const String &s) const;
518 
527  // BIC: remove
529 
530  protected:
536  void detach();
537 
538  private:
543  // BIC: remove
544  TAGLIB_DEPRECATED static const Type WCharByteOrder;
545 
546  class StringPrivate;
547  StringPrivate *d;
548  };
549 }
550 
557 
563 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
564 
570 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
571 
572 
578 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
579 
580 #endif
A byte vector.
Definition: tbytevector.h:46
A list of strings.
Definition: tstringlist.h:46
A wide string class suitable for unicode.
Definition: tstring.h:85
String & operator+=(char c)
bool operator==(const wchar_t *s) const
String upper() const
String & operator=(wchar_t c)
virtual ~String()
String & operator=(const char *s)
bool isEmpty() const
bool isLatin1() const
void swap(String &s)
bool startsWith(const String &s) const
String & operator=(char c)
String & operator+=(const char *s)
StringList split(const String &separator=" ") const
wstring toWString() const
String & clear()
String(char c, Type t=Latin1)
bool operator!=(const char *s) const
String(const wchar_t *s, Type t=UTF16BE)
String & operator+=(wchar_t c)
const wchar_t & operator[](int i) const
bool operator!=(const wchar_t *s) const
TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2)
ByteVector data(Type t) const
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::String &str)
static String number(int n)
String(const wstring &s, Type t=UTF16BE)
ConstIterator end() const
String & operator+=(const String &s)
unsigned int length() const
bool operator==(const char *s) const
String & append(const String &s)
wchar_t & operator[](int i)
String & operator=(const wstring &s)
String(const char *s, Type t=Latin1)
String & operator=(const ByteVector &v)
String stripWhiteSpace() const
Iterator begin()
TAGLIB_DEPRECATED bool isNull() const
String(const ByteVector &v, Type t=Latin1)
TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2)
String(const String &s)
bool operator<(const String &s) const
std::string to8Bit(bool unicode=false) const
bool isAscii() const
String & operator+=(const wchar_t *s)
Type
Definition: tstring.h:97
const char * toCString(bool unicode=false) const
String substr(unsigned int position, unsigned int n=0xffffffff) const
Iterator end()
int toInt(bool *ok) const
String(const std::string &s, Type t=Latin1)
const wchar_t * toCWString() const
ConstIterator begin() const
bool operator==(const String &s) const
int toInt() const
String(wchar_t c, Type t=Latin1)
unsigned int size() const
int rfind(const String &s, int offset=-1) const
TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2)
String & operator=(const std::string &s)
String & operator=(const wchar_t *s)
bool operator!=(const String &s) const
String & operator=(const String &s)
int find(const String &s, int offset=0) const
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41
std::basic_string< wchar_t > wstring
Definition: taglib.h:86
#define TAGLIB_DEPRECATED
Definition: taglib.h:54
#define TAGLIB_EXPORT
Definition: taglib_export.h:40