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  Latin1 = 0,
99  UTF16 = 1,
104  UTF16BE = 2,
108  UTF8 = 3,
112  UTF16LE = 4
113  };
114 
118  String();
119 
125  String(const String &s);
126 
133  String(const std::string &s, Type t = Latin1);
134 
138  String(const wstring &s, Type t = WCharByteOrder);
139 
143  String(const wchar_t *s, Type t = WCharByteOrder);
144 
151  String(char c, Type t = Latin1);
152 
156  String(wchar_t c, Type t = Latin1);
157 
158 
165  String(const char *s, Type t = Latin1);
166 
173  String(const ByteVector &v, Type t = Latin1);
174 
178  virtual ~String();
179 
186  std::string to8Bit(bool unicode = false) const;
187 
194  wstring toWString() const;
195 
214  const char *toCString(bool unicode = false) const;
215 
232  const wchar_t *toCWString() const;
233 
237  Iterator begin();
238 
242  ConstIterator begin() const;
243 
248  Iterator end();
249 
254  ConstIterator end() const;
255 
260  int find(const String &s, int offset = 0) const;
261 
267  int rfind(const String &s, int offset = -1) const;
268 
272  StringList split(const String &separator = " ") const;
273 
277  bool startsWith(const String &s) const;
278 
283  String substr(uint position, uint n = 0xffffffff) const;
284 
289  String &append(const String &s);
290 
296  String upper() const;
297 
301  uint size() const;
302 
306  uint length() const;
307 
313  bool isEmpty() const;
314 
322  bool isNull() const;
323 
329  ByteVector data(Type t) const;
330 
337  // BIC: merge with the method below
338  int toInt() const;
339 
347  int toInt(bool *ok) const;
348 
352  String stripWhiteSpace() const;
353 
357  bool isLatin1() const;
358 
362  bool isAscii() const;
363 
367  static String number(int n);
368 
372  wchar &operator[](int i);
373 
377  const wchar &operator[](int i) const;
378 
383  bool operator==(const String &s) const;
384 
389  bool operator!=(const String &s) const;
390 
394  String &operator+=(const String &s);
395 
399  String &operator+=(const wchar_t* s);
400 
404  String &operator+=(const char* s);
405 
409  String &operator+=(wchar_t c);
410 
414  String &operator+=(char c);
415 
420  String &operator=(const String &s);
421 
425  String &operator=(const std::string &s);
426 
430  String &operator=(const wstring &s);
431 
435  String &operator=(const wchar_t *s);
436 
440  String &operator=(char c);
441 
445  String &operator=(wchar_t c);
446 
450  String &operator=(const char *s);
451 
455  String &operator=(const ByteVector &v);
456 
462  bool operator<(const String &s) const;
463 
467  static String null;
468 
469  protected:
475  void detach();
476 
477  private:
482  void copyFromLatin1(const char *s, size_t length);
483 
488  void copyFromUTF8(const char *s, size_t length);
489 
494  void copyFromUTF16(const wchar_t *s, size_t length, Type t);
495 
500  void copyFromUTF16(const char *s, size_t length, Type t);
501 
507  static const Type WCharByteOrder;
508 
509  class StringPrivate;
510  StringPrivate *d;
511  };
512 }
513 
520 
526 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
527 
533 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
534 
535 
541 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
542 
543 #endif