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 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 std::basic_string<wchar>::iterator Iterator;
90  typedef std::basic_string<wchar>::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 
204  wstring toWString() const;
205 
224  const char *toCString(bool unicode = false) const;
225 
242  const wchar_t *toCWString() const;
243 
247  Iterator begin();
248 
252  ConstIterator begin() const;
253 
258  Iterator end();
259 
264  ConstIterator end() const;
265 
270  int find(const String &s, int offset = 0) const;
271 
277  int rfind(const String &s, int offset = -1) const;
278 
282  StringList split(const String &separator = " ") const;
283 
287  bool startsWith(const String &s) const;
288 
293  String substr(uint position, uint n = 0xffffffff) const;
294 
299  String &append(const String &s);
300 
306  String upper() const;
307 
311  uint size() const;
312 
316  uint length() const;
317 
323  bool isEmpty() const;
324 
332  bool isNull() const;
333 
344  ByteVector data(Type t) const;
345 
352  // BIC: merge with the method below
353  int toInt() const;
354 
362  int toInt(bool *ok) const;
363 
367  String stripWhiteSpace() const;
368 
372  bool isLatin1() const;
373 
377  bool isAscii() const;
378 
382  static String number(int n);
383 
387  wchar &operator[](int i);
388 
392  const wchar &operator[](int i) const;
393 
398  bool operator==(const String &s) const;
399 
404  bool operator!=(const String &s) const;
405 
410  bool operator==(const char *s) const;
411 
416  bool operator!=(const char *s) const;
417 
422  bool operator==(const wchar_t *s) const;
423 
428  bool operator!=(const wchar_t *s) const;
429 
433  String &operator+=(const String &s);
434 
438  String &operator+=(const wchar_t* s);
439 
443  String &operator+=(const char* s);
444 
448  String &operator+=(wchar_t c);
449 
453  String &operator+=(char c);
454 
459  String &operator=(const String &s);
460 
464  String &operator=(const std::string &s);
465 
469  String &operator=(const wstring &s);
470 
474  String &operator=(const wchar_t *s);
475 
479  String &operator=(char c);
480 
484  String &operator=(wchar_t c);
485 
489  String &operator=(const char *s);
490 
494  String &operator=(const ByteVector &v);
495 
501  bool operator<(const String &s) const;
502 
506  static String null;
507 
508  protected:
514  void detach();
515 
516  private:
521  void copyFromLatin1(const char *s, size_t length);
522 
527  void copyFromUTF8(const char *s, size_t length);
528 
533  void copyFromUTF16(const wchar_t *s, size_t length, Type t);
534 
539  void copyFromUTF16(const char *s, size_t length, Type t);
540 
546  static const Type WCharByteOrder;
547 
548  class StringPrivate;
549  StringPrivate *d;
550  };
551 }
552 
559 
565 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
566 
572 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
573 
574 
580 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
581 
582 #endif
std::basic_string< wchar > wstring
Definition: taglib.h:76
static String null
Definition: tstring.h:506
unsigned int uint
Definition: taglib.h:66
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
wchar_t wchar
Definition: taglib.h:61
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
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41