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 
44 #define QStringToTString(s) TagLib::String(s.utf8().data(), TagLib::String::UTF8)
45 
55 #define TStringToQString(s) QString::fromUtf8(s.toCString(true))
56 
57 namespace TagLib {
58 
59  class StringList;
60 
62 
79  {
80  public:
81 
82 #ifndef DO_NOT_DOCUMENT
83  typedef std::basic_string<wchar>::iterator Iterator;
84  typedef std::basic_string<wchar>::const_iterator ConstIterator;
85 #endif
86 
91  enum Type {
95  Locale = -1,
99  Latin1ID3 = 65,
103  Latin1ID3V2 = 66,
107  Latin1 = 0,
111  UTF16 = 1,
116  UTF16BE = 2,
120  UTF8 = 3,
124  UTF16LE = 4
125  };
126 
127  static Type ID3Type(int i);
128  static Type ID3WType(Type type);
129  static Type ID3RealType(Type type);
130 
134  String();
135 
141  String(const String &s);
142 
149  String(const std::string &s, Type t = Latin1);
150 
154  String(const wstring &s, Type t = UTF16BE);
155 
159  String(const wchar_t *s, Type t = UTF16BE);
160 
167  String(char c, Type t = Latin1);
168 
172  String(wchar_t c, Type t = Latin1);
173 
174 
181  String(const char *s, Type t = Latin1);
182 
189  String(const ByteVector &v, Type t = Latin1);
190 
194  virtual ~String();
195 
201  std::string to8Bit(bool unicode = false) const;
202 
206  wstring toWString() const;
207 
223  const char *toCString(bool unicode = false) const;
224 
228  Iterator begin();
229 
233  ConstIterator begin() const;
234 
239  Iterator end();
240 
245  ConstIterator end() const;
246 
251  int find(const String &s, int offset = 0) const;
252 
258  int rfind(const String &s, int offset = -1) const;
259 
263  StringList split(const String &separator = " ") const;
264 
268  bool startsWith(const String &s) const;
269 
274  String substr(uint position, uint n = 0xffffffff) const;
275 
280  String &append(const String &s);
281 
287  String upper() const;
288 
292  uint size() const;
293 
297  uint length() const;
298 
304  bool isEmpty() const;
305 
313  bool isNull() const;
314 
320  ByteVector data(Type t) const;
321 
328  // BIC: merge with the method below
329  int toInt() const;
330 
338  int toInt(bool *ok) const;
339 
343  String stripWhiteSpace() const;
344 
348  bool isLatin1() const;
349 
353  bool isAscii() const;
354 
358  static String number(int n);
359 
363  wchar &operator[](int i);
364 
368  const wchar &operator[](int i) const;
369 
374  bool operator==(const String &s) const;
375 
380  bool operator!=(const String &s) const;
381 
385  String &operator+=(const String &s);
386 
390  String &operator+=(const wchar_t* s);
391 
395  String &operator+=(const char* s);
396 
400  String &operator+=(wchar_t c);
401 
405  String &operator+=(char c);
406 
411  String &operator=(const String &s);
412 
416  String &operator=(const std::string &s);
417 
421  String &operator=(const wstring &s);
422 
426  String &operator=(const wchar_t *s);
427 
431  String &operator=(char c);
432 
436  String &operator=(wchar_t c);
437 
441  String &operator=(const char *s);
442 
446  String &operator=(const ByteVector &v);
447 
453  bool operator<(const String &s) const;
454 
458  static String null;
459 
460  protected:
466  void detach();
467 
468  private:
475  void prepare(Type t);
476 
477  class StringPrivate;
478  StringPrivate *d;
479  };
480 
481 }
482 
489 
495 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
496 
502 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
503 
504 
510 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
511 
512 #endif