TagLib  2.0.2
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 <string>
30 
31 #include "tbytevector.h"
32 #include "taglib_export.h"
33 
43 #if defined(QT_VERSION) && (QT_VERSION >= 0x040000)
44 #define QStringToTString(s) TagLib::String(s.toUtf8().data(), TagLib::String::UTF8)
45 #else
46 #define QStringToTString(s) TagLib::String((s).utf8().data(), TagLib::String::UTF8)
47 #endif
48 
59 #define TStringToQString(s) QString::fromUtf8((s).toCString(true))
60 
61 namespace TagLib {
62 
63  class StringList;
64 
66 
83  {
84  public:
85 
86 #ifndef DO_NOT_DOCUMENT
87  using Iterator = std::wstring::iterator;
88  using ConstIterator = std::wstring::const_iterator;
89 #endif
90 
96  enum Type {
100  Latin1 = 0,
104  UTF16 = 1,
109  UTF16BE = 2,
113  UTF8 = 3,
117  UTF16LE = 4
118  };
119 
123  String();
124 
130  String(const String &s);
131 
138  String(const std::string &s, Type t = Latin1);
139 
143  String(const std::wstring &s);
144 
148  String(const std::wstring &s, Type t);
149 
153  String(const wchar_t *s);
154 
158  String(const wchar_t *s, Type t);
159 
166  String(char c, Type t = Latin1);
167 
171  String(wchar_t c, Type t = Latin1);
172 
179  String(const char *s, Type t = Latin1);
180 
184  String(const ByteVector &v, Type t = Latin1);
185 
189  ~String();
190 
197  std::string to8Bit(bool unicode = false) const;
198 
206  std::wstring toWString() const;
207 
226  const char *toCString(bool unicode = false) const;
227 
244  const wchar_t *toCWString() const;
245 
249  Iterator begin();
250 
254  ConstIterator begin() const;
255 
259  ConstIterator cbegin() const;
260 
265  Iterator end();
266 
271  ConstIterator end() const;
272 
277  ConstIterator cend() const;
278 
283  int find(const String &s, int offset = 0) const;
284 
290  int rfind(const String &s, int offset = -1) const;
291 
295  StringList split(const String &separator = " ") const;
296 
300  bool startsWith(const String &s) const;
301 
306  String substr(unsigned int position, unsigned int n = 0xffffffff) const;
307 
312  String &append(const String &s);
313 
317  String &clear();
318 
324  String upper() const;
325 
329  unsigned int size() const;
330 
334  unsigned int length() const;
335 
339  bool isEmpty() const;
340 
351  ByteVector data(Type t) const;
352 
360  int toInt(bool *ok = nullptr) const;
361 
365  String stripWhiteSpace() const;
366 
370  bool isLatin1() const;
371 
375  bool isAscii() const;
376 
380  static String number(int n);
381 
385  static String fromLongLong(long long n);
386 
390  wchar_t &operator[](int i);
391 
395  const wchar_t &operator[](int i) const;
396 
401  bool operator==(const String &s) const;
402 
407  bool operator!=(const String &s) const;
408 
413  bool operator==(const char *s) const;
414 
419  bool operator!=(const char *s) const;
420 
425  bool operator==(const wchar_t *s) const;
426 
431  bool operator!=(const wchar_t *s) const;
432 
436  String &operator+=(const String &s);
437 
441  String &operator+=(const wchar_t* s);
442 
446  String &operator+=(const char* s);
447 
451  String &operator+=(wchar_t c);
452 
456  String &operator+=(char c);
457 
462  String &operator=(const String &s);
463 
467  String &operator=(const std::string &s);
468 
472  String &operator=(const std::wstring &s);
473 
477  String &operator=(const wchar_t *s);
478 
482  String &operator=(char c);
483 
487  String &operator=(wchar_t c);
488 
492  String &operator=(const char *s);
493 
497  String &operator=(const ByteVector &v);
498 
502  void swap(String &s) noexcept;
503 
509  bool operator<(const String &s) const;
510 
511  protected:
517  void detach();
518 
519  private:
520  class StringPrivate;
522  std::shared_ptr<StringPrivate> d;
523  };
524 } // namespace TagLib
525 
532 
538 TAGLIB_EXPORT TagLib::String operator+(const char *s1, const TagLib::String &s2);
539 
545 TAGLIB_EXPORT TagLib::String operator+(const TagLib::String &s1, const char *s2);
546 
547 
553 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
554 
555 #endif
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::ByteVector &v)
A wide string class suitable for unicode.
Definition: tstring.h:82
A byte vector.
Definition: tbytevector.h:45
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
Definition: taglib_export.h:55
A list of strings.
Definition: tstringlist.h:43
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
Type
Definition: tstring.h:96
TAGLIB_EXPORT TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2)
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41