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 
60 
77  {
78  public:
79 
80 #ifndef DO_NOT_DOCUMENT
81  typedef std::basic_string<wchar>::iterator Iterator;
82  typedef std::basic_string<wchar>::const_iterator ConstIterator;
83 #endif
84 
89  enum Type {
93  Latin1 = 0,
97  UTF16 = 1,
102  UTF16BE = 2,
106  UTF8 = 3,
110  UTF16LE = 4
111  };
112 
116  String();
117 
123  String(const String &s);
124 
131  String(const std::string &s, Type t = Latin1);
132 
136  String(const wstring &s, Type t = UTF16BE);
137 
141  String(const wchar_t *s, Type t = UTF16BE);
142 
149  String(char c, Type t = Latin1);
150 
154  String(wchar_t c, Type t = Latin1);
155 
156 
163  String(const char *s, Type t = Latin1);
164 
171  String(const ByteVector &v, Type t = Latin1);
172 
176  virtual ~String();
177 
183  std::string to8Bit(bool unicode = false) const;
184 
188  wstring toWString() const;
189 
205  const char *toCString(bool unicode = false) const;
206 
210  Iterator begin();
211 
215  ConstIterator begin() const;
216 
221  Iterator end();
222 
227  ConstIterator end() const;
228 
233  int find(const String &s, int offset = 0) const;
234 
240  int rfind(const String &s, int offset = -1) const;
241 
245  bool startsWith(const String &s) const;
246 
251  String substr(uint position, uint n = 0xffffffff) const;
252 
257  String &append(const String &s);
258 
264  String upper() const;
265 
269  uint size() const;
270 
274  uint length() const;
275 
281  bool isEmpty() const;
282 
290  bool isNull() const;
291 
297  ByteVector data(Type t) const;
298 
305  // BIC: merge with the method below
306  int toInt() const;
307 
315  int toInt(bool *ok) const;
316 
320  String stripWhiteSpace() const;
321 
325  bool isLatin1() const;
326 
330  bool isAscii() const;
331 
335  static String number(int n);
336 
340  wchar &operator[](int i);
341 
345  const wchar &operator[](int i) const;
346 
351  bool operator==(const String &s) const;
352 
356  String &operator+=(const String &s);
357 
361  String &operator+=(const wchar_t* s);
362 
366  String &operator+=(const char* s);
367 
371  String &operator+=(wchar_t c);
372 
376  String &operator+=(char c);
377 
382  String &operator=(const String &s);
383 
387  String &operator=(const std::string &s);
388 
392  String &operator=(const wstring &s);
393 
397  String &operator=(const wchar_t *s);
398 
402  String &operator=(char c);
403 
407  String &operator=(wchar_t c);
408 
412  String &operator=(const char *s);
413 
417  String &operator=(const ByteVector &v);
418 
424  bool operator<(const String &s) const;
425 
429  static String null;
430 
431  protected:
437  void detach();
438 
439  private:
446  void prepare(Type t);
447 
448  class StringPrivate;
449  StringPrivate *d;
450  };
451 
452 }
453 
460 
466 TAGLIB_EXPORT const TagLib::String operator+(const char *s1, const TagLib::String &s2);
467 
473 TAGLIB_EXPORT const TagLib::String operator+(const TagLib::String &s1, const char *s2);
474 
475 
481 TAGLIB_EXPORT std::ostream &operator<<(std::ostream &s, const TagLib::String &str);
482 
483 #endif