Add OFString (QString)
This commit is contained in:
parent
53410c810f
commit
daa49494d4
4 changed files with 46 additions and 3 deletions
|
@ -10,6 +10,7 @@ INCLUDEPATH += common \
|
|||
QtWidgets
|
||||
|
||||
HEADERS += common/helpers.h \
|
||||
common/OFString+QString.h \
|
||||
common/QtOwnershipManaging.h \
|
||||
QtCore/QtChildEvent.h \
|
||||
QtCore/QtCoreApplication.h \
|
||||
|
@ -21,7 +22,8 @@ HEADERS += common/helpers.h \
|
|||
QtWidgets/QtApplication.h \
|
||||
QtWidgets/QtWidget.h
|
||||
|
||||
SOURCES += QtCore/QtChildEvent.mm \
|
||||
SOURCES += common/OFString+QString.mm \
|
||||
QtCore/QtChildEvent.mm \
|
||||
QtCore/QtCoreApplication.mm \
|
||||
QtCore/QtEvent.mm \
|
||||
QtCore/QtObject.mm \
|
||||
|
|
9
common/OFString+QString.h
Normal file
9
common/OFString+QString.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#include <QString>
|
||||
|
||||
@interface OFString (QString)
|
||||
+ (instancetype)stringWithQString: (const QString&)qString;
|
||||
- initWithQString: (const QString&)qString;
|
||||
- (QString)qString;
|
||||
@end
|
30
common/OFString+QString.mm
Normal file
30
common/OFString+QString.mm
Normal file
|
@ -0,0 +1,30 @@
|
|||
#import "OFString+QString.h"
|
||||
|
||||
@implementation OFString (QString)
|
||||
+ stringWithQString: (const QString&)qString
|
||||
{
|
||||
return [[[self alloc] initWithQString: qString] autorelease];
|
||||
}
|
||||
|
||||
- initWithQString: (const QString&)qString
|
||||
{
|
||||
static_assert(sizeof(QChar) == sizeof(of_char16_t),
|
||||
"QChar and of_char16_t have a different size!");
|
||||
|
||||
return [self initWithUTF16String: (of_char16_t*)qString.data()
|
||||
length: qString.length()];
|
||||
}
|
||||
|
||||
- (QString)qString
|
||||
{
|
||||
static_assert(sizeof(of_char16_t) == sizeof(QChar),
|
||||
"of_char16_t and QChar have a different size!");
|
||||
|
||||
void *pool = objc_autoreleasePoolPush();
|
||||
QString ret = QString((QChar*)[self UTF16String]);
|
||||
|
||||
objc_autoreleasePoolPop(pool);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@end
|
|
@ -4,16 +4,18 @@
|
|||
#include <QSize>
|
||||
#include <QRect>
|
||||
|
||||
#import "OFString+QString.h"
|
||||
|
||||
static OF_INLINE OFString*
|
||||
toOF(const QString &qString)
|
||||
{
|
||||
return [OFString stringWithUTF8String: qString.toUtf8()];
|
||||
return [OFString stringWithQString: qString];
|
||||
}
|
||||
|
||||
static OF_INLINE QString
|
||||
toQt(OFString *string)
|
||||
{
|
||||
return QString::fromUtf8([string UTF8String]);
|
||||
return [string qString];
|
||||
}
|
||||
|
||||
static OF_INLINE of_point_t
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue