TagLib API Documentation
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
61namespace 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
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
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
318
324 String upper() const;
325
329 unsigned int size() const;
330
334 unsigned int length() const;
335
339 bool isEmpty() const;
340
352
360 int toInt(bool *ok = nullptr) const;
361
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
437
441 String &operator+=(const wchar_t* s);
442
446 String &operator+=(const char* s);
447
451 String &operator+=(wchar_t c);
452
457
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
483
487 String &operator=(wchar_t c);
488
492 String &operator=(const char *s);
493
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
539
546
547
553TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
554
555#endif
A byte vector.
Definition: tbytevector.h:46
A list of strings.
Definition: tstringlist.h:44
A wide string class suitable for unicode.
Definition: tstring.h:83
TAGLIB_EXPORT TagLib::String operator+(const TagLib::String &s1, const char *s2)
String & operator=(const String &s)
bool operator==(const wchar_t *s) const
String upper() const
bool isEmpty() const
bool isLatin1() const
std::wstring toWString() const
String & operator+=(wchar_t c)
bool startsWith(const String &s) const
int toInt(bool *ok=nullptr) const
String & operator+=(char c)
ConstIterator cbegin() const
String & append(const String &s)
StringList split(const String &separator=" ") const
String & operator=(const ByteVector &v)
String(char c, Type t=Latin1)
bool operator!=(const char *s) const
String(const wchar_t *s)
bool operator!=(const wchar_t *s) const
ByteVector data(Type t) const
TAGLIB_EXPORT TagLib::String operator+(const TagLib::String &s1, const TagLib::String &s2)
static String fromLongLong(long long n)
TAGLIB_EXPORT std::ostream & operator<<(std::ostream &s, const TagLib::String &str)
String(const wchar_t *s, Type t)
static String number(int n)
ConstIterator end() const
unsigned int length() const
bool operator==(const char *s) const
String & operator+=(const char *s)
String & operator=(const std::wstring &s)
String & operator+=(const String &s)
String(const char *s, Type t=Latin1)
String(const std::wstring &s)
String & operator=(char c)
String stripWhiteSpace() const
Iterator begin()
String(const ByteVector &v, Type t=Latin1)
const wchar_t * toCWString() const
String(const String &s)
bool operator<(const String &s) const
const char * toCString(bool unicode=false) const
const wchar_t & operator[](int i) const
String & clear()
std::string to8Bit(bool unicode=false) const
wchar_t & operator[](int i)
String & operator=(wchar_t c)
bool isAscii() const
ConstIterator cend() const
String & operator=(const std::string &s)
String & operator+=(const wchar_t *s)
Type
Definition: tstring.h:96
String(const std::wstring &s, Type t)
TAGLIB_EXPORT TagLib::String operator+(const char *s1, const TagLib::String &s2)
String substr(unsigned int position, unsigned int n=0xffffffff) const
Iterator end()
void swap(String &s) noexcept
String(const std::string &s, Type t=Latin1)
String & operator=(const wchar_t *s)
ConstIterator begin() const
bool operator==(const String &s) const
String(wchar_t c, Type t=Latin1)
unsigned int size() const
int rfind(const String &s, int offset=-1) const
bool operator!=(const String &s) const
String & operator=(const char *s)
int find(const String &s, int offset=0) const
A namespace for all TagLib related classes and functions.
Definition: apefile.h:41
#define TAGLIB_EXPORT
Definition: taglib_export.h:40
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
Definition: taglib_export.h:55