2 * This file is part of Soprano Project.
4 * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 class TString::Private
: public QSharedData
49 TString::TString( const TString
& s
)
55 TString::TString( const TCHAR
* s
, bool wrap
)
60 d
->data
= const_cast<TCHAR
*>( s
);
68 TString::TString( const QString
& s
)
80 TString
& TString::operator=( const TString
& s
)
87 TString
& TString::operator=( const TCHAR
* s
)
90 size_t len
= wcslen( s
);
91 d
->data
= ( TCHAR
* )calloc( len
+1, sizeof( TCHAR
) );
96 d
->data
= strdup( s
);
103 TString
& TString::operator=( const QString
& s
)
106 d
->data
= ( TCHAR
* )calloc( s
.length()+1, sizeof( TCHAR
) );
107 s
.toWCharArray( d
->data
);
109 d
->data
= strdup( s
.toUtf8().data() );
116 bool TString::isEmpty() const
122 int TString::length() const
124 return _tcslen( d
->data
);
128 const TCHAR
* TString::data() const
134 TString::operator QString() const
140 QString
TString::toQString() const
144 return QString::fromWCharArray( d
->data
);
146 return QString::fromUtf8( d
->data
);
155 bool TString::operator==( const TString
& other
) const
157 return _tcscmp( d
->data
, other
.d
->data
) == 0;
161 bool TString::operator==( const QString
& other
) const
163 return toQString() == other
;
167 bool TString::operator!=( const TString
& other
) const
169 return !operator==( other
);
173 bool TString::operator!=( const QString
& other
) const
175 return toQString() != other
;
179 TString
TString::fromUtf8( const char* data
)
183 s
.d
->data
= ( TCHAR
* )calloc( strlen( data
)+1, sizeof( TCHAR
) ); // like this we are on the safe side
184 QString::fromUtf8( data
).toWCharArray( s
.d
->data
);
186 s
.d
->data
= strdup( data
);