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 
124  String();
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 
205  wstring toWString() const;
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 
305  String &clear();
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  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 
378  String stripWhiteSpace() const;
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 
444  String &operator+=(const String &s);
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 
480  String &operator=(const wstring &s);
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 
505  String &operator=(const ByteVector &v);
506 
510  void swap(String &s);
511 
517  bool operator<(const String &s) const;
518 
527  // BIC: remove
528  static String null;
529 
530  protected:
536  void detach();
537 
538  private:
539  class StringPrivate;
540  StringPrivate *d;
541  };
542 }
543 
550 
556 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
557 
563 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
564 
565 
571 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
572 
573 #endif
std::basic_string< wchar_t > wstring
Definition: taglib.h:76
static String null
Definition: tstring.h:528
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
A wide string class suitable for unicode.
Definition: tstring.h:84
TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2)
A byte vector.
Definition: tbytevector.h:45
A list of strings.
Definition: tstringlist.h:45
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
Type
Definition: tstring.h:97